<?php
require_once __DIR__ . '/db.php';

// Cek apakah admin sudah login
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
    header("Location: login.php");
    exit();
}

$admin_name = isset($_SESSION['admin_name']) ? $_SESSION['admin_name'] : 'Admin';
$current_page = basename($_SERVER['PHP_SELF']);
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo isset($page_title) ? $page_title . " - Admin Edelys" : "Panel Admin - Toko Kue Edelys"; ?></title>
    <!-- CSS -->
    <link rel="stylesheet" href="../assets/css/admin.css">
    <!-- Icons -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
</head>
<body>
    <!-- Sidebar -->
    <aside class="sidebar">
        <div class="sidebar-brand">
            Edelys<span>Owner</span>
        </div>
        <ul class="sidebar-menu">
            <li class="<?php echo $current_page == 'index.php' ? 'active' : ''; ?>">
                <a href="index.php"><i class="fa-solid fa-chart-line"></i> Dashboard</a>
            </li>
            <li class="<?php echo $current_page == 'orders.php' ? 'active' : ''; ?>">
                <a href="orders.php"><i class="fa-solid fa-receipt"></i> Pesanan</a>
            </li>
            <li class="<?php echo $current_page == 'products.php' ? 'active' : ''; ?>">
                <a href="products.php"><i class="fa-solid fa-cookie"></i> Produk Kue</a>
            </li>
            <li class="<?php echo $current_page == 'stock.php' ? 'active' : ''; ?>">
                <a href="stock.php"><i class="fa-solid fa-boxes-stacked"></i> Mutasi Stok</a>
            </li>
            <li class="<?php echo $current_page == 'reports.php' ? 'active' : ''; ?>">
                <a href="reports.php"><i class="fa-solid fa-file-invoice"></i> Laporan Penjualan</a>
            </li>
        </ul>
        <div class="sidebar-footer">
           
            </a>
            <a href="logout.php" class="btn-admin btn-admin-danger" style="width: 100%; justify-content: center;">
                <i class="fa-solid fa-right-from-bracket"></i> Logout
            </a>
        </div>
    </aside>

    <!-- Content Wrapper -->
    <div class="admin-wrapper">
        <header class="admin-header">
            <div class="admin-header-title">
                <h1><?php echo isset($header_title) ? $header_title : 'Ringkasan Dashboard'; ?></h1>
            </div>
            <div class="admin-header-user" style="gap: 1rem;">
               
                </a>
                <div style="display: flex; align-items: center; gap: 0.5rem;">
                    <i class="fa-solid fa-user-circle" style="font-size: 1.5rem; color: var(--accent);"></i>
                    <span>Halo, <?php echo htmlspecialchars($admin_name); ?></span>
                </div>
            </div>
        </header>
