<div class="">
    <div class="page-title">
        <div class="title_left">
            <h3>Retícula</h3>
        </div>
    </div>

    <div class="clearfix"></div>

    <div class="row">
        <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
                <div class="x_title">
                    <h2>Registrar una nueva retícula</h2>
                    <div class="clearfix"></div>
                </div>
                <div class="x_content">
                    @if (isset($bandera))
                        @if ($bandera === 1)
                            <form id="form-nueva" data-parsley-validate class="form-horizontal form-label-left"
                                enctype="multipart/form-data">
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="nombre">Nombre
                                            <span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <input type="hidden" name="cveRet" id="cveRet" value="{{ $ret->cve_rec }}">
                                        <input type="text" id="nombre" name="nombre" required="required"
                                            class="form-control form-control-sm" value="{{ $ret->nombre_rec }}"
                                            disabled>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="clave">Clave
                                            <span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <input type="text" id="clave" name="clave" required="required"
                                            class="form-control form-control-sm" value="{{ $ret->claveRet_rec }}"
                                            disabled>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="planest">Plan de
                                            estudios
                                            <span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <select id="planest" name="planest" required="required"
                                            class="form-control form-control-sm" disabled>
                                            @foreach ($plan as $p)
                                                @if ($ret->cve_planest == $p->cve_planest)
                                                    <option value="{{ $p->cve_planest }}">{{ $p->claveOfi_planest }}
                                                    </option>
                                                @endif
                                            @endforeach
                                        </select>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="no_sem">Número de
                                            semestres<span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <input type="text" id="no_sem" name="no_sem" required="required"
                                            class="form-control form-control-sm" value="{{ $numsem }}" disabled>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="no_matmax">Número
                                            de materias por semestre<span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <input type="text" id="no_matmax" name="no_matmax" required="required"
                                            class="form-control form-control-sm" value="{{ $maxmat }}" disabled>
                                    </div>
                                </div>
                            </form>
                            <form id="form-nueva-r" data-parsley-validate class="form-horizontal form-label-left"
                                enctype="multipart/form-data">
                                <div id="contenedor_reticula">
                                    <table id="myTable" class="table table-bordered">
                                        <tbody id="contenedor_columna">
                                            <tr>
                                                @for ($i = 0; $i < $numsem; $i++)
                                                    <td class="text-center">Semestre {{ $i + 1 }}</td>
                                                @endfor
                                            </tr>
                                            @for ($i = 0; $i < $maxmat; $i++)
                                                <tr id="col_{{ $i + 1 }}">
                                                    @for ($j = 0; $j < $numsem; $j++)
                                                        <?php $ttp = '';
                                                        $bandera = true; ?>
                                                        <td id="{{ $i }} - {{ $j }}"
                                                            style="width:30%;" class="td">
                                                            @foreach ($sem as $s)
                                                                @foreach ($s->DetalleMateriasem as $dm)
                                                                    @if ($i == $dm->x_detmat && $j == $dm->y_detmat)
                                                                    <div class="card">
                                                                        <div class="card bg-light">
                                                                            <div class="card-header text-center">
                                                                                {{ $dm->materia->nombre_mat }}
                                                                            </div>
                                                                            <div class="text-center">
                                                                                @foreach ($dm->materia->temario as $t)
                                                                                    <?php $ttp = $t->horasTeoricas_tem . ' - ' . $t->horasPracticas_tem . ' - ' . $t->totalHoras_tem; ?>
                                                                                @endforeach
                                                                                <p class="card-text">
                                                                                    {{ $ttp }}</p>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                    @else
                                                                        @if ($i == 1 && $j == 1)
                                                                            <button type="button"
                                                                                class="btn btn-info btn-block btn-sm"
                                                                                title="Materia"
                                                                                onclick="addMateriaSem({{ $i }},{{ $j }},{{ $ret->cve_rec }},{{ $maxmat }})"><i
                                                                                    class="fa fa-plus"></i></button>
                                                                        @endif
                                                                    @endif
                                                                @endforeach
                                                            @endforeach
                                                        </td>
                                                    @endfor
                                                </tr>
                                            @endfor
                                        </tbody>

                                    </table>
                                    <script>
                                        var ret=$("#cveRet").val();
                                        generar_botonesMAS(this.form,ret);
                                    </script>
                                </div>
                                <div id="contenedor_add_cf">
                                    <div class='mb-1 row'>
                                        <div class="col-md-3 col-sm-12"></div>
                                        <div class="col-md-6 col-sm-12">
                                            <div class="row">
                                                <div class="col">
                                                    <button class="btn btn-secondary btn-block" type="button"
                                                        onclick="generar_mas_filas()">Agregar fila</button>
                                                </div>
                                                <div class="col">
                                                    <button class="btn btn-secondary btn-block" type="button"
                                                        onclick="generar_mas_columnas()">Agregar columna</button>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-3 col-sm-12"></div>
                                    </div>
                                </div>
                            </form>
                        @endif
                    @else
                        @if ($data == [])
                            <form id="form-nueva" data-parsley-validate class="form-horizontal form-label-left"
                                enctype="multipart/form-data">
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="nombre">Nombre
                                            <span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">

                                        <input type="hidden" name="cveRet" id="cveRet">
                                        <input type="text" id="nombre" name="nombre" required="required"
                                            class="form-control form-control-sm">
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <div class="alert alert-danger" role="alert" id="a_nombre"
                                            style="display: none">
                                        </div>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="clave">Clave
                                            <span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <input type="text" id="clave" name="clave" required="required"
                                            class="form-control form-control-sm">
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <div class="alert alert-danger" role="alert" id="a_clave"
                                            style="display: none">
                                        </div>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="planest">Plan de
                                            estudios
                                            <span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <select id="planest" name="planest" required="required"
                                            class="form-control form-control-sm">
                                            <option value="">--Seleccione--</option>
                                            @foreach ($planest as $p)
                                                <option value="{{ $p->cve_planest }}">
                                                    {{ $p->claveOfi_planest }}
                                                </option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <div class="alert alert-danger" role="alert" id="a_planest"
                                            style="display: none">
                                        </div>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="no_sem">Número de
                                            semestres<span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <input type="text" id="no_sem" name="no_sem" required="required"
                                            class="form-control form-control-sm">
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <div class="alert alert-danger" role="alert" id="a_nosem"
                                            style="display: none">
                                        </div>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="no_matmax">Número
                                            de materias por semestre<span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <input type="text" id="no_matmax" name="no_matmax" required="required"
                                            class="form-control form-control-sm">
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <div class="alert alert-danger" role="alert" id="a_matmax"
                                            style="display: none">
                                        </div>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-md-3 col-sm-12"></div>
                                    <div class="col-md-6 col-sm-12">
                                        <div class="row">
                                            <div class="col">
                                                <!--generar_reticula() -->
                                                <button id="botongen" type="button"
                                                    onclick="add_reticula(this.form)"
                                                    class="btn btn-success btn-block" form="form-nueva">Generar
                                                    Reticula</button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-3 col-sm-12"></div>
                                </div>
                            </form>
                            <form id="form-nueva-r" data-parsley-validate class="form-horizontal form-label-left"
                                enctype="multipart/form-data">
                                <div id="contenedor_reticula">
                                </div>
                                <div id="contenedor_add_cf">

                                </div>
                            </form>
                        @else
                            @include('semestre.nuevo', ['planest' => $planest])
                            <form id="form-nueva-r" data-parsley-validate class="form-horizontal form-label-left"
                                enctype="multipart/form-data">
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="nombre">Nombre
                                            <span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <input type="hidden" name="cveRet" id="cveRet">
                                        <input type="text" id="nombre" name="nombre" required="required"
                                            class="form-control form-control-sm" value="{{ $data['nombre'] }}"
                                            disabled>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="clave">Clave
                                            <span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <input type="text" id="clave" name="clave" required="required"
                                            class="form-control form-control-sm" value={{ $data['clave'] }} disabled>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="planest">Plan de
                                            estudios
                                            <span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <select id="planest" name="planest" required="required"
                                            class="form-control form-control-sm" disabled>
                                        </select>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="no_sem">Número de
                                            semestres<span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <input type="text" id="no_sem" name="no_sem" required="required"
                                            class="form-control form-control-sm" value="{{ $data['no_sem'] }}"
                                            disabled>
                                    </div>
                                </div>
                                <div class="mb-1 row">
                                    <div class="col-form-label col-md-4 col-sm-4 col-xs-12 text-left text-md-right">
                                        <label class="text-sm-left" for="no_matmax">Número
                                            de materias por semestre<span class="required">*</span>
                                        </label>
                                    </div>
                                    <div class="col-md-4 col-sm-4 col-xs-12">
                                        <input type="text" id="no_matmax" name="no_matmax" required="required"
                                            class="form-control form-control-sm" value="{{ $data['no_mat'] }}"
                                            disabled>
                                    </div>
                                </div>
                            </form>
                            <form id="form-nueva-r" data-parsley-validate class="form-horizontal form-label-left"
                                enctype="multipart/form-data">
                                <div id="contenedor_reticula">
                                </div>
                                <div id="contenedor_add_cf">

                                </div>
                            </form>

                        @endif
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<script>
    $(document).ready(function() {
        $('[data-toggle="tooltip"]').tooltip();
    });
</script>
<script>
    $(document).ready(function() {
        $('[data-toggle="tooltip"]').click(function() {
            $('[data-toggle="tooltip"]').tooltip("hide");

        });
    });
</script>
