<?php
require_once __DIR__.'/bootstrap.php';
function page_start(string $title): void { $u=user(); $menus=menu_registry(); $current=$_GET['p']??'dashboard'; ?>
<!doctype html><html lang="es"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title><?=e($title)?> - <?=e(APP_NAME)?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet"><link href="<?=url('assets/style.css')?>" rel="stylesheet"><link href="<?=url('assets/navigation.css')?>" rel="stylesheet"><link href="<?=url('assets/branding.css')?>" rel="stylesheet"><script src="<?=url('assets/app.js')?>"></script></head><body>
<aside class="sidebar"><div class="brand"><div class="brand-logo"><img src="<?=url('assets/img/logo_principal.png')?>" alt="Grupo de Inversiones S.A."></div><h6>Grupo de Inversiones S.A.</h6><small><?=e(APP_TAGLINE)?></small></div><nav>
<?php foreach(['Inicio','Mantenimiento','Parámetros','Operaciones','Caja','Informes','Seguridad'] as $group): $items=array_filter($menus,fn($m)=>$m[3]===$group); $visible=array_filter($items,fn($m,$k)=>allowed($k),ARRAY_FILTER_USE_BOTH); if(!$visible)continue; $gid='menu-'.preg_replace('/[^a-z]/','',strtolower($group)); ?>
<?php $collapsible=$group!=='Inicio'; if($collapsible):?><div class="menu-group"><a class="menu-title group-link" href="<?=url('app.php?p=grupo&g='.urlencode($group))?>"><i class="fa-solid fa-folder"></i><span><?=e($group)?></span></a><button type="button" class="group-toggle" aria-expanded="false" aria-controls="<?=$gid?>"><i class="fa-solid fa-chevron-down"></i></button></div><div class="submenu" id="<?=$gid?>"><?php endif;?>
<?php foreach($visible as $key=>$m):?><a class="<?=$current===$key||($_GET['t']??'')===$key?'active':''?>" href="<?=url($m[2])?>"><i class="fa-solid <?=e($m[1])?>"></i><?=e($m[0])?></a><?php endforeach;?><?php if($collapsible):?></div><?php endif;?><?php endforeach;?></nav>
<div class="sidebar-footer"><a href="<?=url('logout.php')?>"><i class="fa-solid fa-right-from-bracket"></i>Salir</a></div></aside>
<main class="main"><header class="topbar"><button class="btn sidebar-toggle"><i class="fa fa-bars"></i></button><div><strong><?=e(APP_NAME)?></strong></div><span class="ms-auto"><i class="fa fa-circle-user me-1"></i><?=e($u['nombre']??'')?></span></header><section class="content"><div class="text-end mb-2 no-print"><button type="button" class="btn btn-outline-primary btn-sm" onclick="window.print()"><i class="fa fa-print me-1"></i>Imprimir</button></div><?php $isSub=basename($_SERVER['PHP_SELF']??'')==='app.php' && ($_GET['p']??'')!=='grupo'; if($isSub): $backGroup='Mantenimiento'; foreach($menus as $key=>$m){if(($current===$key||($_GET['t']??'')===$key)){$backGroup=$m[3];break;}} ?><div class="mb-3 no-print"><a class="btn btn-outline-secondary btn-sm" href="<?=url('app.php?p=grupo&g='.urlencode($backGroup))?>" onclick="if(window.history.length>1){window.history.back();return false}"><i class="fa fa-arrow-left me-1"></i>Volver</a></div><?php endif;?>
<?php foreach($_SESSION['flash']??[] as [$type,$text]):?><div class="alert alert-<?=e($type)?> alert-dismissible fade show"><?=e($text)?><button class="btn-close" data-bs-dismiss="alert"></button></div><?php endforeach; unset($_SESSION['flash']);?>
<?php }
function page_end(): void { ?></section></main><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script></body></html><?php }

