@extends('layouts.admin')

@section('title', 'Intakes')
@section('heading', 'Intakes')

@section('content')

    <div class="space-y-4">
        @foreach ($intakes as $intake)
            <x-card>
                <div class="flex flex-wrap items-start justify-between gap-6">
                    <div class="min-w-0">
                        <div class="flex flex-wrap items-center gap-3">
                            <h2 class="text-lg font-semibold text-slate-900">{{ $intake->name }}</h2>
                            <x-status-badge :status="$intake->status" />
                            @if ($intake->is_default)
                                <x-badge color="gold" size="sm">Default</x-badge>
                            @endif
                        </div>

                        <dl class="mt-4 grid gap-4 text-sm sm:grid-cols-2 lg:grid-cols-4">
                            @foreach ([
                                'Applications open' => $intake->application_open_at?->format('j M Y'),
                                'Applications close' => $intake->application_close_at?->format('j M Y'),
                                'Teaching starts' => $intake->start_date?->format('j M Y'),
                                'Programmes' => $intake->intake_programmes_count,
                            ] as $label => $value)
                                <div>
                                    <dt class="text-xs uppercase tracking-wider text-slate-400">{{ $label }}</dt>
                                    <dd class="mt-0.5 text-slate-800">{{ $value ?: '—' }}</dd>
                                </div>
                            @endforeach
                        </dl>
                    </div>

                    <div class="shrink-0 text-right">
                        <p class="font-display text-3xl text-slate-900">{{ number_format($intake->applications_count) }}</p>
                        <p class="text-xs text-slate-500">{{ Str::plural('application', $intake->applications_count) }}</p>

                        @permission('intakes.manage')
                            <form method="POST" action="{{ route('admin.intakes.status', $intake) }}" class="mt-4">
                                @csrf
                                <label for="status-{{ $intake->id }}" class="sr-only">Status for {{ $intake->name }}</label>
                                <div class="flex gap-2">
                                    <select id="status-{{ $intake->id }}" name="status"
                                            class="rounded-lg border border-slate-300 px-3 py-1.5 text-sm focus:border-brand-700 focus:outline-none focus:ring-2 focus:ring-brand-700/30">
                                        @foreach (['upcoming' => 'Upcoming', 'open' => 'Open', 'closed' => 'Closed', 'archived' => 'Archived'] as $value => $label)
                                            <option value="{{ $value }}" @selected($intake->status->value === $value)>{{ $label }}</option>
                                        @endforeach
                                    </select>
                                    <x-button type="submit" size="sm" variant="outline">Update</x-button>
                                </div>
                            </form>
                        @endpermission
                    </div>
                </div>

                @if ($intake->description)
                    <p class="mt-4 border-t border-slate-100 pt-4 text-sm text-slate-600">{{ $intake->description }}</p>
                @endif
            </x-card>
        @endforeach
    </div>

@endsection
