<?php
include("../config/db.php");
if (!isset($_SESSION['admin'])) header("Location: login.php");

// Counts
$totalCategories = $conn->query("SELECT COUNT(*) AS total FROM categories")->fetch_assoc()['total'];

$totalVeg = $conn->query("SELECT COUNT(*) AS total FROM menu_items WHERE type='veg'")->fetch_assoc()['total'];

$totalNonVeg = $conn->query("SELECT COUNT(*) AS total FROM menu_items WHERE type='nonveg'")->fetch_assoc()['total'];

$totalItems = $conn->query("SELECT COUNT(*) AS total FROM menu_items")->fetch_assoc()['total'];
?>



<!DOCTYPE html>
<html>
<head>
    <title>Admin Dashboard</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">
</head>
<body>

<div class="d-flex">

<!-- ================= SIDEBAR ================= -->
<div class="bg-dark text-light p-3" style="width:260px; min-height:100vh;">
    <h4 class="mb-4">🍽 Admin Panel</h4>

    <ul class="nav flex-column">

        <li class="nav-item mb-2">
            <a href="dashboard.php" class="nav-link text-light">
                <i class="fa fa-chart-line"></i> Dashboard
            </a>
        </li>

        <li class="nav-item mb-2">
            <a class="nav-link text-light" data-bs-toggle="collapse" href="#catMenu">
                <i class="fa fa-list"></i> Categories
            </a>
            <div class="collapse ps-3" id="catMenu">
                <a href="categories.php" class="nav-link text-light">Manage Categories</a>
                <a href="subcategories.php" class="nav-link text-light">Manage Sub-Categories</a>
            </div>
        </li>

        <li class="nav-item mb-2">
            <a class="nav-link text-light" data-bs-toggle="collapse" href="#menuMenu">
                <i class="fa fa-utensils"></i> Menu Items
            </a>
            <div class="collapse ps-3" id="menuMenu">
                <a href="manage-menu.php" class="nav-link text-light">Manage Items</a>
                <a href="add-menu.php" class="nav-link text-light">Add Item</a>
            </div>
        </li>

        <li class="nav-item mt-3">
            <a href="logout.php" class="nav-link text-danger">
                <i class="fa fa-sign-out-alt"></i> Logout
            </a>
        </li>
    </ul>
</div>

<!-- ================= MAIN CONTENT ================= -->
<div class="flex-grow-1 p-4 bg-light">

<h2 class="mb-4">Dashboard</h2>

<div class="row g-4">

    <div class="col-md-3">
        <div class="card shadow text-center">
            <div class="card-body">
                <i class="fa fa-list fa-2x text-primary mb-2"></i>
                <h5>Categories</h5>
                <h3><?= $totalCategories ?></h3>
            </div>
        </div>
    </div>

    <div class="col-md-3">
        <div class="card shadow text-center">
            <div class="card-body">
                <i class="fa fa-leaf fa-2x text-success mb-2"></i>
                <h5>Veg Items</h5>
                <h3><?= $totalVeg ?></h3>
            </div>
        </div>
    </div>

    <div class="col-md-3">
        <div class="card shadow text-center">
            <div class="card-body">
                <i class="fa fa-drumstick-bite fa-2x text-danger mb-2"></i>
                <h5>Non-Veg Items</h5>
                <h3><?= $totalNonVeg ?></h3>
            </div>
        </div>
    </div>

    <div class="col-md-3">
        <div class="card shadow text-center">
            <div class="card-body">
                <i class="fa fa-utensils fa-2x text-dark mb-2"></i>
                <h5>Total Items</h5>
                <h3><?= $totalItems ?></h3>
            </div>
        </div>
    </div>

</div>

</div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
