<?php
$biPages = [
    'reports/bi'              => ['icon' => 'bi-speedometer2',      'label' => 'Overview'],
    'reports/bi/revenue'      => ['icon' => 'bi-graph-up-arrow',    'label' => 'Revenue'],
    'reports/bi/category'     => ['icon' => 'bi-grid-fill',         'label' => 'Categories'],
    'reports/bi/peak-hours'   => ['icon' => 'bi-clock-history',     'label' => 'Peak Hours'],
    'reports/bi/cancellations'=> ['icon' => 'bi-x-circle-fill',     'label' => 'Cancellations'],
    'reports/bi/riders'       => ['icon' => 'bi-bicycle',           'label' => 'Riders'],
    'reports/bi/retention'    => ['icon' => 'bi-arrow-repeat',      'label' => 'Retention'],
];
$currentPath = ltrim(parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH), '/');
$base        = ltrim(rtrim(parse_url(APP_URL, PHP_URL_PATH), '/'), '/');
$currentPath = ltrim(str_replace($base, '', '/' . $currentPath), '/');
?>
<div class="d-flex align-items-center justify-content-between mb-3 flex-wrap gap-2">
    <div class="d-flex align-items-center gap-2 flex-wrap">
        <div class="btn-group flex-wrap" role="group">
            <?php foreach ($biPages as $path => $info): ?>
            <a href="<?= url($path) ?>?from=<?= $from ?? date('Y-m-01') ?>&to=<?= $to ?? date('Y-m-d') ?>"
               class="btn btn-sm <?= str_starts_with($currentPath, explode('?', $path)[0]) ? 'btn-dark' : 'btn-outline-secondary' ?>">
                <i class="<?= $info['icon'] ?> me-1"></i><?= $info['label'] ?>
            </a>
            <?php endforeach ?>
        </div>
    </div>
    <!-- Date range filter -->
    <form method="GET" class="d-flex align-items-center gap-2">
        <input type="date" name="from" class="form-control form-control-sm" value="<?= $from ?? date('Y-m-01') ?>">
        <span class="text-muted small">to</span>
        <input type="date" name="to"   class="form-control form-control-sm" value="<?= $to ?? date('Y-m-d') ?>">
        <button class="btn btn-sm btn-primary"><i class="bi bi-funnel"></i></button>
    </form>
</div>
