<?php $title = isset($event) ? 'Edit Event' : 'Create Event'; ?>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-white font-weight-bold"><?= isset($event) ? 'Edit Event' : 'Create Event' ?></h1>
</div>
<div class="glass-card">
    <form method="POST" action="<?= $baseUrl ?>/events/<?= isset($event) ? $event->id . '/update' : 'store' ?>" enctype="multipart/form-data">
        <div class="row">
            <div class="col-md-8 form-group">
                <label style="color: rgba(255,255,255,0.7);">Title</label>
                <input type="text" name="title" class="form-control glass-input" value="<?= htmlspecialchars($event->title ?? '') ?>" required>
            </div>
            <div class="col-md-4 form-group">
                <label style="color: rgba(255,255,255,0.7);">Event Type</label>
                <select name="event_type" class="form-control glass-input">
                    <option value="conference" <?= (($event->event_type ?? '') === 'conference') ? 'selected' : '' ?>>Conference</option>
                    <option value="workshop" <?= (($event->event_type ?? '') === 'workshop') ? 'selected' : '' ?>>Workshop</option>
                    <option value="webinar" <?= (($event->event_type ?? '') === 'webinar') ? 'selected' : '' ?>>Webinar</option>
                    <option value="meeting" <?= (($event->event_type ?? '') === 'meeting') ? 'selected' : '' ?>>Meeting</option>
                    <option value="social" <?= (($event->event_type ?? '') === 'social') ? 'selected' : '' ?>>Social</option>
                    <option value="other" <?= (($event->event_type ?? '') === 'other') ? 'selected' : '' ?>>Other</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label style="color: rgba(255,255,255,0.7);">Description</label>
            <textarea name="description" class="form-control glass-input" rows="5"><?= htmlspecialchars($event->description ?? '') ?></textarea>
        </div>
        <div class="row">
            <div class="col-md-6 form-group">
                <label style="color: rgba(255,255,255,0.7);">Venue</label>
                <input type="text" name="venue" class="form-control glass-input" value="<?= htmlspecialchars($event->venue ?? '') ?>">
            </div>
            <div class="col-md-3 form-group">
                <label style="color: rgba(255,255,255,0.7);">Start Date & Time</label>
                <input type="datetime-local" name="start_datetime" class="form-control glass-input" value="<?= isset($event) ? date('Y-m-d\TH:i', strtotime($event->start_datetime)) : '' ?>" required>
            </div>
            <div class="col-md-3 form-group">
                <label style="color: rgba(255,255,255,0.7);">End Date & Time</label>
                <input type="datetime-local" name="end_datetime" class="form-control glass-input" value="<?= isset($event) && $event->end_datetime ? date('Y-m-d\TH:i', strtotime($event->end_datetime)) : '' ?>">
            </div>
        </div>
        <div class="row">
            <div class="col-md-4 form-group">
                <label style="color: rgba(255,255,255,0.7);">Cover Image</label>
                <input type="file" name="cover_image" class="form-control glass-input" accept="image/*">
                <?php if (isset($event) && $event->cover_image): ?>
                <div class="mt-2">
                    <img src="<?= $baseUrl ?>/<?= $event->cover_image ?>" style="max-height: 80px; border-radius: 8px;">
                    <small style="color: rgba(255,255,255,0.5);">Current image</small>
                </div>
                <?php endif; ?>
            </div>
            <div class="col-md-4 form-group">
                <label style="color: rgba(255,255,255,0.7);">Registration Deadline</label>
                <input type="datetime-local" name="registration_deadline" class="form-control glass-input" value="<?= isset($event) && $event->registration_deadline ? date('Y-m-d\TH:i', strtotime($event->registration_deadline)) : '' ?>">
            </div>
            <div class="col-md-2 form-group">
                <label style="color: rgba(255,255,255,0.7);">Max Attendees</label>
                <input type="number" name="max_attendees" class="form-control glass-input" value="<?= htmlspecialchars($event->max_attendees ?? '') ?>">
            </div>
            <div class="col-md-2 form-group">
                <label style="color: rgba(255,255,255,0.7);">Fee (GHS)</label>
                <input type="number" step="0.01" name="fee" class="form-control glass-input" value="<?= htmlspecialchars($event->fee ?? '0') ?>">
            </div>
        </div>
        <div class="row">
            <div class="col-md-4 form-group">
                <label style="color: rgba(255,255,255,0.7);">Visibility</label>
                <select name="visibility" class="form-control glass-input">
                    <option value="public" <?= (($event->visibility ?? 'public') === 'public') ? 'selected' : '' ?>>Public (anyone)</option>
                    <option value="private" <?= (($event->visibility ?? '') === 'private') ? 'selected' : '' ?>>Private (members only)</option>
                </select>
            </div>
            <?php if (isset($event)): ?>
            <div class="col-md-4 form-group">
                <label style="color: rgba(255,255,255,0.7);">Status</label>
                <select name="status" class="form-control glass-input">
                    <option value="upcoming" <?= ($event->status === 'upcoming') ? 'selected' : '' ?>>Upcoming</option>
                    <option value="ongoing" <?= ($event->status === 'ongoing') ? 'selected' : '' ?>>Ongoing</option>
                    <option value="completed" <?= ($event->status === 'completed') ? 'selected' : '' ?>>Completed</option>
                    <option value="cancelled" <?= ($event->status === 'cancelled') ? 'selected' : '' ?>>Cancelled</option>
                </select>
            </div>
            <?php endif; ?>
        </div>
        <div class="text-right mt-3">
            <a href="<?= $baseUrl ?>/events" class="glass-btn mr-2">Cancel</a>
            <button type="submit" class="glass-btn glass-btn-primary"><?= isset($event) ? 'Update' : 'Create' ?></button>
        </div>
    </form>
</div>
