<?php
$eventName = trim((string) ($event['event_name'] ?? 'Upcoming Event'));
$eventCategory = trim((string) ($event['event_category'] ?? ''));
$eventDateRaw = trim((string) ($event['expiration_date'] ?? ''));
$eventDate = $eventDateRaw !== '' ? date('F j, Y', strtotime($eventDateRaw)) : 'TBD';
$amountRaw = $event['amount'] ?? null;
$amount = ($amountRaw !== null && $amountRaw !== '') ? number_format((float) $amountRaw, 2) : null;
?>
<div style="font-family: sans-serif; line-height: 1.6;">
    <h1 style="font-size: 1.5rem; margin-bottom: 0.5rem;"><?= esc($eventName) ?></h1>
    <p style="margin:0.25rem 0;"><strong>Date:</strong> <?= esc($eventDate) ?></p>
    <?php if ($eventCategory !== ''): ?>
        <p style="margin:0.25rem 0;"><strong>Category:</strong> <?= esc($eventCategory) ?></p>
    <?php endif; ?>
    <?php if ($amount !== null): ?>
        <p style="margin:0.25rem 0;"><strong>Amount:</strong> $<?= esc($amount) ?></p>
    <?php endif; ?>
    <?php if (!empty($event['description'])): ?>
        <div style="margin:0.75rem 0;"><?= $event['description'] ?></div>
    <?php endif; ?>
    <?php if (!empty($flyerUrl)): ?>
        <div style="margin:1rem 0;">
            <img
                src="<?= esc((string) $flyerUrl) ?>"
                alt="Event flyer for <?= esc($eventName) ?>"
                style="display:block; max-width:100%; height:auto; border:1px solid #ddd; border-radius:8px;"
            >
        </div>
        <p style="margin:0.75rem 0;">
            Flyer:
            <a href="<?= esc((string) $flyerUrl) ?>"><?= esc((string) $flyerUrl) ?></a>
        </p>
    <?php endif; ?>
    <p style="margin:0.75rem 0;">For more details, please contact the school office or review the parent event page.</p>
    <p style="margin:0.25rem 0;">
        <a href="<?= esc((string) $eventUrl) ?>"><?= esc((string) $eventUrl) ?></a>
    </p>
</div>
