<script src="../public/js/comunicados.js?rev=<?php echo time(); ?>"></script>
<?php session_start();?>
<div class="content__boxed">
    <div class="content__wrap">
        <nav aria-label="breadcrumb" class="pb-2">
            <ol class="breadcrumb mb-0">
                <li class="breadcrumb-item">Sistema de Tramite Documentario</li>
                <li class="breadcrumb-item">Comunicados</li>
            </ol>
        </nav>
        <!-- Table with toolbar -->
        <div class="card">
            <div class="card-header ">
                <h5 class="card-title mb-3">PANEL ADMINISTRATIVO COMUNICADOS</h5>
                <div class="row ">

                    <!-- Left toolbar -->
                    <div class="col-md-7 gap-1 mb-2">
                        <button type="button" onclick="AbrirRegistro()" class="btn btn-primary hstack gap-1 mb-2 ">
                            <i class="demo-psi-add fs-5"></i>
                            <span class="vr"></span>
                            Crear Comunicado Interno
                        </button>
                        <?php if($_SESSION['S_ROL']=='Administrador') {?>
                        <button type="button" onclick="AbrirRegistro2()" class="btn btn-danger hstack gap-1  ">
                            <i class="demo-psi-add fs-5"></i>
                            <span class="vr"></span>
                            Crear Comunicado Externo
                        </button>
                        <?php } ?>

                    </div>
                    <!-- END : Left toolbar -->
                    <!-- Left toolbar -->
                    <?php if($_SESSION['S_ROL']=='Administrador') {?>

                    <div class="col-md-5 d-flex gap-1 align-items-center mb-3">
                        <div class="alert alert-danger" role="alert">
                            <span><b>IMPORTANTE!</b> Recomendable crear solo un comunicado Externo y elimine los
                                comunicados externos existentes
                            </span>
                        </div>
                    </div>
                    <?php } ?>
                    <!-- END : Left toolbar -->

                    <!-- Right Toolbar -->

                </div>
            </div>
            <div class="card-body ">
                <div class="table-responsive">
                    <table id="tabla_comunicado" class="display " style="width:100%">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Comunicado</th>
                                <th>Fecha Registro</th>
                                <th>Origen</th>
                                <th>Destino</th>
                                <th>Estatus</th>
                                <th style="min-width:90px">Accion</th>
                            </tr>
                        </thead>

                    </table>
                </div>

            </div>
        </div>
        <!-- END : Table with toolbar -->

    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="modal_registro" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">CREAR NUEVO COMUNICADO INTERNO</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-12 mb-3">
                        <label for="">Contenido</label>
                        <textarea id="txt_comunicado" rows="4" class="form-control" style="resize:none;"></textarea>

                    </div>
                    <div class="col-lg-6 mb-3">
                        <label for="">Area de Destino (*)</label>
                        <select class="js-example-basic-single" id="select_area_des" style="width:100%">
                        </select>
                    </div>

                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cerrar</button>
                <button type="button" class="btn btn-secondary"
                    onclick="Registrar_Comunicado()">Registrar</button>
            </div>
        </div>
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="modal_registro2" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">CREAR NUEVO COMUNICADO EXTERNO</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-12 mb-3">
                        <label for="">Contenido</label>
                        <textarea id="txt_comunicado_exterior" rows="4" class="form-control"
                            style="resize:none;"></textarea>

                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-outline-danger" data-bs-dismiss="modal">Cerrar</button>
                <button type="button" class="btn btn-outline-secondary"
                    onclick="Registrar_Comunicado_Exterior()">Registrar</button>
            </div>
        </div>
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="modal_editar" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">EDITAR COMUNICADO</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-12 mb-3">
                        <label for="">Contenido</label>
                        <textarea id="txt_comunicado_e" rows="4" class="form-control" style="resize:none;"></textarea>
                        <input type="text" id="txt_idcomunicado" hidden>
                    </div>
                    <div class="col-lg-6 mb-3" id="not_null_area">
                        <label for="">Area de Destino (*)</label>
                        <select class="js-example-basic-single" id="select_area_d_editar" style="width:100%">
                        </select>
                    </div>
                    <div class="col-lg-6">
                        <label for="">Estado</label>
                        <select name="" class="js-example-basic-single" id="select_estatus" class="form-select">
                            <option value="ACTIVO">ACTIVO</option>
                            <option value="INACTIVO">INACTIVO</option>
                        </select>
                    </div>

                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Cerrar</button>
                <button type="button" class="btn btn-secondary"
                    onclick="Modificar_Comunicado()">Modificar</button>
            </div>
        </div>
    </div>
</div>



<script>
$(document).ready(function() {
    Cargar_Select_Area();
    verificar_tipo_usuario();

});

var myModal = document.getElementById('modal_registro');
$('#modal_registro').on('shown.bs.modal', function(event) {

    $('.js-example-basic-single').select2({
        dropdownParent: '#modal_registro',
        theme: "bootstrap-5",
        width: $(this).data('width') ? $(this).data('width') : $(this).hasClass('w-100') ? '100%' :
            'style',
        placeholder: $(this).data('placeholder'),
        placeholder: 'SELECCIONAR ',
        allowClear: true
    });

})
$('#modal_editar').on('shown.bs.modal', function(event) {

    $('.js-example-basic-single').select2({
        dropdownParent: '#modal_editar',
        theme: "bootstrap-5",
        width: $(this).data('width') ? $(this).data('width') : $(this).hasClass('w-100') ? '100%' :
            'style',
        placeholder: $(this).data('placeholder'),
        placeholder: 'SELECCIONAR ',

    });
})
</script>