<?php ob_start();
$ev = $event ?? [];
$isPostponed = ($ev['event_status'] ?? '') === 'postponed';
$isCancelled  = ($ev['event_status'] ?? '') === 'cancelled';
$hasStatusNote = $isPostponed || $isCancelled;
?>

<article class="event-detail">
    <div class="container">

        <?php if ($hasStatusNote): ?>
        <div class="event-status-notice event-status-notice--<?= e($ev['event_status']) ?>">
            <?php if ($isCancelled): ?>
            ⚠ This event has been <strong>cancelled</strong>.
            <?php else: ?>
            ℹ This event has been <strong>postponed</strong>. Please check back for updated dates.
            <?php endif; ?>
        </div>
        <?php endif; ?>

        <header class="event-detail-header">
            <?php if (!empty($ev['category_name'])): ?>
            <span class="event-category">
                <a href="/events/category/<?= e($ev['category_slug']) ?>"><?= e($ev['category_name']) ?></a>
            </span>
            <?php endif; ?>

            <h1><?= e($ev['title']) ?></h1>

            <div class="event-detail-meta">
                <div class="event-meta-item">
                    <span class="meta-icon"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="3" y="4" width="14" height="14" rx="2"/><path d="M7 2v4M13 2v4M3 8h14"/></svg></span>
                    <span>
                        <?= e(format_date($ev['start_date'])) ?>
                        <?php if (!empty($ev['start_time'])): ?>
                        &nbsp;<?= e(substr($ev['start_time'], 0, 5)) ?>
                        <?php endif; ?>
                        <?php if (!empty($ev['end_date']) && $ev['end_date'] !== $ev['start_date']): ?>
                        &nbsp;–&nbsp;<?= e(format_date($ev['end_date'])) ?>
                        <?php if (!empty($ev['end_time'])): ?>
                        &nbsp;<?= e(substr($ev['end_time'], 0, 5)) ?>
                        <?php endif; ?>
                        <?php elseif (!empty($ev['end_time'])): ?>
                        &nbsp;–&nbsp;<?= e(substr($ev['end_time'], 0, 5)) ?>
                        <?php endif; ?>
                    </span>
                </div>
                <?php if (!empty($ev['location'])): ?>
                <div class="event-meta-item">
                    <span class="meta-icon"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M10 17s-5.5-4.5-5.5-8a5.5 5.5 0 0111 0c0 3.5-5.5 8-5.5 8z"/><circle cx="10" cy="9" r="1.5"/></svg></span>
                    <span><?= e($ev['location']) ?></span>
                </div>
                <?php endif; ?>
            </div>
        </header>

        <?php if (!empty($ev['media_path'])): ?>
        <div class="event-detail-image">
            <?= picture_tag($ev['media_path'], $ev['media_alt'] ?? $ev['title'], 'event-hero-image') ?>
        </div>
        <?php endif; ?>

        <?php if (!empty($ev['excerpt'])): ?>
        <div class="event-detail-excerpt">
            <p><?= e($ev['excerpt']) ?></p>
        </div>
        <?php endif; ?>

        <?php if (!empty($ev['content'])): ?>
        <div class="event-detail-content prose">
            <?= $ev['content'] ?>
        </div>
        <?php endif; ?>

        <div class="event-detail-footer">
            <a href="/events" class="btn-back">← Back to Events</a>
        </div>

    </div>
</article>

<?php $content = ob_get_clean(); include __DIR__ . '/layout.php'; ?>
