@extends('layouts.app')

@section('head')
    <style>
        form {
            width: 100%;
            max-width: 500px;
            margin: 0 auto;
        }

        label {
            display: block;
            margin-top: 20px;
        }

        input,
        textarea {
            width: 100%;
            padding: 10px;
            margin-top: 5px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        input[type="submit"] {
            margin-top: 20px;
            background-color: green;
            color: white;
        }


    </style>
@endsection
@section('content')
<div class="container">

    <form action="{{ route('evenst.update', ['evenst' => $evenst->id]) }}" method="POST">
        @csrf

        <label for='numero'>{{ __('Numero Billet') }}</label>
                <input type='text' class='form-control' id='numero' name='numero' value='{{ $billet->numero }}'>

        <div class="row">
            <div class="col-md-6">
                
                <label for='title'>{{ __('Titre Event') }}</label>
                <input type='text' class='form-control' id='title' name='title' value='{{ $billet->title }}' >
                <?php
                    use App\Models\Chauffeur;

                    $chauffeurs = Chauffeur::all();
                    $selectedVehicle = $billet->chauffeur_id;

            
                ?>
                <label for="vehicule">{{__('Vehicule')}}</label>

<select name="vehicule" id="vehicule" class="form-select">
 
    @foreach($chauffeurs as $chauffeur)
                <option value="{{ $chauffeur->id }}" {{ $selectedVehicle == $chauffeur->id ? 'selected' : '' }}>
                    {{ $chauffeur->name }}
                </option>
    @endforeach
</select>

                <label for="driver1">{{__('Chauffeur 1')}}</label>
                <input type='text' class='form-control' id='driver1' name='chauffeur1' value='{{ $billet->chauffeur1 }}' >

                <label for="telephone1">{{__('Telephone 1')}}</label>
                <input type='text' class='form-control' id='telephone1' name='telephone1' value='{{ $billet->telephone1 }}' >

                <label for="driver2">{{__('Chauffeur 2')}}</label>
                <input type='text' class='form-control' id='driver2' name='chauffeur2' value='{{ $billet->chauffeur2 }}' >

                <label for="telephone2">{{__('Telephone 2')}}</label>
                <input type='text' class='form-control' id='telephone2' name='telephone2' value='{{ $billet->telephone2 }}' >
                <label for="startTime">{{__('Début')}}</label>
                <input type='time' class='form-control' id='startTime' name='heure_debut' value='{{ $billet->heure_debut }}'>
                <label for="endTime">{{__('Fin Prévue')}}</label>
                <input type='time' class='form-control' id='endTime' name='heure_fin' value='{{ $billet->heure_fin }}'>

       


            </div>

            <div class="col-md-6">
                

              

                <label for="address">{{__('Addresse')}}</label>
                <input type='text' class='form-control' id='address' name='adresse' value="{{ $billet->adresse }}">

                <label for="clientAddress">{{__('Client Addresse')}}</label>
                <input type='text' class='form-control' id='clientAddress' name='adresseclient' value="{{ $billet->adresseclient }}">

                <label for="date">{{__('Date')}}</label>
                <input type='date' class='form-control' id='date' name='date' value="{{ $billet->date }}">


                <label for="clientName">{{__('Client Name')}}</label>
                <input type='text' class='form-control' id='clientName' name='nom' value="{{ $billet->nom }}">

                <label for="clientPhoneNumber">{{__('Client Numero Telephone')}}</label>
                <input type='text' class='form-control' id='clientPhoneNumber' name='numero_telephone' value="{{ $billet->numero_telephone }}">
                <label for="email">{{__('Client Email')}}</label>
                <input type='text' class='form-control' id='email' name='email'>
                <label for="travelReason">{{__('Motif Deplacement')}}</label>
                <input type='text' class='form-control' id='travelReason' name='motif_deplacement' value="{{ $billet->motif_deplacement }}">


                <label for="passengerCount">{{__('Nombre Passengers')}}</label>
                <input type='number' class='form-control' id='passengerCount' name='nbr_passagers' value="{{ $billet->nbr_passagers }}">

            </div>
        </div>

        <div class="row mt-3" style="
    float: right;">
            <div class="col-md-12 ">
                <input type="submit" value="Confirmé" class="btn btn-success" />
            </div>
        </div>
    </form>
</div>

<script>

const urlParams = new URLSearchParams(window.location.search);


const dateParam = urlParams.get('date');


const dateField = document.getElementById('date');

if (dateParam) {
  dateField.value = dateParam;
} else {
  console.error('Date parameter is missing in the URL');
}




function getParameterByName(name, url) {
            if (!url) url = window.location.href;
            name = name.replace(/[\[\]]/g, '\\$&');
            var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
                results = regex.exec(url);
            if (!results) return null;
            if (!results[2]) return '';
            return decodeURIComponent(results[2].replace(/\+/g, ' '));
        }

        var eventDataString = getParameterByName('event');

        if (eventDataString) {
       
            var eventData = JSON.parse(eventDataString);

       
            document.getElementById('title').value = eventData.title;
            document.getElementById('start').value = eventData.start;
            document.getElementById('end').value = eventData.end;
            document.getElementById('description').value = eventData.extendedProps.description;
    
        } else {
            console.error('No event data found in the query parameter.');
        }


        function confirmDelete() {
            var userConfirmed = confirm("Êtes-vous sûr? La suppression est irréversible!");
            if (userConfirmed) {
                // If user confirms, submit the form
                document.getElementById("deleteForm").submit();
            }
        }
</script>
@endsection