@extends('layouts.test')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-lg-12 margin-tb">
            <div class="pull-right">
                <a class="btn btn-success" href="{{ route('billets.create') }}">Nouveau Billet</a>
                <a class="btn btn-success" id="chButton" href="{{ route('chauffeurs.create') }}">Nouveau Véhicule</a>

            </div>
        </div>
      
    </div>
    <br><br>
    @if ($message = Session::get('success'))
        <div class="alert alert-success">
            <p>{{ $message }}</p>
        </div>
    @endif

    <table class="table table-bordered">
        <tr>
            <th>N°Billet</th>
            <th>Date</th>
            <th>Nom Client</th>
            <!-- Add more table headers as needed -->
            <th width="280px">Action</th>
        </tr>
        @foreach ($billets as $billet)
            <tr>
                <td>{{ $billet->numero }}</td>
                <td>{{ $billet->date }}</td>
                <td>{{ $billet->nom }}</td>
                <!-- Add more table cells as needed -->
                <td>
                    <form id="deleteForm" action="{{ route('billets.destroy', $billet->id) }}" method="POST">
                        <a class="btn btn-info" href="{{ route('billets.show', $billet->id) }}">Imprimer</a>
                        <a class="btn btn-primary" href="{{ route('billets.edit', $billet->id) }}">Edit</a>
                        @csrf
                        @method('DELETE')
                        <button type="button" class="btn btn-danger" onclick="confirmDelete()">Supprimer</button>
            
                    </form>
                </td>
            </tr>
        @endforeach
    </table>

    {!! $billets->links() !!}
</div>
    <script>
        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
