@php
    $datatable = 'carDataTableID';
    $button = [
        'save' => 'reservationSaveData',
        'close' => 'reservationCloseForm',
    ];
    $form = 'reservationFormID';

    // type
    $typePart = [
        '1' => 'CNI',
        '2' => 'PASSSPORT',
    ];

    // dd($cars);

@endphp

<x-backoffice.back-layout :title="$title" :breadcrumb="$breadcrumb">

    <!--begin::Container-->
    <div id="kt_content_container" class="container-xxl">
        @if (session('success'))
            <div class="alert alert-success text-center">
                {{ session('success') }}
            </div>
        @endif
        <div class="card">
            {{-- @if (session('success'))
                <div class="alert alert-success text-center">
                    {{ session('success') }}
                </div>
            @endif --}}
            <!--begin::Card header-->
            <div class="card-header border-0 pt-6">
                <!--begin::Card title-->
                <div class="card-title">
                    <!--begin::Search-->
                    {{-- <x-backoffice.widget.search-bar /> --}}
                    <span>Lise des reservations</span>
                    <!--end::Search-->
                </div>
                <!--begin::Card title-->
            </div>
            <!--end::Card header-->
            <!--begin::Card body-->
            <div class="card-body py-4">
                <form id="{{ $form }}" method="post" action="{{ route('reservation.post') }}">
                    @csrf
                    <input type="hidden" name="rowID" name="rowID" value="0">


                    <!--begin::-->
                    <div class="fv-row mb-5 row">
                        <div class="col-md-4">
                            <!--begin::Label-->
                            <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                                <span class="required">Véhicules</span>
                                </span>
                            </label>
                            <!--end::Label-->
                            <!--begin::Input-->
                            <select class="form-select form-select-solid sl2" id="car" data-control="select2"
                                data-placeholder="Choisissez un véhicule" name="car_id">
                                <option></option>
                                @forelse ($cars as $car)
                                    @php
                                        // $selected = $car->id === $carID ? ' selected="selected"' : '';
                                    @endphp
                                    <option value="{{ $car->id }}" carprice={{ $car->price }}>
                                        {{ mb_strtoupper($car->brand->name) . ' ' . mb_strtoupper($car->modele->name) . ' | ' . $car->immatriculation }}
                                    </option>
                                @empty
                                @endforelse
                            </select>
                            <!--end::-->
                            @if ($errors->has('car_id'))
                                <div class="text-danger">{{ $errors->first('car_id') }}</div>
                            @endif
                        </div>

                        <div class="col-md-4">
                            <!--begin::Label-->
                            <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                                <span class="required">Date debut</span>
                                </span>
                            </label>
                            <!--end::Label-->
                            <!--begin::Input-->
                            <input class="form-control form-control-solid attr_date"
                                placeholder="Date et heure de debut" id="start" name="start" value="" />
                            <!--end::Input-->
                            @if ($errors->has('start'))
                                <div class="text-danger">{{ $errors->first('start') }}</div>
                            @endif
                        </div>

                        <div class="col-md-4">
                            <!--begin::Label-->
                            <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                                <span class="required">Date fin</span>
                                </span>
                            </label>
                            <!--end::Label-->
                            <!--begin::Input-->
                            <input class="form-control form-control-solid attr_date" placeholder="Date et heure de fin"
                                id="end" name="end" value="" />
                            <!--end::Input-->
                            @if ($errors->has('end'))
                                        <div class="text-danger">{{ $errors->first('end') }}</div>
                                    @endif
                        </div>

                    </div>
                    <!--end::-->

                    <!--begin::-->
                    <div class="fv-row mb-5 row">
                        <div class="col-md-3">
                            <!--begin::Label-->
                            <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                                <span class="required">Prénoms</span>
                                </span>
                            </label>
                            <!--end::Label-->
                            <!--begin::Input-->
                            <input class="form-control form-control-solid" placeholder="" name="first_name"
                                value="" />
                            <!--end::Input-->
                            @if ($errors->has('first_name'))
                                        <div class="text-danger">{{ $errors->first('first_name') }}</div>
                                    @endif
                        </div>
                        <div class="col-md-3">
                            <!--begin::Label-->
                            <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                                <span class="required">Nom</span>
                                </span>
                            </label>
                            <!--end::Label-->
                            <!--begin::Input-->
                            <input class="form-control form-control-solid" placeholder="" name="last_name"
                                value="" />
                            <!--end::Input-->
                            @if ($errors->has('last_name'))
                                        <div class="text-danger">{{ $errors->first('last_name') }}</div>
                                    @endif
                        </div>
                        <div class="col-md-3">
                            <!--begin::Label-->
                            <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                                <span class="required">Téléphone</span>
                                </span>
                            </label>
                            <!--end::Label-->
                            <!--begin::Input-->
                            <input class="form-control form-control-solid" placeholder="" name="phone" type="tel"
                                value="" />
                            <!--end::Input-->
                            @if ($errors->has('phone'))
                                        <div class="text-danger">{{ $errors->first('phone') }}</div>
                                    @endif
                        </div>
                        <div class="col-md-3">
                            <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                                <span class="required">Adresse</span>
                                </span>
                            </label>
                            <!--end::Label-->
                            <!--begin::Input-->
                            <input class="form-control form-control-solid" placeholder="" name="address"
                                value="" />
                            <!--end::Input-->
                            @if ($errors->has('address'))
                                        <div class="text-danger">{{ $errors->first('address') }}</div>
                                    @endif
                        </div>
                    </div>
                    <!--end::-->

                    <!--begin::-->
                    <div class="fv-row mb-5 row">
                        <div class="col-md-3">
                            <!--begin::Label-->
                            <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                                <span class="required">Type de pièce</span>
                                </span>
                            </label>
                            <!--end::Label-->
                            <!--begin::Input-->
                            <select class="form-select cars" data-control="select2"
                                data-placeholder="Choisir le type de pièce" name="type_part">
                                <option></option>
                                @forelse ($typePart as $key => $item)
                                    {{-- @php
                                        $slted = (int)$key === $type_part ? 'selected="selected"' : '';
                                    @endphp --}}
                                    <option value="{{ $key }}">{{ $item }}</option>
                                @empty
                                @endforelse
                            </select>
                            <!--end::Input-->
                            @if ($errors->has('type_part'))
                                        <div class="text-danger">{{ $errors->first('type_part') }}</div>
                                    @endif
                        </div>

                        <div class="col-md-3">
                            <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                                <span class="required">Numéro de pièce</span>
                                </span>
                            </label>
                            <!--end::Label-->
                            <!--begin::Input-->
                            <input class="form-control form-control-solid" placeholder="" name="number_part"
                                value="" />
                            <!--end::Input-->
                            @if ($errors->has('number_part'))
                                        <div class="text-danger">{{ $errors->first('number_part') }}</div>
                                    @endif
                        </div>

                        <div class="col-md-3">
                            <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                                <span class="required">Numéro de permis</span>
                                </span>
                            </label>
                            <!--end::Label-->
                            <!--begin::Input-->
                            <input class="form-control form-control-solid" placeholder="" name="number_permit"
                                value="" />
                            <!--end::Input-->
                        </div>
                        <div class="col-md-3">
                            <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                                <span class="required">Email</span>
                                </span>
                            </label>
                            <!--end::Label-->
                            <!--begin::Input-->
                            <input type="email" class="form-control form-control-solid" placeholder=""
                                name="email" value="" />
                            <!--end::Input-->
                        </div>
                    </div>
                    <!--end::-->


                    <!--begin::-->
                    <div class="mb-5 row">
                        <div class="col-md-6">
                            <div class="form-check form-switch form-check-custom form-check-solid mb-5">
                                <input class="form-check-input h-20px w-30px" type="checkbox" id="account" />
                                <label class="form-check-label text-primary" for="paid">
                                    Je verse un account
                                </label>
                            </div>
                            <!--begin::Input-->
                            <input class="form-control form-control-solid d-none" id="input_account" placeholder=""
                                name="account" />
                            <!--end::Input-->
                        </div>
                        <div class="col-md-6">
                            <div class="form-check form-switch form-check-custom form-check-solid mb-5">
                                <input class="form-check-input h-20px w-30px" type="checkbox" id="delivery" />
                                <label class="form-check-label text-primary" for="paid">
                                    Me faire livrer le véhicule
                                </label>
                            </div>
                            <!--begin::Input-->
                            <input class="form-control form-control-solid d-none" id="input_delivery" placeholder=""
                                name="delivery" value="" />
                            <!--end::Input-->
                        </div>

                    </div>
                    <!--end::-->


                    <div class="form-check form-switch form-check-custom form-check-solid mb-2">
                        <input class="form-check-input h-20px w-30px" type="checkbox" id="paid" name="is_paid"
                            {{ !empty($is_paid) ? 'checked' : '' }} />
                        <label class="form-check-label text-primary" for="paid">
                            Je paie la totalité
                        </label>
                    </div>

                    <div class="form-check form-switch form-check-custom form-check-solid mb-5">
                        <input class="form-check-input h-20px w-30px" type="checkbox" id="conductor"
                            name="conductor" {{ !empty($conductor) ? 'checked' : '' }} />
                        <label class="form-check-label text-primary" for="paid">
                            Je désire un conducteur
                        </label>
                    </div>

                    {{-- <div class="form-check form-switch form-check-custom form-check-solid mb-5">
                        <input class="form-check-input h-20px w-30px" type="checkbox" id="conductor"
                            name="conductor" />
                        <label class="form-check-label text-primary" for="paid">
                            Je verse un account
                        </label>
                    </div>

                    <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                        <span class="required">Account</span>
                        </span>
                    </label>
                    <!--end::Label-->
                    <!--begin::Input-->
                    <input class="form-control form-control-solid" placeholder="" name="email" value="" />
                    <!--end::Input--> --}}


                    <div class="fv-row mt-5 row">
                        <!--begin::Label-->
                        <label class="d-flex align-items-center fs-5 fw-semibold mb-2">
                            <span class="required">Total</span>
                            </span>
                        </label>
                        <!--end::Label-->
                        <!--begin::Input-->
                        <input class="form-control form-control-solid text-end text-primary" id="input_totat"
                            name="total" type="text" placeholder="0.00" />
                        <!--end::Input-->
                    </div>




                    <div class="card-footer text-center">
                        <button type="submit" class="btn btn-primary w-100" id="{{ $button['save'] }}">Reserver</button>
                    </div>

                </form>
            </div>
            <!--end::Card body-->
        </div>
    </div>
    <!--end::Container-->

</x-backoffice.back-layout>
