@extends('layouts.app', ['includeFlatpickr' => true])

@section('title', 'Create Quotation')

@section('content')
    @php
        $linkedBooking = $booking ?? null;
        $lockSpaces = (bool) $linkedBooking;
    @endphp

    <x-breadcrumbs :items="[
        ['label' => 'Dashboard', 'url' => route('dashboard')],
        ['label' => 'Quotations', 'url' => route('quotations.index')],
        ['label' => 'Create'],
    ]" />

    <x-page-header title="Create Quotation" subtitle="Creates a provisional booking/reservation with the quotation" />

    <form method="POST" action="{{ route('quotations.store') }}">
        @csrf
        @if ($linkedBooking)
            <input type="hidden" name="booking_id" value="{{ $linkedBooking->id }}">
        @endif

        <x-card title="Quotation Information" class="mb-3">
            <div class="row mb-1">
                <div class="col-md-3">
                    <x-form.input label="Quotation Date" name="quotation_date" type="date" :value="old('quotation_date', now()->toDateString())" />
                </div>
                <div class="col-md-3">
                    <x-form.input label="Expires At" name="expires_at" type="date" :value="old('expires_at')" />
                </div>
            </div>

            @include('partials.document-event-fields', [
                'booking' => $linkedBooking,
                'quotation' => null,
                'lockSpaces' => $lockSpaces,
                'sectionTitle' => 'Quotation Information',
            ])
        </x-card>

        <x-card title="Spaces" class="mb-3">
            <x-document-spaces-builder
                :spaces="$spaces"
                :booking="$linkedBooking"
                :readonly="(bool) $lockSpaces"
            />
        </x-card>

        <x-card title="Additional Charges" class="mb-3">
            <x-document-pricing-builder
                :packages="$packages"
                :items="old('items', [])"
                initial-mode="{{ old('pricing_mode', 'packages') }}"
                :currency="app(\App\Services\SettingsService::class)->get('currency', 'KES')"
            />
        </x-card>

        <div class="d-flex gap-2">
            <button type="submit" class="btn btn-primary">Save Quotation</button>
            <a href="{{ route('quotations.index') }}" class="btn btn-outline-secondary">Cancel</a>
        </div>
    </form>
@endsection
