<?php
require_once 'config/database.php';
require_once 'app/helpers/auth.php';
requireLogin();

$userName = $_SESSION['user_name'] ?? 'User';
$userName = $_SESSION['user_name'] ?? 'User';
$view = $_GET['view'] ?? 'overview';

$reportViews = [
    'overview' => [
        'title' => 'Reports Overview',
        'description' => 'Use report shortcuts to open the right operational screen quickly.'
    ],
    'compliance' => [
        'title' => 'Compliance Reports',
        'description' => 'Track expiring documents, renewal gaps, and jurisdiction-driven compliance issues.'
    ],
    'vehicles' => [
        'title' => 'Vehicle Reports',
        'description' => 'Review fleet inventory, assignments, and condition-focused vehicle reporting.'
    ],
    'drivers' => [
        'title' => 'Driver Reports',
        'description' => 'Review driver records, licenses, and assignment-linked people reporting.'
    ],
    'maintenance' => [
        'title' => 'Maintenance Reports',
        'description' => 'Track workshop requisitions, repair costs, and financial fulfillment.'
    ],
    'workshop' => [
        'title' => 'Workshop Reports',
        'description' => 'View workshop directory, activity, and performance metrics.'
    ],
    'fuel' => [
        'title' => 'Fuel Reports',
        'description' => 'Analyse fuel requests, approval status, consumption, and costs.'
    ]
];

$activeView = $reportViews[$view] ?? $reportViews['overview'];

include 'views/layouts/header.php';
include 'views/layouts/sidebar.php';
?>

<main class="main-content">
<?php include 'views/layouts/topbar.php'; ?>

<div class="container-fluid p-4">
    <div class="card shadow-sm border-0 compliance-hero mb-4">
        <div class="card-body p-4 p-lg-5">
            <span class="section-chip bg-white text-primary mb-3">Reports</span>
            <h2 class="mb-2"><?= htmlspecialchars($activeView['title'], ENT_QUOTES, 'UTF-8') ?></h2>
            <p class="mb-0 text-white-50"><?= htmlspecialchars($activeView['description'], ENT_QUOTES, 'UTF-8') ?></p>
        </div>
    </div>

    <div class="row g-4">
        <?php if ($view === 'overview' || $view === ''): ?>
        <div class="col-md-6 col-xl-3">
            <a href="reports.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-grid"></i></div>
                    <h5 class="mb-2">Overview</h5>
                    <p class="text-muted mb-0">See all reporting areas from one hub.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="reports.php?view=compliance" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-shield-check"></i></div>
                    <h5 class="mb-2">Compliance</h5>
                    <p class="text-muted mb-0">Open renewable document monitoring and expiring document views.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="reports.php?view=vehicles" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-truck"></i></div>
                    <h5 class="mb-2">Vehicles</h5>
                    <p class="text-muted mb-0">Open the vehicle register for fleet reporting and export workflows.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="reports.php?view=drivers" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-person-badge"></i></div>
                    <h5 class="mb-2">Drivers</h5>
                    <p class="text-muted mb-0">Open the driver register for driver and license reporting.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="reports.php?view=maintenance" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-tools"></i></div>
                    <h5 class="mb-2">Maintenance</h5>
                    <p class="text-muted mb-0">Open workshop financial reports and requisition tracking.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="reports.php?view=workshop" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-building-gear"></i></div>
                    <h5 class="mb-2">Workshop</h5>
                    <p class="text-muted mb-0">View workshop directory, contacts, and quote activity.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="audit_logs.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-clock-history"></i></div>
                    <h5 class="mb-2">Audit Logs</h5>
                    <p class="text-muted mb-0">Review activity history, approvals, and change traces.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="reports.php?view=fuel" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-fuel-pump"></i></div>
                    <h5 class="mb-2">Fuel</h5>
                    <p class="text-muted mb-0">Analyse fuel requests, approval status, and costs.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="tco_report.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-cash-stack"></i></div>
                    <h5 class="mb-2">TCO Report</h5>
                    <p class="text-muted mb-0">Total Cost of Ownership — fuel, maintenance, insurance, expenses.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="data_tools.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-arrow-up-down"></i></div>
                    <h5 class="mb-2">Data Import / Export</h5>
                    <p class="text-muted mb-0">Download and upload fleet data in CSV, Excel, or PDF formats.</p>
                </div>
            </a>
        </div>
        <?php elseif ($view === 'compliance'): ?>
        <!-- Compliance-specific reports -->
        <div class="col-md-6 col-xl-3">
            <a href="compliance.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-file-earmark-text"></i></div>
                    <h5 class="mb-2">Document Expiry</h5>
                    <p class="text-muted mb-0">Monitor expiring documents and renewal requirements.</p>
                </div>
            </a>
        </div>
        <!-- Add more compliance reports as needed -->
        <?php elseif ($view === 'vehicles'): ?>
        <!-- Vehicle-specific reports -->
        <div class="col-md-6 col-xl-3">
            <a href="vehicles.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-truck"></i></div>
                    <h5 class="mb-2">Vehicle Register</h5>
                    <p class="text-muted mb-0">View complete fleet inventory and vehicle details.</p>
                </div>
            </a>
        </div>
        <!-- Add more vehicle reports as needed -->
        <?php elseif ($view === 'drivers'): ?>
        <!-- Driver-specific reports -->
        <div class="col-md-6 col-xl-3">
            <a href="drivers.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-person-badge"></i></div>
                    <h5 class="mb-2">Driver Register</h5>
                    <p class="text-muted mb-0">View driver records and license information.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="driver_age_compliance.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-calendar-check"></i></div>
                    <h5 class="mb-2">Driver Age Compliance</h5>
                    <p class="text-muted mb-0">Check driver's driving age against contractual agreements.</p>
                </div>
            </a>
        </div>

       

        <div class="col-md-6 col-xl-3">
            <a href="driver_overage_report.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-person-up"></i></div>
                    <h5 class="mb-2">Over-Age Analysis</h5>
                    <p class="text-muted mb-0">Monitor drivers exceeding the contractual age limit.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="driver_underage_license.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-person-check"></i></div>
                    <h5 class="mb-2">Underage License Receipt</h5>
                    <p class="text-muted mb-0">Report drivers whose first license was issued before age 18.</p>
                </div>
            </a>
        </div>

        <div class="col-md-6 col-xl-3">
            <a href="driver_assignment_report.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-people"></i></div>
                    <h5 class="mb-2">Driver Assignment History</h5>
                    <p class="text-muted mb-0">View and export assignment records by driver or vehicle.</p>
                </div>
            </a>
        </div>
        <!-- Add more driver reports as needed -->
        <?php elseif ($view === 'maintenance'): ?>
        <!-- Maintenance-specific reports -->
        <div class="col-md-6 col-xl-3">
            <a href="maintenance.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-list-check"></i></div>
                    <h5 class="mb-2">Maintenance Register</h5>
                    <p class="text-muted mb-0">View all maintenance jobs, complaints, and workflow status.</p>
                </div>
            </a>
        </div>
        <div class="col-md-6 col-xl-3">
            <a href="maintenance.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-file-earmark-text"></i></div>
                    <h5 class="mb-2">Work Order Register</h5>
                    <p class="text-muted mb-0">Track work orders by status, workshop, and date range.</p>
                </div>
            </a>
        </div>
        <div class="col-md-6 col-xl-3">
            <a href="maintenance_requisition_report.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-cash-stack"></i></div>
                    <h5 class="mb-2">Requisition Analysis</h5>
                    <p class="text-muted mb-0">Track maintenance job payments and workshop requisitions.</p>
                </div>
            </a>
        </div>
        <div class="col-md-6 col-xl-3">
            <a href="reports.php?view=workshop" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-building-gear"></i></div>
                    <h5 class="mb-2">Workshop Reports</h5>
                    <p class="text-muted mb-0">View workshop directory, performance metrics, and quote activity.</p>
                </div>
            </a>
        </div>
        <?php elseif ($view === 'workshop'): ?>
        <!-- Workshop-specific reports -->
        <div class="col-md-6 col-xl-3">
            <a href="workshop_report.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-building-gear"></i></div>
                    <h5 class="mb-2">Workshop Directory</h5>
                    <p class="text-muted mb-0">View workshop records, contacts, phone, email, and status.</p>
                </div>
            </a>
        </div>
        <div class="col-md-6 col-xl-3">
            <a href="workshop_report.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-bar-chart"></i></div>
                    <h5 class="mb-2">Workshop Performance KPIs</h5>
                    <p class="text-muted mb-0">View total workshops, active workshops, RFQ pipeline, and quote value.</p>
                </div>
            </a>
        </div>
        <div class="col-md-6 col-xl-3">
            <a href="maintenance.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-wrench"></i></div>
                    <h5 class="mb-2">Active Workshop Jobs</h5>
                    <p class="text-muted mb-0">View maintenance jobs currently in workshop or inspection stages.</p>
                </div>
            </a>
        </div>
        <div class="col-md-6 col-xl-3">
            <a href="maintenance_requisition_report.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-currency-dollar"></i></div>
                    <h5 class="mb-2">Workshop Billing</h5>
                    <p class="text-muted mb-0">Track workshop payments, approved amounts, and requisition status.</p>
                </div>
            </a>
        </div>
        <?php elseif ($view === 'fuel'): ?>
        <div class="col-md-6 col-xl-3">
            <a href="fuel_request_report.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-fuel-pump"></i></div>
                    <h5 class="mb-2">Fuel Request Report</h5>
                    <p class="text-muted mb-0">Analyse fuel requests by date, vehicle, and approval status.</p>
                </div>
            </a>
        </div>
        <div class="col-md-6 col-xl-3">
            <a href="fuel_cards.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-credit-card-2-front"></i></div>
                    <h5 class="mb-2">Fuel Card Report</h5>
                    <p class="text-muted mb-0">View fuel card balances, limits, and transaction history.</p>
                </div>
            </a>
        </div>
        <div class="col-md-6 col-xl-3">
            <a href="tco_report.php" class="card report-card shadow-sm border-0 h-100 text-decoration-none text-dark">
                <div class="card-body">
                    <div class="icon-wrap mb-3"><i class="bi bi-cash-stack"></i></div>
                    <h5 class="mb-2">TCO Report</h5>
                    <p class="text-muted mb-0">Total Cost of Ownership — fuel costs broken down per vehicle.</p>
                </div>
            </a>
        </div>
        <?php endif; ?>
    </div>
</div>
</main>

<?php include 'views/layouts/footer.php'; ?>
