@extends('admin.layout')

@section('title', 'Réservation')
@section('header', 'Réservation')

@section('content')
<nav class="mb-6">
    <a href="{{ route('admin.reservation.reservations') }}" class="text-slate-500 hover:text-slate-900 text-sm">← Retour aux réservations</a>
</nav>

<div class="max-w-2xl space-y-6">
    <div class="bg-white rounded-2xl border border-slate-200 p-6">
        <h3 class="font-semibold text-slate-800 mb-4">Client</h3>
        <p><strong>{{ $reservation->customer_name }}</strong></p>
        <p class="text-slate-600">{{ $reservation->customer_email }}</p>
        @if($reservation->customer_phone)<p class="text-slate-600">{{ $reservation->customer_phone }}</p>@endif
        @if($reservation->notes)<p class="text-slate-600 mt-2">{{ $reservation->notes }}</p>@endif
    </div>

    <div class="bg-white rounded-2xl border border-slate-200 p-6">
        <h3 class="font-semibold text-slate-800 mb-4">Détails</h3>
        <p><strong>Service :</strong> {{ $reservation->slot->service->name ?? '—' }}</p>
        <p class="mt-2"><strong>Date :</strong> {{ $reservation->slot->date->format('d/m/Y') }}</p>
        <p><strong>Créneau :</strong> {{ \Carbon\Carbon::parse($reservation->slot->start_time)->format('H:i') }} - {{ \Carbon\Carbon::parse($reservation->slot->end_time)->format('H:i') }}</p>
        @php $count = $reservation->slot->confirmedReservations()->count(); @endphp
        <p class="mt-2 text-slate-600 text-sm">{{ $count }} personne(s) inscrite(s) sur ce créneau
            @if($reservation->slot->max_participants)
                ({{ $reservation->slot->remainingPlaces() }} place(s) restante(s))
            @endif
        </p>
    </div>

    <div class="bg-white rounded-2xl border border-slate-200 p-6">
        <h3 class="font-semibold text-slate-800 mb-4">Changer le statut</h3>
        <form method="POST" action="{{ route('admin.reservation.reservations.status', $reservation) }}" class="flex gap-2 items-center">
            @csrf
            <select name="status" class="px-4 py-2 border border-slate-200 rounded-xl focus:ring-2 focus:ring-primary-500">
                <option value="confirmed" {{ $reservation->status === 'confirmed' ? 'selected' : '' }}>Confirmée</option>
                <option value="cancelled" {{ $reservation->status === 'cancelled' ? 'selected' : '' }}>Annulée</option>
                <option value="completed" {{ $reservation->status === 'completed' ? 'selected' : '' }}>Terminée</option>
            </select>
            <button type="submit" class="px-6 py-2 bg-primary-500 text-white rounded-xl font-medium hover:bg-primary-600 transition">Mettre à jour</button>
        </form>
    </div>

    <form method="POST" action="{{ route('admin.reservation.reservations.destroy', $reservation) }}" class="inline" onsubmit="return confirm('Supprimer cette réservation ?')">
        @csrf
        @method('DELETE')
        <button type="submit" class="text-red-500 hover:underline">Supprimer la réservation</button>
    </form>

</div>
@endsection
