@extends('template')


@section('script')
{!! Html::script('js/filtrage_banque.js') !!}

@endsection

@section('nav')
        <!-- nav Bar !-->
<div class="navbar-fixed">
    <ul id="dropdown1" class="dropdown-content" style="top : 20px">
        <li><a href="/auth/logout" class="logout">Logout</a></li>
    </ul>
    <nav>
        <div class="nav-wrapper">
            <a href="#" class="brand-logo center ">Modification {{$session->nom}}</a>
            <ul class="right hide-on-med-and-down">
                <li><a class="dropdown-button" href="#!"
                       data-activates="dropdown1">{{ \Illuminate\Support\Facades\Auth::user()->login  }}<i
                                class="material-icons right">more_vert</i></a></li>
            </ul>
        </div>
    </nav>
</div>
<!-- nav Bar !-->
@endsection

@section('contenu')

    <div id="progress" class="progress" style="display:none">
        <div class="indeterminate"></div>
    </div>
    <div class="container">

        <!-- Form !-->
         <form action="edit" method="post">
            {!! csrf_field() !!}
        <div class="row">
            <div class="col s12 m9 l10">

                <!-- Date et Niveau !-->
                <div id="Date_Niveau" class="section scrollspy">
                    <br>
                    <br>
                    <br>
                    <!-- Nom du Session  !-->
                    <div class="input-field col s12">
                     <h4 class="light-blue-text text-darken-1 center" >Nom Session</h4>
                      <input id="nom_session" name="nom_session" type="text" value="{{$session->nom}}"
                                           class="validate">
                   
                    </div>
                    <!-- Nom du Session  !-->
                    <br>
                    <br>
                    <!-- Niveau !-->
                    <h4 class="light-blue-text text-darken-1 center">Niveau</h4>

                    <div class="input-field col s12">

                        <select name="id_niveau">
                            <option value="" disabled selected>Choisir Niveau</option>
                            @foreach ($niveaux as $niveau)
                                @if ($session->id_Niveau==$niveau->id_Niveau)
                                      <option value={!! $niveau->id_Niveau !!} selected>{!! $niveau->niveau !!}</option>
                                    @else
                                       <option value={!! $niveau->id_Niveau !!} >{!! $niveau->niveau !!}</option>
                                    } 
                                 @endif
                                
                            @endforeach
                        </select>
                    </div>
                    <!-- Niveau !-->
                </div>
                <!-- Date et Niveau !-->


                <!-- Medecin Observateur !-->
                <div id="MO" class="section scrollspy">
                    <br>
                    <br>
                    <h4 class="light-blue-text text-darken-1 center">Medecins Observateurs</h4>

                    <div class="input-field">
                        <input id="search" type="search" >
                        <label for="search"><i class="material-icons">search</i></label>
                    </div>
                    <table class="highlight">

                        <thead class="thead">
                        <tr>
                            <th data-field="cin">CIN</th>
                            <th data-field="nom">Nom</th>
                            <th data-field="prenom">Prenom</th>
                            <th></th>

                        </tr>
                        </thead>


                        <tbody class="tbody" id="med">
                            <?php $i=0; ?>
                        @foreach ($medecin_observers as $observer)
                            <tr id={!! $observer->id_Enseignant."css" !!} >
                                <td>{!! $observer->CIN !!}</td>
                                <td>{!! $observer->nom !!}</td>
                                <td>{!! $observer->prenom !!}</td>
                                <td>
                                    @if($array[$i]==true)
                                    <input type="checkbox" value="yes"
                                           name={!! $observer->id_Enseignant."" !!} id={!! $observer->id_Enseignant."" !!} checked />
                                    <label for={!! $observer->id_Enseignant !!} >Check</label>
                                    @else 
                                         <input type="checkbox" value="yes"
                                           name={!! $observer->id_Enseignant."" !!} id={!! $observer->id_Enseignant."" !!} />
                                    <label for={!! $observer->id_Enseignant !!} >Check</label>
                                    @endif
                                </td>
                            </tr>
                            <?php $i++ ?>
                        @endforeach

                        </tbody>
                    </table>
                </div>

                <!-- Medecin Observateur !-->


                <!-- Patient Simulé !-->
                <div id="PS" class="section scrollspy">
                    <br>
                    <br>
                    <br>
                    <h4 class="light-blue-text text-darken-1 center">Patient Simulés</h4>
                    <table id="table_patient">
                        <tr>
                            <td>
                                <div class="input-field col s12">
                                    <input id="input_patient_CIN1" name="input_patient_CIN1" type="text"
                                           class="validate">
                                    <label for="input_patient_CIN1">CIN</label>
                                </div>
                            </td>

                            <td>
                                <div class="input-field col s12">
                                    <input id="input_patient_nom1" name="input_patient_nom1" type="text"
                                           class="validate"/>
                                    <label for="input_patient_nom1">Nom</label>
                                </div>
                            </td>
                            <td>
                                <div class="input-field col s12">
                                    <input id="input_patient_prenom1" name="input_patient_prenom1" type="text"
                                           class="validate"/>
                                    <label for="input_patient_prenom1">Prenom</label>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
                <!-- Patient Simulé !-->
                <div class="row center">
                     <div class="row center">
                        <input type="submit" class="waves-effect waves-light btn" onclick="show()"/>
                    </div>
                </div>
            </div>

            <div class="col hide-on-small-only m3 l2">
                <div class="toc-wrapper pinned">

                    <ul class="section table-of-contents">
                        <li><a href="#Date_Niveau">Date et Niveau</a></li>
                        <li><a href="#MO">Medecins Observateurs</a></li>
                        <li><a href="#PS">Patients Simulés</a></li>
                    </ul>
                </div>
            </div>

        </div>
        <div id="add"></div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            $('.scrollspy').scrollSpy();
        });
        $('.datepicker').pickadate({
            selectMonths: true, // Creates a dropdown to control month
            selectYears: 15 // Creates a dropdown of 15 years to control year
        });
        $(document).ready(function () {
            $('.tooltipped').tooltip({delay: 50});
        });
        $(document).ready(function () {
            $('select').material_select();
        });
    </script>
    <script type="text/javascript" src="/js/patient_input.js"></script>
    <script type="text/javascript">
        function show() {
            document.getElementById('progress').style.display = 'block';
            //alert("hhh");
        }
    </script>
    <script type="text/javascript">

        <?php  echo "var observers = ".$medecin_observers."\n";?>
        var $_token = $('input[name=_token]').val();
        $(function () {
              function verif(id_Observer,data){
                for(i=0;i<data.length;i++){
                    if(id_Observer==data[i]['id_Enseignant']){
                        return true;
                    }
                }
                return false;
            }
            //A chaque changement du input search il va une requéte ajax 
            $('#search').on('input', function () {
                var rech = $('#search').val();
                $.ajax({
                    url: 'store',
                    type: "post",
                    dataType : 'json' ,
                    data: {'_token': $_token, 'rech': rech},
                    success: function (data) {

                        for(var i=0;i<observers.length;i++){
                            
                            if(verif(observers[i]['id_Enseignant'],data)){
                                $('#'+observers[i]['id_Enseignant']+"css").css('display','table-row');
                            }else {
                                $('#'+observers[i]['id_Enseignant']+"css").css('display','none');
                            }
                        }
                   
                     
                    }
                });
            });

        });
    </script>

@stop
