<?php
/**
 * Header compartido con navegación unificada
 * Sistema SSOMA - Salud Ocupacional y Seguridad en el Trabajo
 */

// Incluir sistema de autenticación
require_once __DIR__ . '/auth.php';

// Requerir autenticación para todas las páginas
requireAuth();

// Detectar módulo actual
$current_module = basename(dirname($_SERVER['PHP_SELF']));
$page_title = $page_title ?? 'SSOMA';
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= htmlspecialchars($page_title) ?></title>

    <!-- Bootstrap 5.3 -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Bootstrap Icons -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.10.5/font/bootstrap-icons.min.css">

    <!-- Font Awesome (para recursoshumanos) -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">

    <!-- DataTables -->
    <link href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css" rel="stylesheet">

    <!-- Toastify -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css">

    <!-- Estilos compartidos -->
    <link rel="stylesheet" href="/ssoma/shared/assets/css/common.css">

    <!-- Estilos adicionales del módulo -->
    <?= $extra_css ?? '' ?>
</head>
<body>
    <!-- Navbar Principal -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
        <div class="container-fluid">
            <a class="navbar-brand" href="/ssoma/">
                <i class="bi bi-shield-check"></i> SSOMA
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarMain"
                    aria-controls="navbarMain" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarMain">
                <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                    <li class="nav-item">
                        <a class="nav-link <?= $current_module == 'dashboard' ? 'active' : '' ?>"
                           href="/ssoma/dashboard/">
                            <i class="bi bi-speedometer2"></i> Dashboard
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $current_module == 'recursoshumanos' ? 'active' : '' ?>"
                           href="/ssoma/recursoshumanos/">
                            <i class="bi bi-people-fill"></i> Trabajadores
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <?= $current_module == 'atencionesmedicas' ? 'active' : '' ?>"
                           href="/ssoma/atencionesmedicas/">
                            <i class="bi bi-heart-pulse"></i> Atenciones Médicas
                        </a>
                    </li>
                </ul>
                <div class="d-flex align-items-center">
                    <span class="navbar-text text-white me-3">
                        <i class="bi bi-person-circle"></i> <?= htmlspecialchars(Auth::nombre()) ?>
                        <?php if (Auth::isAdmin()): ?>
                            <span class="badge bg-warning text-dark ms-1">Admin</span>
                        <?php endif; ?>
                    </span>
                    <a href="/ssoma/logout.php" class="btn btn-outline-light btn-sm">
                        <i class="bi bi-box-arrow-right"></i> Salir
                    </a>
                </div>
            </div>
        </div>
    </nav>

    <!-- Contenido principal -->
    <div class="container-fluid mt-3">
