<?php
require_once __DIR__ . '/config/auth.php';
require_login();

$pageTitle = 'Dashboard';
$activePage = 'dashboard';

$personnelCount = (int) db_value($conn, 'SELECT COUNT(*) FROM employee_passes');
$visitorCount = (int) db_value($conn, 'SELECT COUNT(*) FROM visitor_passes');
$itemCount = (int) db_value($conn, 'SELECT COUNT(*) FROM package_passes');
$foodCount = (int) db_value($conn, 'SELECT COUNT(*) FROM item_passes');
$mealBreakCount = (int) db_value($conn, 'SELECT COUNT(*) FROM meal_break_passes');

$pendingCount = (int) db_value($conn, "
    SELECT
        (SELECT COUNT(*) FROM employee_passes WHERE status = 'Pending') +
        (SELECT COUNT(*) FROM visitor_passes WHERE status = 'Pending') +
        (SELECT COUNT(*) FROM package_passes WHERE status = 'Pending') +
        (SELECT COUNT(*) FROM item_passes WHERE status = 'Pending') +
        (SELECT COUNT(*) FROM meal_break_passes WHERE status = 'Pending')
");

include __DIR__ . '/includes/header.php';
?>

<div class="stats-grid">

    <div class="stat-card">
        <div>
            <span>Item Passes</span>
            <strong><?php echo $itemCount; ?></strong>
        </div>
        <i class="bi bi-box-seam"></i>
    </div>

    <div class="stat-card">
        <div>
            <span>Personnel Passes</span>
            <strong><?php echo $personnelCount; ?></strong>
        </div>
        <i class="bi bi-person-badge"></i>
    </div>

    <div class="stat-card">
        <div>
            <span>Visitor Passes</span>
            <strong><?php echo $visitorCount; ?></strong>
        </div>
        <i class="bi bi-person-plus"></i>
    </div>

    <div class="stat-card">
        <div>
            <span>Food Passes</span>
            <strong><?php echo $foodCount; ?></strong>
        </div>
        <i class="bi bi-cup-hot"></i>
    </div>

    <div class="stat-card">
        <div>
            <span>Meal Break Passes</span>
            <strong><?php echo $mealBreakCount; ?></strong>
        </div>
        <i class="bi bi-egg-fried"></i>
    </div>

    <div class="stat-card">
        <div>
            <span>Pending Requests</span>
            <strong><?php echo $pendingCount; ?></strong>
        </div>
        <i class="bi bi-hourglass-split"></i>
    </div>

</div>

<section class="content-panel mt-4">
    <div class="panel-heading">
        <div>
            <h2>Quick Actions</h2>
            <p>Create and monitor gate passes from one simple workspace.</p>
        </div>
    </div>

    <div class="quick-actions">

        <a class="quick-action" href="packages.php">
            <i class="bi bi-box-seam"></i>
            <span>Item Pass</span>
        </a>

        <a class="quick-action" href="employees.php">
            <i class="bi bi-person-badge"></i>
            <span>Personnel Pass</span>
        </a>

        <a class="quick-action" href="visitors.php">
            <i class="bi bi-person-plus"></i>
            <span>Visitor Pass</span>
        </a>

        <a class="quick-action" href="items.php">
            <i class="bi bi-cup-hot"></i>
            <span>Food Pass</span>
        </a>

        <a class="quick-action" href="mealbreak.php">
            <i class="bi bi-egg-fried"></i>
            <span>Meal Break Pass</span>
        </a>

        <a class="quick-action" href="activity_logs.php">
            <i class="bi bi-list-check"></i>
            <span>Activity Logs</span>
        </a>

    </div>
</section>

<?php include __DIR__ . '/includes/footer.php'; ?>