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

require_login('airline');
$page_title = 'Dashboard Maskapai - ANATL Portal';
$current_user = get_user();

// Get statistics
$user_id = $_SESSION['user_id'];
$stats = [];

$result = $conn->query("SELECT COUNT(*) as count FROM slot_requests WHERE user_id = $user_id");
$stats['slots'] = $result->fetch_assoc()['count'];

$result = $conn->query("SELECT COUNT(*) as count FROM flight_plans WHERE user_id = $user_id");
$stats['plans'] = $result->fetch_assoc()['count'];

$result = $conn->query("SELECT COUNT(*) as count FROM safety_reports WHERE user_id = $user_id");
$stats['safety'] = $result->fetch_assoc()['count'];

$result = $conn->query("SELECT COUNT(*) as count FROM slot_requests WHERE user_id = $user_id AND status = 'approved'");
$stats['approved'] = $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 Maskapai</div>
            <a href="<?= BASE_URL ?>/maskapai/index.php" class="sidebar-item sidebar-item--active">📊 Dashboard</a>
            <a href="<?= BASE_URL ?>/maskapai/slot.php" class="sidebar-item">✈️ Slot Time</a>
            <a href="<?= BASE_URL ?>/maskapai/flight-plan.php" class="sidebar-item">📋 Flight Plan</a>
            <a href="<?= BASE_URL ?>/maskapai/safety.php" class="sidebar-item">⚠️ Safety Report</a>
        </div>

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

            <p style="color: #5A6A7A; margin-bottom: 32px;">Selamat datang, <strong><?= esc($current_user['company_name'] ?? $current_user['username']) ?></strong></p>

            <div class="grid grid--4" style="margin-bottom: 48px;">
                <div class="stat-card">
                    <div style="font-size: 24px;">✈️</div>
                    <div class="stat-card__value"><?= $stats['slots'] ?></div>
                    <div class="stat-card__label">Total Slot Time</div>
                </div>

                <div class="stat-card">
                    <div style="font-size: 24px;">📋</div>
                    <div class="stat-card__value"><?= $stats['plans'] ?></div>
                    <div class="stat-card__label">Flight Plan</div>
                </div>

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

                <div class="stat-card">
                    <div style="font-size: 24px;">⚠️</div>
                    <div class="stat-card__value"><?= $stats['safety'] ?></div>
                    <div class="stat-card__label">Safety Reports</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 ?>/maskapai/slot.php" class="btn btn--primary">Pengajuan Slot Time</a>
                    <a href="<?= BASE_URL ?>/maskapai/flight-plan.php" class="btn btn--primary">Pengajuan Flight Plan</a>
                    <a href="<?= BASE_URL ?>/maskapai/safety.php" class="btn btn--secondary">Lapor Safety Incident</a>
                </div>
            </div>
        </div>
    </div>
</div>

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