<?php $title = 'Events - Ghana Anaesthesiologists Society'; ?>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-white font-weight-bold"><i class="fas fa-calendar-alt mr-2"></i>Events</h1>
    <?php if (isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin'): ?>
    <a href="<?= $baseUrl ?>/events/create" class="glass-btn glass-btn-primary"><i class="fas fa-plus mr-1"></i>Create Event</a>
    <?php endif; ?>
</div>
<div class="row">
    <?php if (!empty($events)): ?>
        <?php foreach ($events as $event): ?>
        <div class="col-lg-4 col-md-6 mb-4">
            <div class="glass-card h-100 d-flex flex-column">
                <?php if ($event->cover_image): ?>
                <div class="mb-3" style="border-radius: 12px; overflow: hidden; max-height: 140px;">
                    <img src="<?= $baseUrl ?>/<?= $event->cover_image ?>" style="width:100%;height:140px;object-fit:cover;" alt="">
                </div>
                <?php endif; ?>
                <div class="d-flex align-items-center mb-3">
                    <div class="text-center mr-3 px-3 py-2 rounded" style="background: rgba(78,115,223,0.3); min-width: 60px;">
                        <div class="font-weight-bold" style="font-size: 1.5rem; line-height: 1;"><?= date('d', strtotime($event->start_datetime)) ?></div>
                        <small><?= date('M', strtotime($event->start_datetime)) ?></small>
                    </div>
                    <div>
                        <h5 class="mb-1"><?= htmlspecialchars($event->title) ?></h5>
                        <small style="color: rgba(255,255,255,0.5);"><?= htmlspecialchars($event->event_type) ?> | <?= htmlspecialchars($event->venue ?: 'Online') ?></small>
                    </div>
                </div>
                <p style="color: rgba(255,255,255,0.7); font-size: 0.9rem;"><?= substr(strip_tags($event->description ?? ''), 0, 150) ?></p>
                <div class="d-flex justify-content-between align-items-center mt-auto">
                    <div>
                        <span class="glass-badge"><?= htmlspecialchars($event->status) ?></span>
                        <span class="glass-badge" style="background: <?= ($event->visibility ?? 'public') === 'private' ? 'rgba(231,74,59,0.2);color:#e74a3b' : 'rgba(28,200,138,0.2);color:#1cc88a' ?>;">
                            <?= htmlspecialchars($event->visibility ?? 'public') ?>
                        </span>
                    </div>
                    <a href="<?= $baseUrl ?>/events/<?= $event->id ?>" class="glass-btn btn-sm">View Details</a>
                </div>
            </div>
        </div>
        <?php endforeach; ?>
    <?php else: ?>
    <div class="col-12"><div class="empty-state"><i class="fas fa-calendar-alt"></i><p>No events available</p></div></div>
    <?php endif; ?>
</div>
