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

<div class="pcoded-content">

    <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="#!">Nova</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="row">

        <div class="col-sm-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; ?>
            <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 os campos obrigatórios.

            </div>


            <div class="card">
                <div class="card-body">
                    <h5>Nova</h5>

                    <hr>
                    <form id="formulario" action="<?php echo e(route('registar.turma.post')); ?>" method="post" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>

                        <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" name="nome" class="form-control" >

                            </div>

                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-4">
                                <label for="inputZip">Ano Lectivo <span style="color: red">*</span></label>
                                <input  readonly value="<?php echo e($inicio_fim); ?>" id="ano_letivo" name="ano_letivo" class="form-control" >
                            </div>
                            <div class="form-group col-md-4">
                                <label for="inputCity">Sala <span style="color: red">*</span></label>
                                <!--tis.value-->
                                <select  onchange="buscar_capacidade()" id="sala" name="sala" class="form-control">
                                    <option value="" >seleccione a sala</option>
                                    <?php $__currentLoopData = $sala; $__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-4">
                                <label for="inputCity">Capacidade <span style="color: red">*</span></label>
                                <input type="number" min="0" id="total" name="total" class="form-control" readonly >

                            </div>
                        </div>



                        <button onclick="verificarRegisto()" class="btn  btn-primary float-right">Registar</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>


<script>

document.getElementById('sms_erro').style.display = 'none';

function verificarRegisto(){
    event.preventDefault();
    var nome = document.getElementById('nome').value;
    var data = document.getElementById('ano_letivo').value;
    var capacidade = document.getElementById('total').value;
    var sala = document.getElementById('sala').value;

    if(capacidade == 0 || nome ==="" || data==="" || sala ==="" ){
        document.getElementById('sms_erro').style.display = 'block';
    }else{
        document.getElementById('sms_erro').style.display = 'none';
        document.getElementById('formulario').submit();
    }
}


function buscar_data(){


    var data = document.getElementById('ano_letivo').value;
    const ano =  parseInt(data.split('-')[0], 10);
    var ano_letivo = ano+1;
    document.getElementById('ano_letivo2').value = ano_letivo;

}


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/nova_turma.blade.php ENDPATH**/ ?>