<?php
require_once 'class/c_login.php';
$user = Login::get_user();
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Editar Horarios |
        <?= $user->facultad['facultad'] ?? "Administrador"; ?>
    </title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"
        integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
    <?php
    include 'import/html_css_files.php';
    ?>
</head>

<body>
    <?php
    include "import/html_header.php";
    html_header(
        "Menú Inicio",
        "Sistema de gestión de checador ",
    );
    ?>
    <main class="content marco">
        <section id="message"></section>
        <h3 class="text-center mt-3">
            <b>
                <?= $user->user['nombre']; ?>
            </b>
            <i>
                <?= $user->facultad['facultad']; ?>
            </i>
            <small>
                <?= $user->rol['rol'] ?? 'General' ?>
            </small>
        </h3>
        <hr>
        <div class="d-flex justify-content-center align-items-center flex-wrap">
            <?
            foreach ($grupos as $grupo) {
                $paginas = $user->admin
                    ? $db->query("SELECT * FROM PAGINA WHERE grupo_id = :grupo_id ORDER BY pagina_titulo ASC", array(":grupo_id" => $grupo['grupo_id']))
                    : $db->query(
                        "SELECT * FROM PAGINA WHERE pagina_id IN (SELECT pagina_id FROM PERMISO_VIEW WHERE grupo_id = :grupo_id and id = :id) ORDER BY pagina_titulo",
                        array(":grupo_id" => $grupo['grupo_id'], ":id" => $user->user['id'])
                    );
                ?>
                <h3 class="text-center mt-3 w-100">
                    <b>
                        <?= ucfirst($grupo['grupo_nombre']) ?>
                    </b>
                </h3>
                <br>
                <?
                foreach ($paginas as $pagina) {
                    ?>
                    <div class="movie card col-10 col-md-3 border-primary border-3 m-2">
                        <div class="card-body text-center bg-light">
                            <a href="<?= $pagina['pagina_ruta'] ?>.php"
                                class="card-link text-decoration-none text-primary d-flex flex-column align-items-center">
                                <i class="<?= $grupo['grupo_icon'] ?>" aria-hidden="true"></i>
                                <h5 class="card-title mt-2">
                                    <?= $pagina['pagina_titulo']; ?>
                                </h5>
                            </a>
                        </div>
                    </div>
                <?
                }
            } ?>
        </div>
    </main>
    <?php
    include "import/html_footer.php";
    ?>
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap/bootstrap.min.js"></script>
    <?php include_once 'js/messages.php'; ?>
    <script>
        $(document).ready(function () {
            // constantly update the date and time
            setInterval(function () {
                $('.fecha_hora').html(new Date().toLocaleString());
            }, 1000);

            <?php if (isset($_GET['error'])) { ?>
                var error = <?php echo $_GET['error'] ?? 0; ?>;
                switch (error) {
                    case 1:
                        triggerMessage('No tienes permiso de acceso a esta página', 'Error de permisos', 'danger');
                        break;

                    default:
                        triggerMessage('Error desconocido', 'Error', 'danger');
                        break;
                }
            <?php } ?>
        });
    </script>
</body>

</html>