<div class="form-group {{ $errors->has('id_filiere') ? 'has-error' : ''}}">
    <label for="id_filiere" class="control-label">{{ 'Filière' }}</label>
    <select name="id_filiere" class="form-control" id="id_filiere" required="required">
    @foreach ($filieres as $filiere)
        <option
            value="{{ $filiere->idFiliere }}" {{ (isset($jury->id_filiere) && $jury->id_filiere == $filiere->idFiliere) ? 'selected' : ''}}
            {{ (isset($selected_filiere) && $selected_filiere == $filiere->idFiliere) ? 'selected' : ''}}
        >
            {{ $filiere->intituleFilieres }}
        </option>
    @endforeach
    </select>
    {!! $errors->first('id_filiere', '<p class="help-block">:message</p>') !!}
</div>
<div class="form-group">
    <label for="id_niveau" class="control-label">{{ 'Niveau formation' }}</label>
    <select name="id_niveau" class="form-control" id="id_niveau" required="required">
        <option value="2" {{ (isset($niveau) && $niveau == 2) ? 'selected' : ''}}> Master </option>
        <option value="0" {{ (isset($niveau) && $niveau == 0) ? 'selected' : ''}}> Master Grade Ingénieur</option>
        <option value="1" {{ (isset($niveau) && $niveau == 1) ? 'selected' : ''}}> Licence </option>
    </select>
</div>
<div class="form-group {{ $errors->has('id_etudiant') ? 'has-error' : ''}}">
    <label for="id_etudiant" class="control-label">{{ 'Etudiant' }}</label>
    <select
        name="id_etudiants[]"
        class="select2 m-b-10 select2-multiple"
        multiple="multiple"
        data-placeholder="Choisir"
        id="id_etudiants"
        required
    >
    @foreach ($etudiants as $etudiant)
        <option
            value="{{ $etudiant->matricule }}"
            {{ (isset($etudiants_matricules) && in_array($etudiant->matricule, $etudiants_matricules)) ? 'selected' : ''}}
        >
                {{ $etudiant->nom }} {{ $etudiant->prenom }}
        </option>
    @endforeach
    </select>
    {!! $errors->first('id_etudiant', '<p class="help-block">:message</p>') !!}
</div>
<div class="form-group {{ $errors->has('president') ? 'has-error' : ''}}">
    <label for="president" class="control-label">{{ 'President' }}</label>
    <select name="president" class="form-control" id="president"  required>
        <option disabled selected value> -- Choisir le president -- </option>
    @foreach ($membres_jury as $membre_jury)
        <option
            value="{{ $membre_jury->id }}"
            {{ (isset($jury->president) && $jury->president == $membre_jury->id) ? 'selected' : ''}}
        >
                {{ $membre_jury->nom }} {{ $membre_jury->prenoms }}
        </option>
    @endforeach
    </select>
    {!! $errors->first('president', '<p class="help-block">:message</p>') !!}
</div>
<div class="form-group {{ $errors->has('maitre_memoire') ? 'has-error' : ''}}">
    <label for="maitre_memoire" class="control-label">{{ 'Maitre Memoire' }}</label>
    <select name="maitre_memoire" class="form-control" id="maitre_memoire"   required>
        <option disabled selected value> -- Choisir le maitre memoire -- </option>
        @foreach ($membres_jury as $membre_jury)
            <option
                value="{{ $membre_jury->id }}"
                {{ (isset($jury->maitre_memoire) && $jury->maitre_memoire == $membre_jury->id) ? 'selected' : ''}}
            >
                    {{ $membre_jury->nom }} {{ $membre_jury->prenoms }}
            </option>
        @endforeach
    </select>
    {!! $errors->first('maitre_memoire', '<p class="help-block">:message</p>') !!}
</div>
<div class="form-group {{ $errors->has('membres') ? 'has-error' : ''}}">
    <label for="membres" class="control-label">{{ 'Membres' }}</label>
    <select
        name="membres[]"
        class="select2 m-b-10 select2-multiple"
        multiple="multiple"
        data-placeholder="Choisir"
        id="membres"
        required
    >
        @foreach ($membres_jury as $membre_jury)
            <option
                class="membre-select"
                value="{{ $membre_jury->id }}"
                {{ (isset($membres_ids) && in_array($membre_jury->id, $membres_ids)) ? 'selected' : ''}}
            >
                    {{ $membre_jury->nom }} {{ $membre_jury->prenoms }}
            </option>
        @endforeach
    </select>
    {!! $errors->first('membres', '<p class="help-block">:message</p>') !!}
</div>
<div class="form-group {{ $errors->has('sujet') ? 'has-error' : ''}}">
    <label for="sujet" class="control-label">{{ 'Sujet' }}</label>
    <textarea
        class="form-control"
        name="sujet"
        type="text"
        id="sujet"
        rows="5"
        required
    >{{ isset($jury->sujet) ? $jury->sujet : '' }}</textarea>
    {!! $errors->first('sujet', '<p class="help-block">:message</p>') !!}
</div>
<div class="form-group {{ $errors->has('id_salle') ? 'has-error' : ''}}" >
    <label for="id_salle" class="control-label">{{ 'Salle' }}</label>
    <select
        name="id_salle"
        class="form-control"
        id="id_salle"
        required
    >
    @foreach ($salles as $salle)
        <option
            value="{{ $salle->id }}"
            {{ (isset($jury->id_salle) && $jury->id_salle == $salle->id) ? 'selected' : ''}}
        >
                {{ $salle->nom }}
        </option>
    @endforeach
    </select>
    {!! $errors->first('id_salle', '<p class="help-block">:message</p>') !!}
</div>
<div class="form-group {{ $errors->has('signataire') ? 'has-error' : ''}}">
    <label for="signataire" class="control-label">{{ 'Signataire' }}</label>
    <select
        name="signataire"
        class="form-control"
        id="signataire"
        required
    >
    @foreach ($signataires as $signataire)
        <option
            value="{{ $signataire->id }}"
            {{ (isset($jury->signataire) && $jury->signataire == $signataire->id) ? 'selected' : ''}}
        >
                {{ $signataire->nom }} {{ $signataire->prenoms }}
        </option>
    @endforeach
    </select>
    {!! $errors->first('signataire', '<p class="help-block">:message</p>') !!}
</div>
<div class="form-group {{ $errors->has('id_salle') ? 'has-error' : ''}}">
    <label for="type_numero" class="control-label">{{ 'Numero' }}</label>
    <select
        name="type_numero"
        class="form-control"
        id="type_numero"
        required
    >
        <option
            value="vide"
            {{ (isset($jury->type_numero) && $jury->type_numero == 'vide') ? 'selected' : ''}}
        >
            vide
        </option>
        <option
            value="automatique"
            {{ (isset($jury->type_numero) && $jury->type_numero == 'automatique') ? 'selected' : ''}}
        >
            automatique
        </option>
    </select>
    {!! $errors->first('id_salle', '<p class="help-block">:message</p>') !!}
</div>
<div class="form-group {{ $errors->has('date') ? 'has-error' : ''}}">
    <label for="date" class="control-label">{{ 'Date' }}</label>
    <input
        class="form-control"
        name="date"
        type="date"
        id="date"
        value="{{ isset($jury->date) ? $jury->date : ''}}"
        required
    >
    {!! $errors->first('date', '<p class="help-block">:message</p>') !!}
</div>
<div class="form-group {{ $errors->has('heure_debut') ? 'has-error' : ''}}">
    <label for="heure_debut" class="control-label">{{ 'Heure Debut' }}</label>
    <input
        class="form-control"
        name="heure_debut"
        type="time"
        id="heure_debut"
        value="{{ isset($jury->heure_debut) ? $jury->heure_debut : ''}}"
        required
    >
    {!! $errors->first('heure_debut', '<p class="help-block">:message</p>') !!}
</div>
<div class="form-group">
    <label for="verification_grade" class="control-label">{{ 'Verification grade' }}</label>
    <select name="verification_grade" class="form-control" id="verification_grade">
        <option value="oui" selected> oui </option>
        <option value="non" > non </option>
    </select>
</div>
<div class="form-group">
    <label for="verification_conflicts" class="control-label">{{ 'Verification conflicts' }}</label>
    <select name="verification_conflicts" class="form-control" id="verification_conflicts">
        <option value="oui" selected> oui </option>
        <option value="non" > non </option>
    </select>
</div>
<div class="form-group">
    <input class="btn btn-primary" type="submit" value="{{ $formMode === 'edit' ? 'Modifier' : 'Créer' }}">
</div>
<script src="{{ asset('ample-admin/plugins/bower_components/jquery/dist/jquery.min.js')}}"></script>
<script type="text/javascript">
    $('#president').change(function() {     
        const val = $(this).val();
        console.log('----------- president change: ', val)
        $('#maitre_memoire option').each(function() {
            if ($(this).val() == val) {
                $(this).css('display', 'none')
            } else $(this).css('display', 'block')
        });
    });
    $('#maitre_memoire').change(function() {     
        const val = $(this).val();
        $('#president option').each(function() {
            if ($(this).val() == val) {
                $(this).css('display', 'none')
            } else $(this).css('display', 'block')
        });
    });
    $('#membres').change(function() {     
        const val = $(this).val();
        $('#maitre_memoire option').each(function() {
            if ($(this).val() == val) {
                $(this).css('display', 'none')
            } else $(this).css('display', 'block')
        });
        $('#membres option').each(function() {
            if ($(this).val() == val) {
                $(this).css('display', 'none')
            } else $(this).css('display', 'block')
        });
    });
</script>