<?php
require_once 'config.php';
require_once 'functions.php';

$current_page = basename($_SERVER['PHP_SELF']);
if ($current_page != 'login.php') {
    requireLogin();
}

$current_user = null;
if (isLoggedIn()) {
    global $db;
    $current_user = $db->fetchOne("SELECT * FROM users WHERE id = ?", [$_SESSION['user_id']]);
}
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= APP_NAME ?> - <?= $page_title ?? 'لوحة التحكم' ?></title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Almarai:wght@300;400;700;800&display=swap" rel="stylesheet">

    <link rel="stylesheet" href="assets/css/style.css">
</head>

<body>
    <div class="container">
        <!-- Sidebar -->
        <div class="sidebar">
            <div class="sidebar-header">
                <h2><?= APP_NAME ?></h2>
            </div>
            <div class="sidebar-menu">
                <a href="dashboard.php" class="menu-item <?= $current_page == 'dashboard.php' ? 'active' : '' ?>">
                    <i class="fas fa-tachometer-alt"></i>
                    <span>لوحة التحكم</span>
                </a>
                <a href="create_invoice.php" class="menu-item <?= $current_page == 'create_invoice.php' ? 'active' : '' ?>">
                    <i class="fas fa-file-invoice-dollar"></i>
                    <span>إنشاء فاتورة</span>
                </a>
                <a href="review_invoices.php" class="menu-item <?= $current_page == 'review_invoices.php' ? 'active' : '' ?>">
                    <i class="fas fa-list"></i>
                    <span>مراجعة الفواتير</span>
                </a>
                <a href="search_invoice.php" class="menu-item <?= $current_page == 'search_invoice.php' ? 'active' : '' ?>">
                    <i class="fas fa-search"></i>
                    <span>بحث عن فاتورة</span>
                </a>
                <a href="logout.php" class="menu-item">
                    <i class="fas fa-sign-out-alt"></i>
                    <span>تسجيل الخروج</span>
                </a>
            </div>
        </div>

        <!-- Main Content -->
        <div class="main-content">
            <div class="header">
                <h2 id="page-title"><?= $page_title ?? 'لوحة التحكم' ?></h2>
                <div class="user-info">
                    <img src="./assets/images/click.png" alt="admin">
                </div>
            </div>