<?php
require_once '../includes/auth.php';
require_once '../includes/functions.php';

require_login('ground_handler');
$page_title = 'Dashboard Ground Handling - ANATL Portal';
$user_id = $_SESSION['user_id'];

// Get stats
$result = $conn->query("SELECT COUNT(*) as count FROM service_reports WHERE vendor_id = $user_id");
$stats['reports'] = $result->fetch_assoc()['count'];

$result = $conn->query("SELECT COUNT(*) as count FROM invoices WHERE vendor_id = $user_id AND status = 'unpaid'");
$stats['unpaid'] = $result->fetch_assoc()['count'];

$result = $conn->query("SELECT COUNT(*) as count FROM invoices WHERE vendor_id = $user_id AND status = 'paid'");
$stats['paid'] = $result->fetch_assoc()['count'];
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $page_title ?></title>
    <link rel="stylesheet" href="<?= BASE_URL ?>/assets/css/style.css">
</head>
<body>
<?php require '../includes/header.php'; ?>

<div class="main">
    <div class="portal">
        <div class="portal__sidebar">
            <div class="sidebar__title">Menu Ground Handling</div>
            <a href="<?= BASE_URL ?>/ground-handling/index.php" class="sidebar-item sidebar-item--active">📊 Dashboard</a>
            <a href="<?= BASE_URL ?>/ground-handling/notif.php" class="sidebar-item">📢 Penerbangan</a>
            <a href="<?= BASE_URL ?>/ground-handling/invoice.php" class="sidebar-item">💰 Invoice</a>
        </div>

        <div class="portal__content">
            <h1 style="color: #003A70; margin-bottom: 32px;">Dashboard Ground Handling</h1>

            <div class="grid grid--3" style="margin-bottom: 48px;">
                <div class="stat-card">
                    <div style="font-size: 24px;">📋</div>
                    <div class="stat-card__value"><?= $stats['reports'] ?></div>
                    <div class="stat-card__label">Service Reports</div>
                </div>

                <div class="stat-card">
                    <div style="font-size: 24px;">⚠️</div>
                    <div class="stat-card__value"><?= $stats['unpaid'] ?></div>
                    <div class="stat-card__label">Invoice Unpaid</div>
                </div>

                <div class="stat-card">
                    <div style="font-size: 24px;">✅</div>
                    <div class="stat-card__value"><?= $stats['paid'] ?></div>
                    <div class="stat-card__label">Invoice Paid</div>
                </div>
            </div>

            <div class="card">
                <div class="card__header">
                    <div class="card__title">Quick Actions</div>
                </div>
                <div class="grid grid--2">
                    <a href="<?= BASE_URL ?>/ground-handling/notif.php" class="btn btn--primary">Lihat Penerbangan</a>
                    <a href="<?= BASE_URL ?>/ground-handling/invoice.php" class="btn btn--primary">Lihat Invoice</a>
                </div>
            </div>
        </div>
    </div>
</div>

<?php require '../includes/footer.php'; ?>
