<x-app-layout>
    <div class="container mx-auto my-6">
        <h2 class="text-2xl font-semibold mb-4">Book a Session</h2>

        <div class="mb-4">
            <a href="{{ route('student.calendar') }}" class="text-blue-600 hover:underline">← Back to calendar</a>
        </div>

        {{-- Prefilled details from controller (no Carbon in Blade) --}}
        <div class="border rounded p-4 bg-white shadow-sm space-y-1">
            <p><span class="font-semibold">When:</span> {{ $weekdayName }} {{ $prettyDate }} at {{ $prettyTime }}</p>
            <p><span class="font-semibold">Date (value to save):</span> {{ $date }}</p>
            <p><span class="font-semibold">Slot ID:</span> {{ $slot->id }}</p>
        </div>

        <div class="mt-6 text-sm text-gray-600">
            Next step: we’ll add a confirmation step (and later, payment) before creating the booking.
        </div>
		
		<form action="{{ route('student.bookings.store') }}" method="POST" class="mt-6 border rounded p-4 bg-white shadow-sm space-y-4">
			@csrf

			{{-- keep the selected date/slot --}}
			<input type="hidden" name="date" value="{{ $date }}">
			<input type="hidden" name="slot_id" value="{{ $slot->id }}">

			@if ($errors->any())
				<div class="p-3 rounded bg-red-50 text-red-700 text-sm">
					<ul class="list-disc pl-5"> 
						@foreach ($errors->all() as $err)
							<li>{{ $err }}</li>
						@endforeach
					</ul>
				</div>
			@endif

			<div>
				<label class="block text-sm font-medium mb-1" for="message">Message (optional)</label>
				<textarea id="message" name="message" rows="3" class="w-full border rounded px-3 py-2">{{ old('message') }}</textarea>
				@error('message') <p class="text-sm text-red-600 mt-1">{{ $message }}</p> @enderror
			</div>

			<div class="flex items-center gap-3">
				<button type="submit" class="px-4 py-2 rounded bg-indigo-600 text-white hover:bg-indigo-700">
					Confirm booking
				</button>
				<a href="{{ route('student.calendar') }}" class="text-blue-600 hover:underline">Cancel</a>
			</div>
		</form>
    </div>
</x-app-layout>