@extends('layouts.app')

@section('title', $offer->title . ' | TAXILANZ Demo')
@section('meta_description', $offer->excerpt ?: 'Detalle de oferta contextual con reserva simple en TAXILANZ Demo.')

@section('content')
<section class="split">
    <article class="card offer-card">
        <div class="offer-visual" aria-hidden="true"></div>
        <div>
            <span class="eyebrow">4 · Detalle de oferta</span>
            <h1 style="font-size:clamp(2.15rem,4vw,3.6rem);max-width:14ch;">{{ $offer->title }}</h1>
            <p>{{ $offer->description ?: $offer->excerpt }}</p>
            <div class="offer-meta" style="margin-top:16px;">
                <span class="pill">{{ ucfirst($offer->category) }}</span>
                @if($offer->location_label)<span class="pill">{{ $offer->location_label }}</span>@endif
                @if($offer->price_from)<span class="pill">Desde €{{ number_format((float) $offer->price_from, 0) }}</span>@endif
                @if($offer->duration_minutes)<span class="pill">{{ $offer->duration_minutes }} min</span>@endif
            </div>

            @if($recommendation)
                <div class="notice" style="margin-top:18px;">
                    <strong>Contexto de recomendación:</strong>
                    esta visita viene del trayecto #{{ $ride?->id }} y de la sugerencia en posición {{ $recommendation->position }}.
                    El clic ya cuenta como <code>recommendation_clicked</code>.
                </div>
            @endif
        </div>
    </article>

    <aside class="card">
        <span class="eyebrow">5 · Reserva simple</span>
        <h2>Confirma en menos de un minuto</h2>
        <p>Este formulario crea la reserva y registra <code>booking_started</code> y <code>booking_completed</code>.</p>

        @if ($errors->any())
            <div class="errors">
                <ul>
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        <form method="post" action="{{ route('bookings.store', $offer) }}" style="margin-top:18px;">
            @csrf
            <input type="hidden" name="ride_id" value="{{ $ride?->id }}">
            <input type="hidden" name="ride_recommendation_id" value="{{ $recommendation?->id }}">
            <label>
                Nombre
                <input type="text" name="customer_name" value="{{ old('customer_name', 'Alex Morgan') }}" required>
            </label>
            <div class="grid-2">
                <label>
                    Email
                    <input type="email" name="customer_email" value="{{ old('customer_email', 'alex@example.com') }}">
                </label>
                <label>
                    Teléfono
                    <input type="text" name="customer_phone" value="{{ old('customer_phone', '+34 600 123 456') }}">
                </label>
            </div>
            <div class="grid-2">
                <label>
                    Personas
                    <input type="number" name="party_size" value="{{ old('party_size', 2) }}" min="1" max="12" required>
                </label>
                <label>
                    Fecha / hora
                    <input type="datetime-local" name="booking_for" value="{{ old('booking_for') }}">
                </label>
            </div>
            <label>
                Nota
                <textarea name="notes">{{ old('notes', 'Mesa tranquila si está disponible.') }}</textarea>
            </label>
            <button class="btn" type="submit">Confirmar reserva</button>
        </form>
    </aside>
</section>
@endsection
