<?php $ev = $ev ?? []; ?>
<div class="row g-3">
    <div class="col-md-6">
        <label class="form-label">Title (EN) <span class="text-danger">*</span></label>
        <input type="text" name="title_en" class="form-control" value="<?= e($ev['title_en'] ?? '') ?>" required>
        <div class="invalid-feedback" data-field="title_en"></div>
    </div>
    <div class="col-md-6">
        <label class="form-label">Title (AR)</label>
        <input type="text" name="title_ar" class="form-control" value="<?= e($ev['title_ar'] ?? '') ?>" dir="rtl">
    </div>
    <div class="col-md-4">
        <label class="form-label">Event Type <span class="text-danger">*</span></label>
        <select name="event_type" class="form-select" required>
            <?php foreach (['social','sport','cultural','charity','celebration','workshop','competition','other'] as $t): ?>
            <option value="<?= $t ?>" <?= selected($t, $ev['event_type'] ?? '') ?>><?= ucfirst($t) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="col-md-4">
        <label class="form-label">Venue (Facility)</label>
        <select name="facility_id" class="form-select">
            <option value="">No facility</option>
            <?php foreach ($facilities as $f): ?>
            <option value="<?= $f['id'] ?>" <?= selected($f['id'], $ev['facility_id'] ?? '') ?>><?= e($f['name_en']) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <div class="col-md-4">
        <label class="form-label">Location</label>
        <input type="text" name="location" class="form-control" value="<?= e($ev['location'] ?? '') ?>">
    </div>
    <div class="col-md-3"><label class="form-label">Start DateTime <span class="text-danger">*</span></label><input type="datetime-local" name="start_datetime" class="form-control" value="<?= e(str_replace(' ', 'T', $ev['start_datetime'] ?? '')) ?>" required></div>
    <div class="col-md-3"><label class="form-label">End DateTime</label><input type="datetime-local" name="end_datetime" class="form-control" value="<?= e(str_replace(' ', 'T', $ev['end_datetime'] ?? '')) ?>"></div>
    <div class="col-md-3"><label class="form-label">Registration Start</label><input type="datetime-local" name="registration_start" class="form-control" value="<?= e(str_replace(' ', 'T', $ev['registration_start'] ?? '')) ?>"></div>
    <div class="col-md-3"><label class="form-label">Registration End</label><input type="datetime-local" name="registration_end" class="form-control" value="<?= e(str_replace(' ', 'T', $ev['registration_end'] ?? '')) ?>"></div>
    <div class="col-md-3"><label class="form-label">Max Attendees</label><input type="number" name="max_attendees" class="form-control" value="<?= e($ev['max_attendees'] ?? '') ?>" min="0"></div>
    <div class="col-md-3"><label class="form-label">Member Fee</label><input type="number" name="member_fee" class="form-control" value="<?= e($ev['member_fee'] ?? '0') ?>" step="0.01" min="0"></div>
    <div class="col-md-3"><label class="form-label">Guest Fee</label><input type="number" name="guest_fee" class="form-control" value="<?= e($ev['guest_fee'] ?? '0') ?>" step="0.01" min="0"></div>
    <div class="col-md-3">
        <div class="form-check form-switch mt-4">
            <input type="hidden" name="allow_guests" value="0">
            <input class="form-check-input" type="checkbox" name="allow_guests" value="1" id="allow_guests" <?= checked(1, $ev['allow_guests'] ?? 0) ?>>
            <label class="form-check-label" for="allow_guests">Allow Guests</label>
        </div>
    </div>
    <?php if (!empty($ev)): ?>
    <div class="col-md-4">
        <label class="form-label">Status</label>
        <select name="status" class="form-select">
            <?php foreach (['planned','registration_open','registration_closed','ongoing','completed','cancelled','postponed'] as $s): ?>
            <option value="<?= $s ?>" <?= selected($s, $ev['status'] ?? '') ?>><?= ucfirst(str_replace('_', ' ', $s)) ?></option>
            <?php endforeach; ?>
        </select>
    </div>
    <?php endif; ?>
    <div class="col-md-6"><label class="form-label">Description (EN)</label><textarea name="description_en" class="form-control" rows="3"><?= e($ev['description_en'] ?? '') ?></textarea></div>
    <div class="col-md-6"><label class="form-label">Description (AR)</label><textarea name="description_ar" class="form-control" rows="3" dir="rtl"><?= e($ev['description_ar'] ?? '') ?></textarea></div>
</div>