<?php $__env->startSection('conteudo'); ?>


<div class="pcoded-content">
    <!-- [ breadcrumb ] start -->
    <div class="page-header">
        <div class="page-block">
            <div class="row align-items-center">
                <div class="col-md-12">
                    <div class="page-header-title">
                        <h5 class="m-b-10">Turmas</h5>
                    </div>
                    <ul class="breadcrumb">
                        <li class="breadcrumb-item"><a href="index.html"><i class="feather icon-home"></i></a></li>
                        <li class="breadcrumb-item"><a href="#!">Turmas</a></li>
                        <li class="breadcrumb-item"><a href="#!">Listagem</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="row">

        <div class="col-xl-12">

            <?php if($errors->any()): ?>

                <div class="sufee-alert alert with-close alert-danger alert-dismissible fade show">
                    <span class="badge badge-pill badge-danger">Erro</span>
                    <ul class="errors">
                        <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $erro): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <li> <?php echo e($erro); ?></li>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </ul>
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
        <?php endif; ?>

            <?php if(session()->has('sms')): ?>
                <div class="sufee-alert alert with-close alert-success alert-dismissible fade show">
                    <span class="badge badge-pill badge-success">Successo</span>
                    <?php echo e(session()->get('sms')); ?>

                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
            <?php endif; ?>


            <div class="card">
                <div class="card-header">
                    <h5>Listagem</h5>
               </div>
                <div class="card-body table-border-style">
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>Nome da Turma</th>
                                    <th>Ano Lectivo</th>
                                    <th>Sala</th>
                                    <th>Cuidadora</th>
                                    <th>Auxiliar</th>
                                    <th>Capacidade</th>
                                    <th>Matriculadas</th>
                                    <th>Qtd Masculino</th>
                                    <th>Qtd feminino</th>
                                    <th>Acção</th>

                                </tr>
                            </thead>
                            <tbody>
                                <?php $__currentLoopData = $turma; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tur): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                    <tr>
                                        <td><?php echo e($tur->nome); ?> </td>
                                        <td><?php echo e($tur->ano_lectivo); ?></td>
                                        <td>
                                            <?php if($tur->id_sala !=null): ?>
                                                Sala nº<?php echo e($tur->id_sala); ?>

                                            <?php endif; ?>
                                        </td>
                                        <td><?php echo e($tur->cuidadora); ?></td>
                                        <td><?php echo e($tur->auxiliar); ?></td>
                                        <td><?php echo e($tur->total_criancas); ?></td>
                                        <td><?php echo e($tur->total_matriculadas); ?></td>
                                        <td><?php echo e($tur->total_masculino); ?></td>
                                        <td><?php echo e($tur->total_femenino); ?></td>


                                        <td>



                                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('editar_turma')): ?>
                                                <a href="" data-toggle="modal" data-target="#editar_turma"

                                                onclick="editar_turma(<?php echo e(json_encode($tur->id_sala)); ?>, <?php echo e(json_encode($tur->id)); ?>, <?php echo e(json_encode($tur->nome)); ?>, <?php echo e(json_encode($tur->ano_lectivo)); ?>, <?php echo e(json_encode($tur->total_criancas)); ?>)"
                                                >
                                                    <i class="fa-solid fa-pen-to-square" style="color: blue;"></i>
                                                </a>
                                            <?php endif; ?>


                                            <a href="<?php echo e(route('adicionar.crianca.turma',['id_turma'=>$tur->id])); ?>"
                                            >
                                            <i class="fa-solid fa-child"></i>
                                            </a>

                                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('criar_turma')): ?>
                                                <a href="" data-toggle="modal" data-target="#adicionar_professor"
                                                    onclick="adicionar_professor(<?php echo e(json_encode($tur->id)); ?>)"
                                                >
                                                    <i class="fa-solid fa-chalkboard-teacher" style="color:rgb(15, 15, 15);"></i>
                                                </a>
                                            <?php endif; ?>



                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

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

    </div>

</div>


<div id="editar_turma" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title h4" id="myLargeModalLabel">Editar Dados da Turma</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>

            <div class="modal-body">
                <div  id="sms_erro_ed" class="sufee-alert alert with-close alert-danger alert-dismissible fade show">
                    <span class="badge badge-pill badge-danger">Erro</span>
                   Preencha todos o campo obrigatório.

                </div>
                <div class="modal-body">
                    <form id="formulario_editar" action="<?php echo e(route('editar.turma')); ?>" method="post" enctype="multipart/form-data" >
                       <?php echo csrf_field(); ?>
                       <h5>Ano Lectivo: <label id="ano_lectivo2"></label> </h5>
                       <div class="form-row">

                            <div class="form-group col-md-12">
                                <label for="inputCity">Nome da Turma <span style="color: red">*</span></label>
                                <input type="text" id="nome_ed" name="nome" class="form-control" >
                                <input type="text" id="id" name="id" class="form-control" hidden>

                            </div>
                            <div class="form-group col-md-6">
                                <label for="inputCity">Sala <span style="color: red">*</span></label>
                                <select  onchange="buscar_capacidade()" id="sala" name="sala" class="form-control">
                                    <option value="" id="id_sala_reg" ></option>

                                    <?php $__currentLoopData = $salas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sala): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($sala->id); ?>" data-capacidade="<?php echo e($sala->capacidade); ?>">Sala<?php echo e($sala->id); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


                                </select>

                            </div>
                            <div class="form-group col-md-6">
                                <label for="inputCity">Capacidade  <span style="color: red">*</span></label>
                                <input type="number" min="0"  readonly id="total" name="total" class="form-control" >

                            </div>
                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn  btn-secondary" data-dismiss="modal">Fechar</button>
                            <button onclick="verificarRegisto2()"  class="btn  btn-primary">Confirmar</button>
                        </div>
                    </form>
                </div>

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


<div id="crianca_turma" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title h4" id="myLargeModalLabel">Editar Dados da Turma</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>

            <div class="modal-body">
                <div  id="sms_erro_ed" class="sufee-alert alert with-close alert-danger alert-dismissible fade show">
                    <span class="badge badge-pill badge-danger">Erro</span>
                   Preencha todos o campo obrigatório.

                </div>
                <div class="modal-body">
                    <form id="formulario_editar" action="<?php echo e(route('editar.turma')); ?>" method="post" enctype="multipart/form-data" >
                       <?php echo csrf_field(); ?>
                       <h5>Ano Lectivo: <label id="ano_lectivo2"></label> </h5>
                       <div class="form-row">

                            <div class="form-group col-md-12">
                                <label for="inputCity">Nome da Turma <span style="color: red">*</span></label>
                                <input type="text" id="nome_ed" name="nome" class="form-control" >
                                <input type="text" id="id" name="id" class="form-control" hidden>

                            </div>
                            <div class="form-group col-md-6">
                                <label for="inputCity">Sala <span style="color: red">*</span></label>
                                <select  onchange="buscar_capacidade()" id="sala" name="sala" class="form-control">
                                    <option value="" id="id_sala_reg" ></option>

                                    <?php $__currentLoopData = $salas; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sala): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($sala->id); ?>" data-capacidade="<?php echo e($sala->capacidade); ?>">Sala<?php echo e($sala->id); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


                                </select>

                            </div>
                            <div class="form-group col-md-6">
                                <label for="inputCity">Capacidade  <span style="color: red">*</span></label>
                                <input type="number" min="0"  readonly id="total" name="total" class="form-control" >

                            </div>
                        </div>

                        <div class="modal-footer">
                            <button type="button" class="btn  btn-secondary" data-dismiss="modal">Fechar</button>
                            <button onclick="verificarRegisto2()"  class="btn  btn-primary">Confirmar</button>
                        </div>
                    </form>
                </div>

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


<!-- ver director -->

<div id="adicionar_crianca" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title h4" id="myLargeModalLabel">Adicionar_crianca</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>
            <div class="modal-body">

               <div class="row ">
                    <div class="col-md-6 ">
                        <h6 style="color:black">Dados Pessoais</h6>
                        <hr>

                        <label for="">Nome: <label id="nome" style="color: rgb(65, 170, 109)" ></label></label><br>
                        <label for="">BI: <label id="bi" style="color: rgb(65, 170, 109)" ></label></label><br>
                        <label for="">Genero: <label id="genero" style="color: rgb(65, 170, 109)" ></label></label><br>
                        <label for="">Data de Nascimento: <label id="data_nascimento" style="color: rgb(65, 170, 109)" ></label></label>

                    </div>
                    <div class="col-md-6 ">
                        <h6  style="color:black">Contactos</h6>
                        <hr>
                        <label for="">Telefone: <label id="telefone" style="color: rgb(65, 170, 109)" ></label></label><br>
                        <label for="">Cidade: <label id="cidade" style="color: rgb(65, 170, 109)" ></label></label><br>
                        <label for="">Endereço: <label id="endereco" style="color: rgb(65, 170, 109)" ></label></label>
                    </div>
                    <div class="col-md-12">
                        <br><br>
                        <h6 style="color:black">Informações Profissionais</h6>
                        <hr>
                        <label for="">Função: <label id="funcao" style="color: rgb(65, 170, 109)" ></label></label><br>
                        <label for="">Estado: <label id="estado" style="color: rgb(65, 170, 109)" ></label></label><br>
                        <label for="">Data de Admissão: <label id="data_admissao" style="color: rgb(65, 170, 109)" ></label></label>
                    </div>
               </div>
            </div>
        </div>
    </div>
</div>

<div id="adicionar_professor" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title h4" id="myLargeModalLabel">Gerir Professor e Auxiliar da Turma</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>
            <div  id="sms_erro" class="sufee-alert alert with-close alert-danger alert-dismissible fade show">
                <span class="badge badge-pill badge-danger">Erro</span>
               Preencha todos o campo obrigatório.

            </div>
            <div class="modal-body">
                <form id="formulario_cuidadora" action="<?php echo e(route('adicionar.professor')); ?>" method="post" enctype="multipart/form-data" >
                   <?php echo csrf_field(); ?>
                   <div class="form-row">

                        <div class="form-group col-md-6">
                            <label for="inputCity">Professor (a) <span style="color: red">*</span></label>
                            <select id="cuidadora" name="cuidadora" class="form-control">
                                <option value="" >seleccione o professor (a)</option>
                                <?php $__currentLoopData = $funcionario; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $func): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($func->id_func); ?>"><?php echo e($func->nome_completo); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                            </select>


                        </div>
                        <input type="text" id="id_turma" name="id_turma" class="form-control" hidden>
                        <div class="form-group col-md-6">
                            <label for="inputCity">Auxiliar</label>
                            <select id="auxiliar" name="auxiliar" class="form-control">
                                <option value="" >seleccione o professor (a)</option>
                                <?php $__currentLoopData = $funcionario; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $func): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($func->id_func); ?>"><?php echo e($func->nome_completo); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                            </select>

                        </div>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn  btn-secondary" data-dismiss="modal">Fechar</button>
                        <button onclick="verificarRegisto()"  class="btn  btn-primary">Adicionar</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<script>
    document.getElementById('sms_erro').style.display = 'none';
    document.getElementById('sms_erro_ed').style.display = 'none';
    function editar_turma(id_sala, id, nome, ano, capacidade){

        var data_i = ano.split('-')[0];
        var data_f = ano.split('-')[1];

        document.getElementById("id").value = id;
        document.getElementById("nome_ed").value = nome;

        document.getElementById("id_sala_reg").value = id_sala;
        document.getElementById("id_sala_reg").innerHTML  = "Sala nº"+id_sala;
        document.getElementById('total').value=capacidade;
        document.getElementById("ano_lectivo2").innerHTML  = ano;

        document.getElementById("ano").value = data_i;
        document.getElementById("total").value = capacidade;
    }

    function verificarRegisto2(){
        event.preventDefault();

       var nome = document.getElementById("nome_ed").value;
       var sala = document.getElementById("sala").value;

        if(nome ==="" || sala ==="" ){
            document.getElementById('sms_erro_ed').style.display = 'block';
        }else{
            document.getElementById('sms_erro_ed').style.display = 'none';

            document.getElementById('formulario_editar').submit();
        }
    }

    function verificarRegisto(){
        event.preventDefault();
       var nome = document.getElementById('cuidadora').value;

        if(nome ==="" ){
            document.getElementById('sms_erro').style.display = 'block';
        }else{
            document.getElementById('sms_erro').style.display = 'none';
            document.getElementById('formulario_cuidadora').submit();
        }
    }


    function adicionar_professor(id) {
        document.getElementById('sms_erro').style.display = 'none';
        document.getElementById('id_turma').value = id;
    }


    function buscar_capacidade()
{
    let select = document.getElementById("sala");
    let selectedOption = select.options[select.selectedIndex];

    let capacidade = selectedOption.getAttribute("data-capacidade");
    document.getElementById('total').value=capacidade;

}

</script>


<?php $__env->stopSection(); ?>

<?php echo $__env->make('Dashboard.layout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\Users\Ferdinando Roque\Documents\GitHub\creche\resources\views/Dashboard/pagina/listagem_turmas.blade.php ENDPATH**/ ?>