@extends('layouts.index')
@section('content')

<div class="pagetitle">
    <h1>REGISTRE </h1>
</div><!-- End Page Title -->

<section class="section">

    @if ($message = Session::get('success'))
    <div class="alert alert-success alert-block">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <strong>{{ $message }}</strong>
    </div>
    @endif

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">
                    <h5 class="card-title">LISTE DES LIGNES</h5>
                    <!-- Table with stripped rows -->
                    <table class="table datatable">
                        <thead>
                            <tr>
                                <tr>
                                    <th scope="col">#</th>
                                    <th scope="col">NOM LIGNE</th>
                                    <th scope="col">VILLE DEPART</th>
                                    <th scope="col">VILLE ARRIVEE</th>
                                    <th scope="col">COÜT</th>
                                    <th scope="col">GARE</th>
                                    <th scope="col">RESPONSABLE</th>
                                </tr>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($listLignes as $ligne)
                            <tr>
                                <th scope="row">{{ $ligne->id }}</th>
                                <td>{{ $ligne->nom_ligne }}</td>
                                <td>{{ $ligne->ville_deb}}</td>
                                <td>{{ $ligne->ville_fin }} </td>
                                <td>{{ $ligne->distance }} </td>
                                <td>{{ $ligne->gare->nom_gare }} </td>
                                <td>{{ $ligne->personne->nom }} - {{ $ligne->personne->prenom }} </td>
                                <td>
                                    <div class="dropdown">
                                        <button class="btn btn-danger dropdown-toggle btn-sm" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
                                            Actions
                                        </button>
                                        <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
                                            <li>
                                                <a class="dropdown-item" href="#" data-bs-toggle="modal" data-bs-target="#editligne_{{ $ligne->id }}">Modifier</a>
                                            </li>
                                        </ul>
                                    </div>

                                    {{-- Modal POUR AJOUT LIGNE --}}
                                    <!-- form action="" method="POST">
                                        @csrf
                                        {{--@method('PUT')--}}
                                        <div class="modal fade" id="editligne_{{ $ligne->id }}" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                            <div class="modal-dialog">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <h5 class="modal-title" id="exampleModalLabel">Ajout de Ligne</h5>
                                                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                                    </div>
                                                    <div class="modal-body">
                                                        <input type="hidden" value="{{ $ligne->id }}" name="id">
                                                        FORMULAIRE DE MODIFICATION DE LIGNE  : <span class="fw-bold fst-italic">{{ $ligne->nom_ligne }}</span> ?
                                                        <div class="row mb-3">
                                                            <div class="col-sm-8">
                                                                </br>
                                                            </div>
                                                        </div>

                                                        <div class="row mb-3">
                                                            <label class="col-sm-4 col-form-label">NOM LIGNE :</label>
                                                            <div class="col-sm-8">
                                                                <input type="text" value="{{ $ligne->contact }}" name="nom_ligne" class="form-control">
                                                            </div>
                                                        </div>

                                                        <div class="row mb-3">
                                                            <label class="col-sm-4 col-form-label">VILLE DEPART :</label>
                                                            <div class="col-sm-8">
                                                                <input type="text" value="{{$ligne->gare->commune->libelle }}" name="ville_deb" class="form-control" readonly = true>
                                                            </div>
                                                        </div>

                                                        <div class="row mb-3">
                                                            <label class="col-sm-4 col-form-label">QUART. DEPART :</label>
                                                            <div class="col-sm-8">
                                                                <input type="text" value="{{ $ligne->contact }}" name="quartier_deb" class="form-control">
                                                            </div>
                                                        </div>

                                                        <div class="row mb-3">
                                                            <label class="col-sm-4 col-form-label">VILLE ARRIVEE :</label>
                                                            <div class="col-sm-8">
                                                                <select class="form-select" name="ville_fin" aria-label="Default select example"  readonly = true>
                                                                    <option selected>Choisir Ici</option>
                                                                    @foreach($allCommunes as $commune)
                                                                        <option value="{{$commune->libelle }}">{{ $commune->libelle }}</option>
                                                                    @endforeach
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="row mb-3">
                                                            <label class="col-sm-4 col-form-label">QUART. ARRIVE :</label>
                                                            <div class="col-sm-8">
                                                                <input type="text" value="{{ $ligne->contact }}" name="quartier_arr" class="form-control">
                                                            </div>
                                                        </div>

                                                        <div class="row mb-3">
                                                            <label class="col-sm-4 col-form-label"> RESPONSABLE :</label>
                                                            <div class="col-sm-8">
                                                                <select class="form-select" name="personne_id" aria-label="Default select example">
                                                                    <option selected>Choisir Ici</option>
                                                                    @foreach($allPersonnes as $personne)
                                                                        <option value="{{$personne->id }}">{{ $personne->nom }} - {{ $personne->prenom }}</option>
                                                                    @endforeach
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="row mb-3">
                                                            <label class="col-sm-4 col-form-label">COÛT :</label>
                                                            <div class="col-sm-8">
                                                                <input type="text" value="{{ $ligne->contact }}" name="distance" class="form-control">
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="submit" class="btn btn-primary">VALIDER</button>
                                                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">QUITTER</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </form-->
                                    {{-- Modal POUR EDITER--}}
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                    <!-- End Table with stripped rows -->
                    <div class="row mb-3">

                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

@endsection
