@php($event = $event ?? null)

<div class="card-arena p-4">
    <div class="row g-3">
        <div class="col-md-8">
            <label class="form-label">Title</label>
            <input type="text" name="title" class="form-control" value="{{ old('title', $event?->title) }}" required>
        </div>
        <div class="col-md-4">
            <label class="form-label">Game</label>
            <select name="game_id" class="form-select" required>
                @foreach($games as $game)
                    <option value="{{ $game->id }}" @selected(old('game_id', $event?->game_id) == $game->id)>{{ $game->name }}</option>
                @endforeach
            </select>
        </div>
        <div class="col-12">
            <label class="form-label">Short Description</label>
            <input type="text" name="short_description" class="form-control" value="{{ old('short_description', $event?->short_description) }}">
        </div>
        <div class="col-12">
            <label class="form-label">Description</label>
            <textarea name="description" class="form-control" rows="4">{{ old('description', $event?->description) }}</textarea>
        </div>
        <div class="col-md-4">
            <label class="form-label">Event Type</label>
            <select name="event_type" class="form-select" required>
                @foreach(\App\Enums\EventType::cases() as $type)
                    <option value="{{ $type->value }}" @selected(old('event_type', $event?->event_type?->value) === $type->value)>{{ $type->label() }}</option>
                @endforeach
            </select>
        </div>
        <div class="col-md-4">
            <label class="form-label">Participation</label>
            <select name="participation_type" class="form-select" required>
                @foreach(\App\Enums\ParticipationType::cases() as $type)
                    <option value="{{ $type->value }}" @selected(old('participation_type', $event?->participation_type?->value) === $type->value)>{{ $type->label() }}</option>
                @endforeach
            </select>
        </div>
        <div class="col-md-4">
            <label class="form-label">Location</label>
            <select name="location_type" class="form-select" required>
                @foreach(\App\Enums\LocationType::cases() as $type)
                    <option value="{{ $type->value }}" @selected(old('location_type', $event?->location_type?->value) === $type->value)>{{ $type->label() }}</option>
                @endforeach
            </select>
        </div>
        <div class="col-md-3">
            <label class="form-label">Starts At</label>
            <input type="datetime-local" name="starts_at" class="form-control" value="{{ old('starts_at', optional($event?->starts_at)->format('Y-m-d\TH:i')) }}" required>
        </div>
        <div class="col-md-3">
            <label class="form-label">Ends At</label>
            <input type="datetime-local" name="ends_at" class="form-control" value="{{ old('ends_at', optional($event?->ends_at)->format('Y-m-d\TH:i')) }}" required>
        </div>
        <div class="col-md-3">
            <label class="form-label">Registration Opens</label>
            <input type="datetime-local" name="registration_opens_at" class="form-control" value="{{ old('registration_opens_at', optional($event?->registration_opens_at)->format('Y-m-d\TH:i')) }}">
        </div>
        <div class="col-md-3">
            <label class="form-label">Registration Closes</label>
            <input type="datetime-local" name="registration_closes_at" class="form-control" value="{{ old('registration_closes_at', optional($event?->registration_closes_at)->format('Y-m-d\TH:i')) }}">
        </div>
        <div class="col-md-3">
            <label class="form-label">Capacity</label>
            <input type="number" name="capacity" class="form-control" value="{{ old('capacity', $event?->capacity) }}" min="1">
        </div>
        <div class="col-md-3">
            <label class="form-label">Timezone</label>
            <input type="text" name="timezone" class="form-control" value="{{ old('timezone', $event?->timezone ?? 'UTC') }}" required>
        </div>
        <div class="col-md-3">
            <label class="form-label">Approval</label>
            <select name="approval_mode" class="form-select" required>
                @foreach(\App\Enums\ApprovalMode::cases() as $mode)
                    <option value="{{ $mode->value }}" @selected(old('approval_mode', $event?->approval_mode?->value) === $mode->value)>{{ $mode->label() }}</option>
                @endforeach
            </select>
        </div>
        <div class="col-md-3">
            <label class="form-label">Pricing</label>
            <select name="pricing_type" class="form-select" required>
                @foreach(\App\Enums\PricingType::cases() as $type)
                    <option value="{{ $type->value }}" @selected(old('pricing_type', $event?->pricing_type?->value) === $type->value)>{{ $type->label() }}</option>
                @endforeach
            </select>
        </div>
        <div class="col-md-3">
            <label class="form-label">Fee (minor units)</label>
            <input type="number" name="fee_amount_minor" class="form-control" value="{{ old('fee_amount_minor', $event?->fee_amount_minor) }}" min="0">
        </div>
        <div class="col-md-3">
            <label class="form-label">Currency</label>
            <input type="text" name="currency" class="form-control" value="{{ old('currency', $event?->currency ?? 'USD') }}" maxlength="3">
        </div>
        <div class="col-md-3 d-flex align-items-end">
            <div class="form-check">
                <input type="hidden" name="waitlist_enabled" value="0">
                <input type="checkbox" name="waitlist_enabled" value="1" class="form-check-input" id="waitlist_enabled" @checked(old('waitlist_enabled', $event?->waitlist_enabled))>
                <label class="form-check-label" for="waitlist_enabled">Waitlist enabled</label>
            </div>
        </div>
        <div class="col-12">
            <label class="form-label">Payment Instructions</label>
            <textarea name="payment_instructions" class="form-control" rows="3">{{ old('payment_instructions', $event?->payment_instructions) }}</textarea>
        </div>
    </div>
</div>
