<?php
/**
 * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 * @link          https://cakephp.org CakePHP(tm) Project
 * @since         0.10.0
 * @license       https://opensource.org/licenses/mit-license.php MIT License
 * @var \App\View\AppView $this
 */

?>
<!DOCTYPE html>
<html>
<head>
    <?= $this->Html->charset() ?>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>
        <?= $this->fetch('title') ?>
    </title>
    <?= $this->Html->meta('icon') ?>

    <link href="https://fonts.googleapis.com/css?family=Raleway:400,700" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>

    <?= $this->Html->css(['normalize.min', 'milligram.min', 'cake']) ?>

    <?= $this->fetch('meta') ?>
    <?= $this->fetch('css') ?>
    <?= $this->fetch('script') ?>
</head>
<body>
     <nav class="top-nav">
        <div class="top-nav-title">
            <?= $this->Html->image('logo.png', ['width' => 200, 'style' => 'padding:10px;']); ?>
        </div>
        <div class="top-nav-links">
            <?php if($isLogged): ?>
                <?= $this->Html->link('Autorizaciones', ['controller' => 'ipAuths', 'action' => 'index']); ?>
                <?= $this->Html->link('Chats', ['controller' => 'chatbots', 'action' => 'index']); ?>
                <?= $this->Html->link('Notificaciones', ['controller' => 'notifications', 'action' => 'index']); ?>
                <?= $this->Html->link('Reporte', ['controller' => 'slowQueries', 'action' => 'index']); ?>
                <?= $this->Html->link('Usuarios', ['controller' => 'users', 'action' => 'index']); ?>
                <?= $this->Html->link('Cerrar sesión', ['controller' => 'users', 'action' => 'logout']); ?>
            <?php endif; ?>
        </div>
    </nav>
    <main class="main">
        <div class="container">
            <?= $this->Flash->render() ?>
            <?= $this->fetch('content') ?>
        </div>
    </main>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js"></script>
</body>
<script type="text/javascript">
    function getRequest(url, data = null, cntType = 'json'){
        var response = false;
        $.ajax({
            type: 'post',
            url: url,
            data: data,
            async: false,
            dataType: 'json',
            contentType: cntType,
            headers : {
                    'X-CSRF-Token': "<?= $this->request->getCookie('csrfToken')?>"
                },
            success:function(resp){
                response = resp;
            },
            error:function(error){
                alert('Error al procesar la solicitud');
                console.log(error);
                response = false;
            }
        });

        return response;
    }
</script>
</html>
