<?php
// pwa/components/pwa_nav.php
// Outputs the top bar + optional bottom nav
// Call: pwa_nav($user)

if (!function_exists('pwa_nav')) {
    function pwa_nav($user = [])
    {
        $role = $user['role'] ?? 'solar';
        $page = $user['page'] ?? 'dashboard'; // optional: can be set per-page

        $roleTitleMap = [
            'solar'     => 'SolarDoot',
            'captain'   => 'Captain',
            'statehead' => 'State Head',
        ];

        $pageTitleMap = [
            'dashboard' => 'Dashboard',
            'customers' => 'Customers',
            'followups' => 'Follow-ups',
            'tasks'     => 'Tasks',
            'settings'  => 'Settings',
        ];

        $roleLabel = $roleTitleMap[$role] ?? 'SolarDoot';
        $pageLabel = $pageTitleMap[$page] ?? 'Dashboard';
        $teamName  = htmlspecialchars($_SESSION['team']['full_name'] ?? 'Team');

        ?>
        <!-- PWA Top Header -->
        <header class="pwa-topbar" data-role="<?= htmlspecialchars($role) ?>">
            <div class="pwa-header-left">
                <div class="pwa-logo">
                    <img src="/assets/logos/Atulya_Logo.png" alt="Logo" class="pwa-logo">
                </div>
                <div class="pwa-header-text">
                    <div class="pwa-app-name"><?= $teamName ?> CRM</div>
                    <div class="pwa-role-name"><?= htmlspecialchars($roleLabel) ?></div>
                </div>
            </div>
            <div class="pwa-header-right">
                <span class="pwa-page-title"><?= htmlspecialchars($pageLabel) ?></span>
            </div>
        </header>
        <?php
    }
}
