<x-admin-layout :title="$item->exists ? 'Edit Class Session' : 'Create Class Session'">
    <x-admin.form-panel :back-route="route('admin.class-sessions.index')">
        <form method="POST" action="{{ $item->exists ? route('admin.class-sessions.update', $item) : route('admin.class-sessions.store') }}" class="space-y-4">
            @csrf
            @if ($item->exists) @method('PUT') @endif

            <div class="grid grid-cols-2 gap-4">
                <div>
                    <label class="block text-sm font-medium">Class Type</label>
                    <select name="class_type_id" class="admin-input" required>
                        <option value="">Select class type</option>
                        @foreach ($classTypes as $classType)
                            <option value="{{ $classType->id }}" @selected(old('class_type_id', $item->class_type_id) == $classType->id)>{{ $classType->name }}</option>
                        @endforeach
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium">Coach</label>
                    <select name="coach_id" class="admin-input" required>
                        <option value="">Select coach</option>
                        @foreach ($coaches as $coach)
                            <option value="{{ $coach->id }}" @selected(old('coach_id', $item->coach_id) == $coach->id)>{{ $coach->name }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="grid grid-cols-3 gap-4">
                <div>
                    <label class="block text-sm font-medium">Day of Week</label>
                    <select name="day_of_week" class="admin-input" required>
                        @foreach (['mon' => 'Monday', 'tue' => 'Tuesday', 'wed' => 'Wednesday', 'thu' => 'Thursday', 'fri' => 'Friday', 'sat' => 'Saturday', 'sun' => 'Sunday'] as $value => $label)
                            <option value="{{ $value }}" @selected(old('day_of_week', $item->day_of_week) === $value)>{{ $label }}</option>
                        @endforeach
                    </select>
                </div>
                <div>
                    <label class="block text-sm font-medium">Start Time</label>
                    <input type="time" name="start_time" value="{{ old('start_time', $item->start_time ? \Illuminate\Support\Str::of($item->start_time)->substr(0, 5) : '') }}" class="admin-input" required>
                </div>
                <div>
                    <label class="block text-sm font-medium">Duration (min)</label>
                    <input type="number" name="duration_minutes" value="{{ old('duration_minutes', $item->duration_minutes) }}" class="admin-input">
                </div>
            </div>
            <div class="grid grid-cols-2 gap-4">
                <div>
                    <label class="block text-sm font-medium">Spots Label</label>
                    <input name="spots_label" value="{{ old('spots_label', $item->spots_label) }}" class="admin-input">
                </div>
                <div>
                    <label class="block text-sm font-medium">Availability</label>
                    <select name="availability" class="admin-input" required>
                        @foreach (['open' => 'Open', 'low' => 'Low', 'waitlist' => 'Waitlist'] as $value => $label)
                            <option value="{{ $value }}" @selected(old('availability', $item->availability ?? 'open') === $value)>{{ $label }}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="flex items-center gap-2">
                <input type="checkbox" name="is_active" value="1" @checked(old('is_active', $item->is_active ?? true))>
                <label class="text-sm font-medium">Active</label>
            </div>
            <button type="submit" class="admin-btn-primary">Save</button>
        </form>
    </x-admin.form-panel>
</x-admin-layout>
