@extends('layouts.app')

@section('title', $offer->title . ' | ArrivalFlow')
@section('meta_description', $offer->excerpt ?: 'Contextual offer detail with a simple booking form.')

@section('content')
<section class="split">
    <article class="card offer-card">
        <div class="offer-visual" aria-hidden="true"></div>
        <div>
            <span class="eyebrow">4 · Offer detail</span>
            <h1 style="font-size:clamp(2.1rem,4vw,3.4rem);">{{ $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">From €{{ 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="list-item" style="margin-top:18px;">
                    <strong>Recommendation context:</strong> This click is tied to ride #{{ $ride?->id }} and recommendation #{{ $recommendation->position }}.
                </div>
            @endif
        </div>
    </article>

    <aside class="card">
        <span class="eyebrow">5 · Reserve</span>
        <h2>Simple booking form</h2>
        <p>This POST creates a confirmed booking and logs both <code>booking_started</code> and <code>booking_completed</code>.</p>

        @if ($errors->any())
            <div class="errors" style="margin-top:16px;">
                <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>
                Customer name
                <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>
                    Phone
                    <input type="text" name="customer_phone" value="{{ old('customer_phone', '+1 555 010 224') }}">
                </label>
            </div>
            <div class="grid-2">
                <label>
                    Party size
                    <input type="number" name="party_size" value="{{ old('party_size', 2) }}" min="1" max="12" required>
                </label>
                <label>
                    Booking for
                    <input type="datetime-local" name="booking_for" value="{{ old('booking_for') }}">
                </label>
            </div>
            <label>
                Notes
                <textarea name="notes">{{ old('notes', 'Window table if available.') }}</textarea>
            </label>
            <button class="btn" type="submit">Confirm booking</button>
        </form>
    </aside>
</section>
@endsection
