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

$userName = $_SESSION['user_name'] ?? 'User';
$page_js = 'driver_age_compliance.js';

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="row g-3 mb-4">
        <div class="col-12 col-md-6 col-xl-3">
            <div class="card kpi-card shadow-sm border-0 h-100">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="kpi-label">Total Drivers</div>
                            <div class="kpi-value" id="kpiTotalDrivers">0</div>
                        </div>
                        <div class="kpi-icon text-primary">
                            <i class="bi bi-people"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-12 col-md-6 col-xl-3">
            <div class="card kpi-card shadow-sm border-0 h-100">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="kpi-label">Compliant</div>
                            <div class="kpi-value" id="kpiCompliant">0</div>
                        </div>
                        <div class="kpi-icon text-success">
                            <i class="bi bi-check-circle"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-12 col-md-6 col-xl-3">
            <div class="card kpi-card shadow-sm border-0 h-100">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="kpi-label">Non-Compliant</div>
                            <div class="kpi-value" id="kpiNonCompliant">0</div>
                        </div>
                        <div class="kpi-icon text-danger">
                            <i class="bi bi-exclamation-triangle"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-12 col-md-6 col-xl-3">
            <div class="card kpi-card shadow-sm border-0 h-100">
                <div class="card-body">
                    <div class="d-flex justify-content-between align-items-center">
                        <div>
                            <div class="kpi-label">Average Age</div>
                            <div class="kpi-value" id="kpiAverageAge">0</div>
                        </div>
                        <div class="kpi-icon text-info">
                            <i class="bi bi-bar-chart"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="card shadow-sm border-0">
        <div class="card-header bg-white d-flex flex-column flex-lg-row justify-content-between align-items-lg-center gap-3">
            <div>
                <h4 class="mb-1">Driver Age Compliance</h4>
                <p class="text-muted mb-0">Check driver's driving age against contractual agreements (minimum 18 years).</p>
            </div>
            <div class="d-flex flex-column flex-sm-row gap-2 w-100 w-lg-auto">
                <input type="text" id="searchDriver" class="form-control" placeholder="Search name or code">
                <button class="btn btn-outline-secondary" id="btnRefresh">Refresh</button>
                <button class="btn btn-primary" id="btnExport">Export Report</button>
            </div>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table align-middle table-hover">
                    <thead class="table-light">
                        <tr>
                            <th>Driver Code</th>
                            <th>Name</th>
                            <th>Date of Birth</th>
                            <th>Age</th>
                            <th>Compliance Status</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody id="complianceTable">
                        <tr>
                            <td colspan="6" class="text-center text-muted">Loading compliance data...</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

</main>

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