<?php
/**
 * Layout header para backoffice administrativo
 * Turpial Airlines, C.A.
 */

require_once '../includes/functions.php';
require_once '../includes/User.php';

// Verificar autenticación
requireLogin();

$current_page = basename($_SERVER['PHP_SELF'], '.php');
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo isset($page_title) ? $page_title . ' - ' : ''; ?>Turpial Airlines Admin</title>
    
    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <!-- Chart.js -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <!-- Custom CSS -->
    <link href="../assets/css/style.css" rel="stylesheet">
    
    <style>
        .main-content {
            margin-left: 0;
            transition: margin-left 0.3s;
        }
        
        .sidebar {
            position: fixed;
            top: 0;
            left: 0;
            height: 100vh;
            width: 250px;
            z-index: 1000;
            transform: translateX(-100%);
            transition: transform 0.3s;
        }
        
        .sidebar.show {
            transform: translateX(0);
        }
        
        @media (min-width: 992px) {
            .sidebar {
                transform: translateX(0);
            }
            .main-content {
                margin-left: 250px;
            }
        }
        
        .navbar-admin {
            background: linear-gradient(135deg, var(--turpial-yellow) 0%, var(--turpial-yellow-dark) 100%);
            color: var(--turpial-black);
        }
        
        .content-wrapper {
            min-height: calc(100vh - 76px);
            padding: 2rem;
        }
    </style>
</head>
<body>
    <!-- Sidebar -->
    <nav class="sidebar admin-sidebar" id="sidebar">
        <div class="p-3 text-center border-bottom border-secondary">
            <h5 class="text-turpial mb-0">
                <i class="fas fa-plane-departure me-2"></i>
                Turpial Airlines
            </h5>
            <small class="text-light">Panel Administrativo</small>
        </div>
        
        <ul class="nav flex-column mt-3">
            <li class="nav-item">
                <a class="nav-link <?php echo $current_page == 'dashboard' ? 'active' : ''; ?>" href="dashboard.php">
                    <i class="fas fa-tachometer-alt"></i>Dashboard
                </a>
            </li>
            
            <li class="nav-item">
                <a class="nav-link <?php echo $current_page == 'vacancies' ? 'active' : ''; ?>" href="vacancies.php">
                    <i class="fas fa-briefcase"></i>Vacantes
                </a>
            </li>
            
            <li class="nav-item">
                <a class="nav-link <?php echo $current_page == 'applications' ? 'active' : ''; ?>" href="applications.php">
                    <i class="fas fa-file-alt"></i>Aplicaciones
                </a>
            </li>
            
            <li class="nav-item">
                <a class="nav-link <?php echo $current_page == 'divisions' ? 'active' : ''; ?>" href="divisions.php">
                    <i class="fas fa-building"></i>Divisiones
                </a>
            </li>
            
          
            
            <?php if (hasPermission(2)): // Solo Admin y Super Admin ?>
            <li class="nav-item">
                <a class="nav-link <?php echo $current_page == 'users' ? 'active' : ''; ?>" href="users.php">
                    <i class="fas fa-users"></i>Usuarios
                </a>
            </li>
            <?php endif; ?>
            
            <li class="nav-item">
                <a class="nav-link <?php echo $current_page == 'reports' ? 'active' : ''; ?>" href="reports.php">
                    <i class="fas fa-chart-line"></i>Reportes
                </a>
            </li>
            
            <li class="nav-item mt-3 border-top border-secondary pt-3">
                <a class="nav-link" href="../public/index.php" target="_blank">
                    <i class="fas fa-external-link-alt"></i>Ver Sitio Web
                </a>
            </li>
            
            <li class="nav-item">
                <a class="nav-link" href="logout.php">
                    <i class="fas fa-sign-out-alt"></i>Cerrar Sesión
                </a>
            </li>
        </ul>
        
        <div class="mt-auto p-3 border-top border-secondary">
            <div class="text-center">
                <small class="text-light">
                    <strong><?php echo escape($_SESSION['full_name']); ?></strong><br>
                    <span class="text-turpial"><?php echo escape($_SESSION['role_name']); ?></span>
                </small>
            </div>
        </div>
    </nav>
    
    <!-- Top Navigation -->
    <nav class="navbar navbar-admin navbar-expand-lg main-content">
        <div class="container-fluid">
            <button class="btn d-lg-none" type="button" onclick="toggleSidebar()">
                <i class="fas fa-bars"></i>
            </button>
            
            <span class="navbar-brand mb-0 h1">
                <?php echo isset($page_title) ? $page_title : 'Panel Administrativo'; ?>
            </span>
            
            <div class="navbar-nav ms-auto">
                <div class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">
                        <i class="fas fa-user-circle me-1"></i>
                        <?php echo escape($_SESSION['full_name']); ?>
                    </a>
                    <ul class="dropdown-menu dropdown-menu-end">
                        <li><h6 class="dropdown-header"><?php echo escape($_SESSION['role_name']); ?></h6></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="profile.php"><i class="fas fa-user me-2"></i>Mi Perfil</a></li>
                        <li><a class="dropdown-item" href="../public/index.php" target="_blank"><i class="fas fa-external-link-alt me-2"></i>Ver Sitio Web</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="logout.php"><i class="fas fa-sign-out-alt me-2"></i>Cerrar Sesión</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </nav>
    
    <!-- Main Content -->
    <main class="main-content">
        <div class="content-wrapper">
