<?php
require_once __DIR__ . '/../../includes/bootstrap.php';
require_login();

$pageTitle = 'Reports Dashboard';

if (!function_exists('h')) {
    function h($value): string
    {
        return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
    }
}

$today = date('Y-m-d');
$monthStart = date('Y-m-01');

$reports = [
        [
            'title' => 'Executive Dashboard',
            'subtitle' => 'Live KPIs: revenue, occupancy, ADR, RevPAR, payments, arrivals and debtor exposure.',
            'icon' => 'bi-stars',
            'color' => 'dark',
            'href' => 'executive_dashboard.php',
            'badge' => 'Executive',
        ], 
        [
            'title' => 'Forecast Report',
            'subtitle' => 'Predict occupancy, rooms left, expected room revenue, ADR, RevPAR and booking pickup for future dates.',
            'icon' => 'bi-stars',
            'color' => 'dark',
            'href' => 'forecast_report.php',
            'badge' => 'Forecast',
        ],        
    [
        'title' => 'Revenue Report',
        'subtitle' => 'Room revenue, extras revenue, payments, balances and transaction detail.',
        'icon' => 'bi-graph-up-arrow',
        'color' => 'success',
        'href' => 'revenue_report.php?date_from=' . urlencode($monthStart) . '&date_to=' . urlencode($today),
        'badge' => 'Finance',
    ],
    [
        'title' => 'Extras / Services Report',
        'subtitle' => 'Analyse service categories, extras, quantities, unmatched services and revenue.',
        'icon' => 'bi-bag-plus',
        'color' => 'warning',
        'href' => 'extras_report.php?date_from=' . urlencode($monthStart) . '&date_to=' . urlencode($today),
        'badge' => 'Extras',
    ],
    [
        'title' => 'Payments Report',
        'subtitle' => 'Daily reconciliation, payment methods, currencies, voids and receipts.',
        'icon' => 'bi-cash-stack',
        'color' => 'primary',
        'href' => 'payments_report.php?date_from=' . urlencode($monthStart) . '&date_to=' . urlencode($today),
        'badge' => 'Cash Control',
    ],
    [
        'title' => 'Outstanding Balances',
        'subtitle' => 'Debtors, folio balances, aging buckets, agent and property exposure.',
        'icon' => 'bi-wallet2',
        'color' => 'danger',
        'href' => 'outstanding_report.php?as_at=' . urlencode($today),
        'badge' => 'Debtors',
    ],
[
    'title' => 'Operations Alerts',
    'subtitle' => 'Unpaid departures, overbooking risk, unassigned rooms, debtor alerts.',
    'icon' => 'bi-shield-exclamation',
    'color' => 'danger',
    'href' => 'alerts.php?date=' . date('Y-m-d'),
    'badge' => 'Operations',
],    
    [
        'title' => 'Occupancy Report',
        'subtitle' => 'Occupied rooms, available rooms, occupancy percentage and room type performance.',
        'icon' => 'bi-calendar3',
        'color' => 'info',
        'href' => 'occupancy_report.php?date_from=' . urlencode($monthStart) . '&date_to=' . urlencode($today),
        'badge' => 'Rooms',
    ],
    [
        'title' => 'ADR / RevPAR Report',
        'subtitle' => 'Room revenue performance, ADR, RevPAR, occupancy and room nights.',
        'icon' => 'bi-speedometer2',
        'color' => 'secondary',
        'href' => 'adr_revpar_report.php?date_from=' . urlencode($monthStart) . '&date_to=' . urlencode($today),
        'badge' => 'Performance',
    ],
    [
        'title' => 'Agent Production Report',
        'subtitle' => 'Agent bookings, revenue, extras, payments, outstanding and room nights.',
        'icon' => 'bi-people',
        'color' => 'primary',
        'href' => 'agent_production_report.php?date_from=' . urlencode($monthStart) . '&date_to=' . urlencode($today),
        'badge' => 'Sales',
    ],
    [
        'title' => 'Daily Manager / Night Audit',
        'subtitle' => 'Revenue today, payments, arrivals, departures, occupancy and alerts.',
        'icon' => 'bi-moon-stars',
        'color' => 'dark',
        'href' => 'daily_manager_report.php?report_date=' . urlencode($today),
        'badge' => 'Daily Control',
    ],
];

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

<div class="hero-band">
    <div class="row g-4 align-items-center">
        <div class="col-lg-8">
            <div class="page-eyebrow text-white-50">
                <i class="bi bi-bar-chart-line"></i> PMS Intelligence
            </div>
            <div class="hero-title mt-2">Reports Dashboard</div>
            <div class="hero-subtitle mt-2">
                A central reporting hub for revenue, payments, occupancy, agent production, night audit and management control.
            </div>
        </div>
        <div class="col-lg-4 text-lg-end">
            <a href="daily_manager_report.php?report_date=<?php echo h($today); ?>" class="btn btn-light me-2">
                <i class="bi bi-moon-stars me-2"></i>Today
            </a>
            <a href="/rooms/dashboard.php" class="btn btn-outline-light">
                <i class="bi bi-speedometer2 me-2"></i>Dashboard
            </a>
        </div>
    </div>
</div>

<div class="row g-4 mb-4">
    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-success-subtle text-success">
                <i class="bi bi-cash-coin"></i>
            </div>
            <div>
                <div class="metric-label">Finance</div>
                <div class="metric-value">Revenue</div>
            </div>
        </div>
    </div>

    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-primary-subtle text-primary">
                <i class="bi bi-house-check"></i>
            </div>
            <div>
                <div class="metric-label">Operations</div>
                <div class="metric-value">Occupancy</div>
            </div>
        </div>
    </div>

    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-warning-subtle text-warning">
                <i class="bi bi-bag-plus"></i>
            </div>
            <div>
                <div class="metric-label">Ancillary</div>
                <div class="metric-value">Extras</div>
            </div>
        </div>
    </div>

    <div class="col-md-6 col-xl-3">
        <div class="metric-card">
            <div class="metric-icon bg-danger-subtle text-danger">
                <i class="bi bi-exclamation-circle"></i>
            </div>
            <div>
                <div class="metric-label">Control</div>
                <div class="metric-value">Debtors</div>
            </div>
        </div>
    </div>
</div>

<div class="row g-4">
    <?php foreach ($reports as $report): ?>
        <div class="col-md-6 col-xl-3">
            <a href="<?php echo h($report['href']); ?>" class="text-decoration-none">
                <div class="report-card h-100">
                    <div class="report-card-top">
                        <div class="report-icon bg-<?php echo h($report['color']); ?>-subtle text-<?php echo h($report['color']); ?>">
                            <i class="bi <?php echo h($report['icon']); ?>"></i>
                        </div>
                        <span class="badge text-bg-light border"><?php echo h($report['badge']); ?></span>
                    </div>

                    <div class="report-card-body">
                        <h5><?php echo h($report['title']); ?></h5>
                        <p><?php echo h($report['subtitle']); ?></p>
                    </div>

                    <div class="report-card-footer">
                        <span>Open report</span>
                        <i class="bi bi-arrow-right"></i>
                    </div>
                </div>
            </a>
        </div>
    <?php endforeach; ?>
</div>

<style>
.report-card {
    background: #fff;
    border: 1px solid rgba(15, 23, 42, .08);
    border-radius: 24px;
    padding: 20px;
    box-shadow: 0 14px 35px rgba(15, 23, 42, .06);
    transition: all .2s ease;
    display: flex;
    flex-direction: column;
    min-height: 235px;
}
.report-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 22px 48px rgba(15, 23, 42, .10);
    border-color: rgba(15, 118, 110, .25);
}
.report-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 22px;
}
.report-icon {
    width: 54px;
    height: 54px;
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}
.report-card-body h5 {
    font-weight: 850;
    color: #111827;
    margin: 0 0 10px;
}
.report-card-body p {
    color: #64748b;
    font-size: 13px;
    line-height: 1.55;
    margin: 0;
}
.report-card-footer {
    margin-top: auto;
    padding-top: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--brand, #0f766e);
    font-weight: 800;
    font-size: 13px;
}
.report-card-footer i {
    transition: transform .2s ease;
}
.report-card:hover .report-card-footer i {
    transform: translateX(4px);
}
</style>

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