<?php
/**
 * Enterprise HRM ERP System - Header Template
 * Excel-like UI with tables
 */

if (!defined('HRM_ACCESS')) {
    die('Direct access not allowed');
}

requireLogin();

$pageTitle = isset($pageTitle) ? $pageTitle : 'Dashboard';
$currentModule = isset($currentModule) ? $currentModule : 'dashboard';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo htmlspecialchars($pageTitle); ?> - <?php echo getSetting('SYSTEM_NAME', APP_NAME); ?></title>
    <link rel="stylesheet" href="<?php echo BASE_URL; ?>/assets/css/style.css">
    <link rel="stylesheet" href="<?php echo BASE_URL; ?>/assets/css/table.css">
</head>
<body>
    <div class="app-container">
        <!-- Sidebar Navigation -->
        <aside class="sidebar">
            <div class="sidebar-header">
                <h2><?php echo getSetting('SYSTEM_NAME', APP_NAME); ?></h2>
                <p class="site-info"><?php echo htmlspecialchars($_SESSION['site_name'] ?? 'Site'); ?></p>
            </div>
            
            <nav class="sidebar-nav">
                <ul>
                    <li class="<?php echo $currentModule === 'dashboard' ? 'active' : ''; ?>">
                        <a href="<?php echo BASE_URL; ?>/index.php">
                            <span class="icon">📊</span> Dashboard
                        </a>
                    </li>
                    <li class="<?php echo $currentModule === 'employee' ? 'active' : ''; ?>">
                        <a href="<?php echo BASE_URL; ?>/modules/employee/list.php">
                            <span class="icon">👥</span> Employees
                        </a>
                    </li>
                    <li class="<?php echo $currentModule === 'attendance' ? 'active' : ''; ?>">
                        <a href="<?php echo BASE_URL; ?>/modules/attendance/list.php">
                            <span class="icon">⏰</span> Attendance
                        </a>
                    </li>
                    <li class="<?php echo $currentModule === 'leave' ? 'active' : ''; ?>">
                        <a href="/hrm/modules/leave/list.php" onclick="console.log('Leave clicked'); return true;">
                            <span class="icon">📅</span> Leave Management
                        </a>
                    </li>
                    <li class="<?php echo $currentModule === 'payroll' ? 'active' : ''; ?>">
                        <a href="/hrm/modules/payroll/list.php" onclick="console.log('Payroll clicked'); return true;">
                            <span class="icon">💰</span> Payroll
                        </a>
                    </li>
                    <li class="<?php echo $currentModule === 'reports' ? 'active' : ''; ?>">
                        <a href="/hrm/modules/mis/index.php" onclick="console.log('Reports clicked'); return true;">
                            <span class="icon">📈</span> Reports
                        </a>
                    </li>
                    <li class="<?php echo $currentModule === 'settings' ? 'active' : ''; ?>">
                        <a href="/hrm/admin/settings.php" onclick="console.log('Settings clicked'); return true;">
                            <span class="icon">⚙️</span> Settings
                        </a>
                    </li>
                </ul>
            </nav>
            
            <div class="sidebar-footer">
                <div class="user-info">
                    <p><strong><?php echo htmlspecialchars($_SESSION['full_name'] ?? 'User'); ?></strong></p>
                    <p class="role"><?php echo htmlspecialchars($_SESSION['role_name'] ?? 'Role'); ?></p>
                </div>
                <a href="<?php echo BASE_URL; ?>/auth/logout.php" class="btn-logout">Logout</a>
            </div>
        </aside>

        <!-- Main Content -->
        <main class="main-content">
            <!-- Top Bar -->
            <header class="top-bar">
                <h1><?php echo htmlspecialchars($pageTitle); ?></h1>
                <div class="top-bar-actions">
                    <span class="current-time" id="current-time"></span>
                </div>
            </header>

            <!-- Flash Messages -->
            <?php
            $success = getFlashMessage('success');
            $error = getFlashMessage('error');
            $warning = getFlashMessage('warning');
            $info = getFlashMessage('info');
            ?>
            
            <?php if ($success): ?>
            <div class="alert alert-success">
                <span class="alert-icon">✓</span>
                <span class="alert-message"><?php echo htmlspecialchars($success); ?></span>
            </div>
            <?php endif; ?>
            
            <?php if ($error): ?>
            <div class="alert alert-error">
                <span class="alert-icon">✗</span>
                <span class="alert-message"><?php echo htmlspecialchars($error); ?></span>
            </div>
            <?php endif; ?>
            
            <?php if ($warning): ?>
            <div class="alert alert-warning">
                <span class="alert-icon">⚠</span>
                <span class="alert-message"><?php echo htmlspecialchars($warning); ?></span>
            </div>
            <?php endif; ?>
            
            <?php if ($info): ?>
            <div class="alert alert-info">
                <span class="alert-icon">ℹ</span>
                <span class="alert-message"><?php echo htmlspecialchars($info); ?></span>
            </div>
            <?php endif; ?>

            <!-- Page Content -->
            <div class="content-wrapper">

