<?= $this->extend('estructura/header_dashboard'); ?>
<?= $this->section('content'); ?>
<!-- ============================================================== -->
<!-- Start right Content here -->
<!-- ============================================================== -->
<style>
    .select2-container--locked{
        pointer-events: none;  /* Bloquea la interacción con el select */
        background-color: #d3d3d3; /* Gris claro */
    }
</style>
<div class="main-content">
	<div class="page-content">
		<div class="container-fluid">
			<!-- start page title -->
			<div class="row">
				<div class="col-12">
					<div class="page-title-box d-sm-flex align-items-center justify-content-between">
						<h4 class="mb-sm-0"><?= $elementoSeleccionadoModulo ?></h4>
						<div class="page-title-right">
							<ol class="breadcrumb m-0">
								<li class="breadcrumb-item"><a href="javascript: void(0);">Inicio</a></li>
								<li class="breadcrumb-item active"><?= $breadcrumb ?></li>
							</ol>
						</div>
					</div>
				</div>
			</div>
			<!-- end page title -->
			<div class="row">
			    <div class="col-xxl-12">
                    <div class="card">
                        <div class="card-body p-4">
                            <div class="d-flex justify-content-center">
                                <div class="flex-shrink-0 avatar-md mx-4">
                                    <div class="avatar-title bg-light rounded">
                                        <img src="<?= $baseUrl ?>/<?= $basePublic ?>/images/favicon.ico" alt="" height="50">
                                    </div>
                                </div>
                                <div class="d-flex text-center align-items-center">
                                    <div>
                                        <p class="text-muted m-0">Marca</p>
                                        <h5 class="mb-0"><?= !empty($marca) ? $marca["Marca"] : "TOTAL DE DISPOSITIVOS" ?></h5>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--end card-body-->
                    </div>
                    <!--end card-->
                </div>
				<div class="col-lg-12">
					<div class="card">
						<div class="card-header d-flex align-items-center">
                            <h5 class="card-title mb-0 flex-grow-1"><?= $subtitulo ?></h5>
                            <div class="d-flex">
								<?php
								if (in_array("ADDDIS", $permisos)) 
								{
								?>
                                <button class="btn bg-sistema d-flex justify-content-center align-items-center mx-1 color-white datos-dispositivo" data-bs-target="#informacionDispositivo" data-form="#formInformacionDispositivo" data-id="0" data-marca="<?= $idMarca ?>" data-accion="crear" id="crear-dispositivo">
									<i class="mdi mdi-plus-circle me-1" style="font-size: 14px;"></i>Nuevo
								</button>
								<?php
								}
								?>
								<button type="button" class="btn bg-filtros color-white px-2 py-1 mx-1 waves-effect waves-light layout-rightside-btn" data-bs-toggle="offcanvas" data-bs-target="#theme-settings-offcanvas" aria-controls="theme-settings-offcanvas">
                                    <i class="mdi mdi-filter" style="font-size: 18px;"></i>
                                </button>
								<a href="<?= $baseUrl.'/'.$previo ?>" class="btn bg-red-verisure color-white px-2 py-1 mx-1 waves-effect waves-light layout-rightside-btn">
								    <i class="mdi mdi-arrow-left" style="font-size: 18px;"></i>
								</a>
                            </div>
                        </div>
						<div class="card-body">
							<table id="tblModeloDispositivo" class="table table-bordered dt-responsive nowrap table-striped align-middle" style="width:100%">
								
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
		<span class="respuesta_global"></span>
		<!-- container-fluid -->
	</div>
	<!-- End Page-content -->
	<footer class="footer">
		<div class="container-fluid">
			<div class="row">
				<div class="col-sm-6">
					<script>document.write(new Date().getFullYear())</script> © Verisure Peru.
				</div>
				<div class="col-sm-6">
					<div class="text-sm-end d-none d-sm-block">
						Desarrollado por <a href="https://www.verisure.pe/">Verisure Peru</a>
					</div>
				</div>
			</div>
		</div>
	</footer>
</div>
<!-- end main content-->

<?= $this->section('js'); ?>
<script>
	$(function () {
		/***SERVERSIDE LISTADO DE MODELOS DE DISPOSITIVOS***/
		assetListVM = {
			dt: null,
			init: function () {
				dt = $('#tblModeloDispositivo').DataTable({
					"serverSide": true,
					"processing": true,
					"ajax": {
						"url": baseUrl + "/dispositivos-serverside",
						type: 'POST',
						data: function(d) {
						    let rutavista = window.location.href;
						    let arrayrutavista = rutavista.split("/");
						    //arrayrutavista.length-2 para devolver la ruta del controller
						    d.url_vista = arrayrutavista[arrayrutavista.length-2];
						    //arrayrutavista.length-2 para devolver el parámetro de la url
						    d.idMarca = arrayrutavista[arrayrutavista.length-1];
						}
					},
					"columns": [
						{"title": "Código", "data": "IDDispositivo", "class": "text-center", "searchable": true },
						{"title": "Marca", "data": "Marca", "class": "text-center", "searchable": true },
						{"title": "Modelo", "data": "Modelo", "class": "text-center", "searchable": true },
						{"title": "¿Descontinuado?", "data": "ModeloDescontinuado", "class": "text-center", "searchable": false },
						{"title": "Categoría", "data": "nombre_categoria", "class": "text-center", "searchable": true },
						{"title": "Tipo", "data": "nombre_tipo", "class": "text-center", "searchable": true, "orderable": false },
						{"title": "Subtipo", "data": "nombre_subtipo", "class": "text-center", "searchable": false, "orderable": false },
						{"title": "Estado", "data": "EstadoDispositivo", "class": "text-center", "searchable": true },
						{"title": "Acciones", "data": "acciones", "class": "text-center", "searchable": false, "orderable": false },
					],
					"lengthMenu": [[10, 25, 50], [10, 25, 50]],
					responsive: true,
					autoWidth: false,
					"pageLength": 10,
					"paging": true,
					"aaSorting": [[0, 'desc']],
				});
			}
		}

		assetListVM.init();
		/****FIN SERVERSIDE LISTADO DE MODELOS DE DISPOSITIVOS****/
		
	});
</script>
<?php $this->endSection(); ?>


<!-- Filtros -->
<div class="offcanvas offcanvas-end border-0" tabindex="-1" id="theme-settings-offcanvas" aria-modal="true" role="dialog">
    <div class="d-flex align-items-center bg-filtros bg-gradient p-3 offcanvas-header">
        <h5 class="m-0 me-2 text-white">Filtros</h5>

        <button type="button" class="btn-close btn-close-white ms-auto" id="customizerclose-btn" data-bs-dismiss="offcanvas" aria-label="Close"></button>
    </div>
    <div class="offcanvas-body p-0">
        <!--<div data-simplebar="init" class="h-100 simplebar-scrollable-y">-->
        <!--    <div class="simplebar-wrapper" style="margin: 0px;">-->
        <!--        <div class="simplebar-height-auto-observer-wrapper">-->
        <!--            <div class="simplebar-height-auto-observer">-->
                        
        <!--            </div>-->
        <!--        </div>-->
        <!--        <div class="simplebar-mask">-->
        <!--            <div class="simplebar-offset" style="right: 0px; bottom: 0px;">-->
        <!--                <div class="simplebar-content-wrapper" tabindex="0" role="region" aria-label="scrollable content" style="height: 100%; overflow: hidden scroll;">-->
        <!--                    <div class="simplebar-content" style="padding: 0px;">-->
            <div id="ctnFiltro" class="p-3">
				<div class="card border" style="border-top: 3px #536878 solid!important;">
					<div class="card-header">
                        <div class="d-flex align-items-center">
                            <div class="flex-grow-1">
                                <h6 class="card-title mb-0">Columnas</h6>
                            </div>
                            <div class="flex-shrink-0">
                                <ul class="list-inline card-toolbar-menu d-flex align-items-center mb-0">
                                    <li class="list-inline-item">
                                        <a class="align-middle minimize-card" data-bs-toggle="collapse" href="#collapseColumnasFiltros" role="button" aria-expanded="true" aria-controls="collapseColumnasFiltros">
                                            <i class="mdi mdi-plus align-middle plus"></i>
                                            <i class="mdi mdi-minus align-middle minus"></i>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
					<div class="card-body collapse show" id="collapseColumnasFiltros" style="">
						cxcvcxxvxcxcv
					</div>
				</div>
				<div class="panel">
                    <div class="panel-heading">
                        <h4>Columnas</h4>
                    </div>
                    <div class="panel-content">
                        <div class="row">
                            adasasads
                        </div>
                    </div>
                </div>
            </div>
        <!--                    </div>-->
        <!--                </div>-->
        <!--            </div>-->
        <!--        </div>-->
        <!--        <div class="simplebar-placeholder" style="width: 400px; height: 1978px;">-->
                    
        <!--        </div>-->
        <!--    </div>-->
        <!--    <div class="simplebar-track simplebar-horizontal" style="visibility: hidden;">-->
        <!--        <div class="simplebar-scrollbar" style="width: 0px; display: none;">-->
                    
        <!--        </div>-->
        <!--    </div>-->
        <!--    <div class="simplebar-track simplebar-vertical" style="visibility: visible;">-->
        <!--        <div class="simplebar-scrollbar" style="height: 314px; transform: translate3d(0px, 0px, 0px); display: block;">-->
                    
        <!--        </div>-->
        <!--    </div>-->
        <!--</div>-->
    </div>
    <div class="offcanvas-footer border-top p-3 text-center">
        <div class="row">
            <div class="col-4">
                <button type="button" class="btn btn-light w-100" id="btnLimpiar">Limpiar</button>
            </div>
            <div class="col-4">
                <button type="button" class="btn btn-danger w-100" id="btnCerrarFiltros" data-bs-dismiss="offcanvas" aria-label="Close">Cerrar</button>
            </div>
            <div class="col-4">
                <button type="button" class="btn btn-primary w-100" id="btnBuscarFiltros">Buscar</button>
            </div>
        </div>
    </div>
</div>

<!-- Modal Información Dispositivo -->
<div class="modal fade zoomIn" id="informacionDispositivo" data-bs-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="exampleinformacionDispositivo" aria-hidden="true">
	<div class="modal-dialog modal-dialog-centered" role="document">
		<div class="modal-content" style="border: none;">
			<div class="modal-header bg-sistema p-3">
				<h5 class="modal-title color-white" id="exampleinformacionDispositivo">Información de Dispositivo</h5>
				<button type="button" class="btn-close bg-white" data-bs-dismiss="modal" aria-label="Close"></button>
			</div>
			<form id="formInformacionDispositivo" class="formulario" autocomplete="off" action="" method="POST">
				<span class="respuesta"></span>
				<div class="modal-body">
					<input type="hidden" id="txtIDDispositivo_i" name="txtIDDispositivo_i">
					<div class="row">
						<div class="col-xxl-12 col-md-12 col-12 mb-3">
							<div>
								<label for="txtIDMarca_i" class="form-label">Marca</label>
								<select class="form-select select2-dinamico" aria-label="Marca" id="txtIDMarca_i" name="txtIDMarca_i" data-modal="informacionDispositivo">
									<option selected="" value="">Seleccione una opción</option>
									
								</select>
							</div>
						</div>
						<div class="col-xxl-12 col-md-12 col-12 mb-3">
							<label for="txtModelo_i" class="form-label">Modelo</label>
							<div class="input-group">
								<input type="text" class="form-control" aria-label="Marca" id="txtModelo_i" name="txtModelo_i">
							</div>
						</div>
						<div class="col-xxl-12 col-md-12 col-12 mb-3">
							<div>
								<label for="txtCategoriaDispositivo_i" class="form-label">Categoría</label>
								<select class="form-select select2-dinamico" aria-label="Categoría" id="txtCategoriaDispositivo_i" name="txtCategoriaDispositivo_i" data-modal="informacionDispositivo">
									<option selected="" value="">Seleccione una opción</option>
									
								</select>
							</div>
						</div>
						<div class="col-xxl-12 col-md-12 col-12 mb-3">
							<div>
								<label for="txtTipo_i" class="form-label">Tipo</label>
								<select class="form-select select2-dinamico" aria-label="Tipo" id="txtTipo_i" name="txtTipo_i" data-modal="informacionDispositivo">
									<option selected="" value="">Seleccione una opción</option>
									
								</select>
							</div>
						</div>
						<div class="col-xxl-12 col-md-12 col-12 mb-3">
							<div>
								<label for="txtSubtipo_i" class="form-label">Subtipo</label>
								<select class="form-select select2-dinamico" aria-label="Subtipo" id="txtSubtipo_i" name="txtSubtipo_i" data-modal="informacionDispositivo">
									<option selected="" value="">Seleccione una opción</option>
									
								</select>
							</div>
						</div>
						<div class="col-12 col-md-12 justify-content-end my-2">
							<div class="col-xxl-12 col-md-12 col-12 border-sistema-2px p-2 d-flex justify-content-between align-items-center" style="border-radius: 15px;">
    						    <h5 class="color-sistema m-0" for="chkModeloDescontinuado_i">¿Modelo descontinuado?</h5>
    						    <div class="form-check form-switch form-switch-lg d-flex justify-content-start align-items-center" for="chkModeloDescontinuado_i">
    								<input class="form-check-input form-check-input-sistema" type="checkbox" role="switch" name="chkModeloDescontinuado_i" id="chkModeloDescontinuado_i">
    								<label class="form-check-label m-0" for="chkModeloDescontinuado_i"></label>
    							</div>
    						</div>
    					</div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn bg-danger color-white" data-bs-dismiss="modal"><i class="mdi mdi-close-thick mx-1" style="font-size: 14px;"></i>Cerrar</button>
					<button type="submit" id="btnEjecutarDispositivo" class="btn bg-success color-white"><i class="mdi mdi-content-save mx-1" style="font-size: 14px;"></i>Actualizar</button>
				</div>
			</form>
		</div>
	</div>
</div>
<?php $this->endSection(); ?>