<?php
/** @var array<string,bool> $capabilities */
$isArTabs = current_lang() === 'ar';
$tabTr = static function (string $en, string $ar) use ($isArTabs): string { return $isArTabs ? $ar : $en; };

if (\App\Services\DiarWorkspaceNavigation::isPremiumPage((string)($activePage ?? ''))) { // DIAR_6B_2_R3_1_NO_HORIZONTAL_TABS
    return;
}

$diarWorkspaceModules = \App\Services\DiarWorkspaceNavigation::modules((string)($activePage ?? ''));
if ($diarWorkspaceModules !== []): // DIAR_6B_2_R2_ROLE_NAV
?>
<link rel="stylesheet" href="assets/css/diar-workspace.css?v=diar-6b-2-r2">
<nav class="diar-workspace-nav" aria-label="<?= e($tabTr('DIAR sections', 'أقسام DIAR')) ?>">
    <?php foreach ($diarWorkspaceModules as $workspaceModule): ?>
        <a class="<?= !empty($workspaceModule['active']) ? 'active' : '' ?>" href="<?= e(url_to((string)$workspaceModule['route'])) ?>">
            <span class="nav-icon"><?= e((string)$workspaceModule['icon']) ?></span>
            <strong><?= e((string)$workspaceModule['short_label']) ?></strong>
            <small><?= e((string)$workspaceModule['status']) ?></small>
        </a>
    <?php endforeach; ?>
</nav>
<?php
return;
endif;

$tabs = [
    ['page' => 'diar-executive-overview', 'label' => $tabTr('Executive Overview', 'النظرة التنفيذية'), 'meta' => $tabTr('Monthly', 'شهري'), 'tone' => 'live', 'visible' => (bool)($capabilities['command'] ?? false)], // DIAR_6B_1_COMPAT_TAB_R1_1
    ['page' => 'diar-command-center', 'label' => $tabTr('Overview', 'النظرة العامة'), 'meta' => $tabTr('Start here', 'ابدأ هنا'), 'tone' => 'live', 'visible' => (bool)($capabilities['command'] ?? false), 'step' => '1'],
    ['page' => 'diar-statistical-profiles', 'label' => $tabTr('Statistical baselines', 'الأنماط المتوقعة للحركة'), 'meta' => $tabTr('Normal behaviour', 'السلوك الطبيعي'), 'tone' => 'profile', 'visible' => (bool)($capabilities['profiles'] ?? false), 'step' => '2'],
    ['page' => 'diar-anomaly-candidates', 'label' => $tabTr('Detected deviations', 'الحركات غير المعتادة'), 'meta' => $tabTr('Compare', 'المقارنة'), 'tone' => 'prepared', 'visible' => (bool)($capabilities['candidates'] ?? false), 'step' => '3'],
    ['page' => 'diar-investigations', 'label' => $tabTr('Investigation cases', 'قضايا التحقيق'), 'meta' => $tabTr('Review', 'المراجعة'), 'tone' => 'review', 'visible' => (bool)($capabilities['investigations'] ?? false), 'step' => '4'],
    ['page' => 'diar-rules', 'label' => $tabTr('Review policy', 'سياسة المراجعة'), 'meta' => $tabTr('Governance', 'الحوكمة'), 'tone' => 'governance', 'visible' => (bool)($capabilities['rules'] ?? false), 'step' => '5'],
];
?>
<nav class="diar-module-tabs diar-workflow-tabs" aria-label="<?= e($tabTr('Medication movement intelligence workflow', 'مسار ذكاء حركات مخزون الأدوية')) ?>">
    <?php foreach ($tabs as $tab): if (!$tab['visible']) { continue; } ?>
        <a class="<?= ($activePage ?? '') === $tab['page'] ? 'active' : '' ?>" href="<?= e(url_to($tab['page'])) ?>">
            <b class="workflow-tab-step"><?= e($tab['step']) ?></b>
            <span><?= e($tab['label']) ?></span>
            <small class="tab-meta tab-meta-<?= e($tab['tone']) ?>"><?= e($tab['meta']) ?></small>
        </a>
    <?php endforeach; ?>
</nav>
