@extends('layouts.app')
@section('title', 'Events & Functions')
@section('content')
    <x-page-head title="Events & Functions" subtitle="School calendar">
        <x-slot:actions>
            @if ($pendingCount > 0)<a href="{{ route('extras.events.index', ['status' => 'pending_approval']) }}" class="btn btn-outline">{{ $pendingCount }} pending</a>@endif
            <a href="{{ route('extras.events.create') }}" class="btn btn-primary">New Event</a>
        </x-slot:actions>
    </x-page-head>
    <x-panel>
        <form method="GET" style="display:flex;gap:12px;margin-bottom:16px;flex-wrap:wrap;">
            <select class="input" name="event_type" onchange="this.form.submit()"><option value="">All types</option>@foreach($eventTypes as $t)<option value="{{ $t }}" @selected(request('event_type')===$t)>{{ ucfirst($t) }}</option>@endforeach</select>
            <select class="input" name="status" onchange="this.form.submit()"><option value="">All statuses</option>@foreach(\App\Services\School\EventManagementService::STATUSES as $s)<option value="{{ $s }}" @selected(request('status')===$s)>{{ ucfirst(str_replace('_',' ',$s)) }}</option>@endforeach</select>
        </form>
        @if ($events->isEmpty())
            <x-empty-state title="No events" message="Create school events and functions." />
        @else
            <div class="table-wrap"><table><thead><tr><th>Title</th><th>Type</th><th>Starts</th><th>Organizer</th><th>Status</th><th></th></tr></thead><tbody>
                @foreach ($events as $event)
                    <tr>
                        <td><a href="{{ route('extras.events.show', $event) }}">{{ $event->title }}</a></td>
                        <td>{{ ucfirst($event->event_type ?? 'event') }}</td>
                        <td>{{ $event->starts_at->format('d M Y H:i') }}</td>
                        <td>{{ $event->organizer_type === 'student_leadership' ? ($event->studentOrganizer?->full_name ?? 'Student') : ($event->createdBy?->name ?? 'Admin') }}</td>
                        <td><x-badge variant="blue">{{ str_replace('_', ' ', $event->status) }}</x-badge></td>
                        <td class="text-right"><a href="{{ route('extras.events.edit', $event) }}" class="btn btn-ghost btn-sm">Edit</a></td>
                    </tr>
                @endforeach
            </tbody></table></div>
            {{ $events->links() }}
        @endif
    </x-panel>
@endsection
