<?php
declare(strict_types=1);

/**
 * Layout comun. Cada pagina debe definir $pageTitle y $activeMenu antes de incluir este archivo.
 * $activeMenu valores esperados: dashboard, consultas, importar, informes
 */
$pageTitle  = $pageTitle ?? APP_NAME;
$activeMenu = $activeMenu ?? '';
$basePath   = $basePath ?? '..';
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= h($pageTitle) ?> · <?= h(APP_NAME) ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
<link href="https://cdn.datatables.net/1.13.11/css/dataTables.bootstrap5.min.css" rel="stylesheet">
<link href="<?= h($basePath) ?>/assets/css/style.css" rel="stylesheet">
</head>
<body>
<div class="d-flex" id="app-wrapper">
  <nav class="sidebar bg-dark text-white" id="sidebar">
    <div class="sidebar-brand">
      <i class="bi bi-boxes"></i>
      <span>Dimersad ERP</span>
    </div>
    <ul class="nav flex-column">
      <li class="nav-item">
        <a class="nav-link <?= $activeMenu === 'dashboard' ? 'active' : '' ?>" href="<?= h($basePath) ?>/informes/index.php">
          <i class="bi bi-speedometer2"></i> Dashboard
        </a>
      </li>

      <li class="nav-section">Consultas</li>
      <li class="nav-item"><a class="nav-link <?= ($activeMenu === 'consultas' && ($activePage ?? '') === 'clientes') ? 'active' : '' ?>" href="<?= h($basePath) ?>/consultas/clientes.php"><i class="bi bi-people"></i> Clientes</a></li>
      <li class="nav-item"><a class="nav-link <?= ($activeMenu === 'consultas' && ($activePage ?? '') === 'productos') ? 'active' : '' ?>" href="<?= h($basePath) ?>/consultas/productos.php"><i class="bi bi-box-seam"></i> Productos</a></li>
      <li class="nav-item"><a class="nav-link <?= ($activeMenu === 'consultas' && ($activePage ?? '') === 'vendedores') ? 'active' : '' ?>" href="<?= h($basePath) ?>/consultas/vendedores.php"><i class="bi bi-person-badge"></i> Vendedores</a></li>
      <li class="nav-item"><a class="nav-link <?= ($activeMenu === 'consultas' && ($activePage ?? '') === 'ventas') ? 'active' : '' ?>" href="<?= h($basePath) ?>/consultas/ventas.php"><i class="bi bi-receipt"></i> Ventas</a></li>
      <li class="nav-item"><a class="nav-link <?= ($activeMenu === 'consultas' && ($activePage ?? '') === 'cartera') ? 'active' : '' ?>" href="<?= h($basePath) ?>/consultas/cartera.php"><i class="bi bi-cash-stack"></i> Cartera</a></li>
      <li class="nav-item"><a class="nav-link <?= ($activeMenu === 'consultas' && ($activePage ?? '') === 'recaudos') ? 'active' : '' ?>" href="<?= h($basePath) ?>/consultas/recaudos.php"><i class="bi bi-wallet2"></i> Recaudos</a></li>

      <li class="nav-section">Importación</li>
      <li class="nav-item"><a class="nav-link <?= ($activeMenu === 'importar') ? 'active' : '' ?>" href="<?= h($basePath) ?>/importar/index.php"><i class="bi bi-upload"></i> Cargar CSV</a></li>

      <li class="nav-section">Informes</li>
      <li class="nav-item"><a class="nav-link <?= ($activeMenu === 'informes' && ($activePage ?? '') === 'cartera') ? 'active' : '' ?>" href="<?= h($basePath) ?>/informes/cartera.php"><i class="bi bi-graph-up-arrow"></i> Cartera vencida</a></li>
      <li class="nav-item"><a class="nav-link <?= ($activeMenu === 'informes' && ($activePage ?? '') === 'ventas') ? 'active' : '' ?>" href="<?= h($basePath) ?>/informes/ventas.php"><i class="bi bi-bar-chart-line"></i> Ventas y recaudo</a></li>
      <li class="nav-item"><a class="nav-link <?= ($activeMenu === 'informes' && ($activePage ?? '') === 'utilidad_ventas') ? 'active' : '' ?>" href="<?= h($basePath) ?>/informes/utilidad_ventas.php"><i class="bi bi-cash-coin"></i> Utilidad por Ventas</a></li>
    </ul>
  </nav>

  <div class="flex-grow-1">
    <nav class="navbar navbar-expand navbar-light bg-white border-bottom topbar">
      <div class="container-fluid">
        <button class="btn btn-sm btn-outline-secondary d-lg-none" id="btnToggleSidebar" type="button">
          <i class="bi bi-list"></i>
        </button>
        <span class="fw-semibold ms-2"><?= h($pageTitle) ?></span>
      </div>
    </nav>
    <main class="container-fluid py-4">
