<?php

declare(strict_types=1);

/**
 * Liste normalisierter Termine (Spiele + Vereins-Events gemischt). Props:
 *   $items      array{date, date_end?, title, department, type, meta?, href?}
 *   $empty_text string (optional)
 * Kennt selbst nichts von Matchcenter-/Events-Datenstruktur — bekommt nur die
 * bereits gemergte, normalisierte Form (app/pages/termine.php baut sie).
 */
$items = $items ?? [];
$emptyText = $empty_text ?? 'Aktuell keine Termine.';
?>
<?php if ($items === []): ?>
                <p class="text-muted"><?= e($emptyText) ?></p>
<?php else: ?>
                <ul class="termine-list">
<?php foreach ($items as $item): ?>
<?php
    $tag = !empty($item['href']) ? 'a' : 'div';
    $chip = german_date_chip($item['date']);
    $dateText = german_date_range($item['date'], $item['date_end'] ?? null);
?>
                    <li class="termine-list__item">
                        <<?= $tag ?> class="termine-list__link"<?= !empty($item['href']) ? ' href="' . e($item['href']) . '"' : '' ?>>
                            <span class="termine-list__date-chip" aria-hidden="true">
                                <span class="termine-list__date-day"><?= e($chip['day']) ?></span>
                                <span class="termine-list__date-month"><?= e($chip['month']) ?></span>
                            </span>
                            <span class="termine-list__body">
                                <span class="termine-list__title"><?= e($item['title']) ?></span>
                                <span class="termine-list__meta">
                                    <time datetime="<?= e($item['date']) ?>"><?= e($dateText) ?></time><?php if (!empty($item['meta'])): ?> · <?= e($item['meta']) ?><?php endif; ?>
                                </span>
                            </span>
                            <span class="termine-list__badge termine-list__badge--<?= e($item['department']) ?>">
                                <?= e(department_label($item['department'])) ?>
                            </span>
                        </<?= $tag ?>>
                    </li>
<?php endforeach; ?>
                </ul>
<?php endif; ?>
