@php
    $data = $data['user_infos'];
@endphp

<template id="user-info">
    <swal-title>
        Changer d'etablissement......
    </swal-title>
    <swal-html>
        <div class="contact-form create-form">
            <div class="form-wrapper pt-0">
                <form class="mx-2" id="contact-form" style="display: block; overflow-x: hidden;"  action="{{ route('home') }}"  method = "POST">
                    @csrf
                    <div class="row single-form">
                        <label
                            class="col-sm-5 mt-2 text-end fs-5 form-label"
                            style="font-weight: bold;"
                            for="matricule"
                        >
                            <strong>Matricule:</strong>
                        </label>

                        <div class="col-sm-7">
                            <input
                                required
                                readonly
                                id="matricule"
                                name="matricule"
                                type="number"
                                class="form-control form-control-line fs-5"
                                value="{{$data['matricule']}}"
                            >
                        </div>
                    </div>

                    <div class="row single-form">
                        <label
                            class="col-sm-5 mt-2 text-end fs-5 form-label"
                            style="font-weight: bold;"
                            for="nom">Nom:
                        </label>

                        <div class="col-sm-7">
                            <input
                                required
                                readonly
                                id="nom"
                                name="nom"
                                class="form-control form-control-line fs-5"
                                type="text"
                                placeholder=""
                                value="{{$data['nom']}}"
                            >
                        </div>
                    </div>
                    <div class="row single-form">
                        <label
                            class="col-sm-5 mt-2 text-end fs-5 form-label"
                            style="font-weight: bold;"
                            for="prenom"
                        >
                            Prénom:
                        </label>
                        <div class="col-sm-7">
                            <input
                                required
                                readonly
                                id="prenom"
                                name="prenom"
                                class="form-control form-control-line fs-5"
                                type="text"
                                placeholder=""
                                value="{{$data['prenom']}}"
                            >
                        </div>
                    </div>

                    <div class="row single-form">
                        <label
                            class="col-sm-5 mt-2 text-end fs-5 form-label"
                            style="font-weight: bold;"
                            for="email"
                        >
                            Email:
                        </label>

                        <div class="col-sm-7">
                            <input
                                required
                                {{ (session('type_user') != 3 ) ? 'readonly' : '' }}
                                id="email"
                                name="email"
                                type="email"
                                class="form-control fs-5"
                                placeholder=""
                                value="{{$data['email']}}"
                            >
                        </div>

                    </div>

                    <div class="row single-form">
                        <label
                            class="col-sm-5 mt-2 text-end fs-5 form-label"
                            style="font-weight: bold;"
                            for="phone"
                        >
                            Phone
                        </label>

                        <div class="col-sm-7">
                            <input
                                required
                                {{ (session('type_user') != 3 ) ? 'readonly' : '' }}
                                id="phone"
                                name="phone"
                                type="number"
                                class="form-control fs-5"
                                placeholder=""
                                value="{{$data['phone']}}"
                            >
                        </div>

                    </div>

                    <div class="row single-form">
                        <label class="col-sm-5 mt-2 text-end fs-5 form-label fw-bold" for="role">
                            Catégorie :
                        </label>

                        <div class="col-sm-7 input-modal">
                            <select
                                class="form-control fs-5 border-info custom-select2"
                                name="role"
                                data-border-color="info"
                                data-border-variation="darken-2"
                                data-text-color="info"
                                data-text-variation="darken-3"
                                style="width: 100%;height: 36px;"
                            >
                                @php
                                    $role = userRole( session('type_user'), true );
                                @endphp

                                @foreach ($role as $ind => $tile)
                                    <option value='{{ $ind }}' {{ (session('type_user') == $ind ) ? 'selected' : '' }}>{{ $tile }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>

                    <div class="row single-form">
                        <label class="col-sm-5 mt-2 text-end fs-5 form-label fw-bold" for="etablissement">
                            Etablissement :
                        </label>

                        <div class="col-sm-7">
                            <select
                                class="form-control fs-5 border-info custom-select2"
                                name="etablissement"
                                data-border-color="info"
                                data-border-variation="darken-2"
                                data-text-color="info"
                                data-text-variation="darken-3"
                                style="width: 100%;height: 36px;"
                            >
                                @if (session('type_user') == 3)
                                    @php
                                        $schools_info = getUserEta();

                                        $mes_eta = $schools_info['etablissements'];
                                        $universites = $schools_info['universites'];
                                    @endphp

                                    {{--
                                    @foreach ($universites as $universite)
                                        @if ( isset($mes_eta[$universite['idUniversite']]) )
                                            @php
                                                $etab = $mes_eta[$universite['idUniversite']];
                                            @endphp
                                            <optgroup label="{{ $universite['descruni'].' ('.$universite['sigleuni'].')'}}">
                                                @foreach ($etab as $eta)
                                                    <option
                                                        value="{{$eta['idEtablissement']}}"
                                                        {{ (session('id_etablissement') == $eta['idEtablissement'] ) ? 'selected' : '' }}
                                                    >
                                                        {{$eta['sigle']}}
                                                    </option>
                                                @endforeach
                                            </optgroup>
                                        @endif
                                    @endforeach
                                    --}}
                                    @foreach ($mes_eta as $eta)
                                        <option
                                            value="{{$eta['idEtablissement']}}"
                                            {{ (session('id_etablissement') == $eta['idEtablissement'] ) ? 'selected' : '' }}
                                        >
                                            {{$eta['sigle']}}
                                        </option>
                                    @endforeach
                                @else
                                    <option value='{{ session('id_etablissement') }}' selected>{{ session('sigle') }}</option>
                                @endif
                            </select>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </swal-html>

    @if (session('type_user') == 3)
        <swal-button type="confirm"> Sauvegarder </swal-button>
        <swal-button type="cancel"> Annuler </swal-button>
    @endif

    <swal-param name="allowEscapeKey" value="true" />
    <swal-param name="customClass" value='{ "popup": "my-popup" }' />
</template>

