<?php
require_once __DIR__ . '/helpers.php';
require_once __DIR__ . '/auth.php';
?>
<!doctype html>
<html lang="id">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Admin - <?= sanitize(APP_NAME); ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="<?= base_url('assets/css/style.css'); ?>">
</head>
<body class="admin">
<div class="admin-layout">
    <?php if (is_logged_in()): ?>
    <aside class="admin-sidebar">
        <div class="admin-brand">Admin Panel</div>
        <nav class="admin-nav">
            <a href="<?= base_url('admin/dashboard.php'); ?>">Dashboard</a>
            <a href="<?= base_url('admin/categories.php'); ?>">Kategori</a>
            <a href="<?= base_url('admin/products.php'); ?>">Produk</a>
            <a href="<?= base_url('admin/product_create.php'); ?>">Tambah Produk</a>
            <a href="<?= base_url('admin/sliders.php'); ?>">Manajemen Slider</a>
            <a href="<?= base_url('admin/customers.php'); ?>">Customer</a>
            <a href="<?= base_url('admin/orders.php'); ?>">Order Online</a>
            <a href="<?= base_url('admin/sales_online.php'); ?>">Penjualan Online</a>
            <a href="<?= base_url('admin/sales_offline.php'); ?>">Penjualan Offline</a>
            <a href="<?= base_url('admin/report_online.php'); ?>">Laporan Online</a>
            <a href="<?= base_url('admin/report_offline.php'); ?>">Laporan Offline</a>
            <a href="<?= base_url('admin/payment_methods.php'); ?>">Metode Pembayaran</a>
            <a href="<?= base_url('admin/shipping.php'); ?>">Manajemen Ongkir</a>
            <?php if ((current_user()['role'] ?? '') === 'owner'): ?>
                <a href="<?= base_url('admin/report_all.php'); ?>">Laporan Keseluruhan</a>
                <a href="<?= base_url('owner/users.php'); ?>">Manajemen User</a>
            <?php endif; ?>
            <a href="<?= base_url('admin/report_customers.php'); ?>">Laporan Customer</a>
            <a href="<?= base_url('admin/report_stock.php'); ?>">Laporan Stok</a>
            <a href="<?= base_url('admin/user_logout.php'); ?>">Keluar</a>
        </nav>
    </aside>
    <?php endif; ?>
    <div class="admin-main">
        <?php if (is_logged_in()): ?>
        <header class="admin-topbar">
            <div>
                <strong>Halo, <?= sanitize(current_user()['name'] ?? 'Admin'); ?></strong>
            </div>
            <div class="small text-muted"><?= sanitize(current_user()['role'] ?? ''); ?></div>
        </header>
        <?php endif; ?>
        <main class="admin-content">
            <?php if ($message = flash_message('success')): ?>
                <div class="alert success mb-3"><?= sanitize($message); ?></div>
            <?php endif; ?>
            <?php if ($message = flash_message('error')): ?>
                <div class="alert error mb-3"><?= sanitize($message); ?></div>
            <?php endif; ?>
