<?php
/**
 * app/views/partials/sidebar.php
 *
 * Expects $activeNav (string key, e.g. 'users', 'roles', 'departments',
 * 'teams', 'profile', 'activity-logs', 'notifications') set by the
 * calling view. Markup/classes are ported verbatim from the completed
 * frontend's ab-hub templates (assets/css/style.css already defines
 * every class used here) — only the `active` state and nav visibility
 * (RBAC-gated) are dynamic.
 */
$nav = fn (string $key) => $activeNav === $key ? 'active' : '';
?>
<aside class="ab-sidebar">
  <div class="ab-sidebar-brand">
    <div class="ab-logo-mark">AB</div>
    <div class="ab-logo-text">A&amp;B Hub<small>Homecare &amp; Janitorial CRM</small></div>
  </div>
  <nav class="ab-sidebar-scroll">
    <div class="ab-nav-label">Workspace</div>
    <a href="<?= base_url('dashboard') ?>" class="ab-nav-link <?= $nav('dashboard') ?>"><i class="bi bi-grid-1x2-fill"></i><span>Dashboard</span></a>

    <?php if (\App\Core\Rbac::can('leads_customers.view')): ?>
    <div class="ab-nav-label">CRM</div>
    <a href="<?= base_url('leads') ?>" class="ab-nav-link <?= $nav('leads') ?>"><i class="bi bi-person-lines-fill"></i><span>Leads</span></a>
    <a href="<?= base_url('customers') ?>" class="ab-nav-link <?= $nav('customers') ?>"><i class="bi bi-people-fill"></i><span>Customers</span></a>
    <a href="<?= base_url('companies') ?>" class="ab-nav-link <?= $nav('companies') ?>"><i class="bi bi-building"></i><span>Companies</span></a>
    <?php if (\App\Core\Rbac::can('scheduling.view')): ?>
    <a href="<?= base_url('appointments') ?>" class="ab-nav-link <?= $nav('appointments') ?>"><i class="bi bi-calendar-week-fill"></i><span>Appointments</span></a>
    <?php endif; ?>
    <?php if (\App\Core\Rbac::can('leads_customers.manage')): ?>
    <a href="<?= base_url('services') ?>" class="ab-nav-link <?= $nav('services') ?>"><i class="bi bi-bag-check-fill"></i><span>Services</span></a>
    <a href="<?= base_url('lead-sources') ?>" class="ab-nav-link <?= $nav('lead-sources') ?>"><i class="bi bi-funnel-fill"></i><span>Lead Sources</span></a>
    <?php endif; ?>
    <?php endif; ?>

    <?php if (\App\Core\Rbac::can('email_campaigns.view')): ?>
    <div class="ab-nav-label">Marketing</div>
    <a href="<?= base_url('campaigns') ?>" class="ab-nav-link <?= $nav('campaigns') ?>"><i class="bi bi-megaphone-fill"></i><span>Campaigns</span></a>
    <a href="<?= base_url('email-templates') ?>" class="ab-nav-link <?= $nav('email-templates') ?>"><i class="bi bi-envelope-paper-fill"></i><span>Email Templates</span></a>
    <a href="<?= base_url('audience-segments') ?>" class="ab-nav-link <?= $nav('audience-segments') ?>"><i class="bi bi-people-fill"></i><span>Audience Segments</span></a>
    <?php if (\App\Core\Rbac::can('ai_automation.view')): ?>
    <a href="<?= base_url('automation') ?>" class="ab-nav-link <?= $nav('automation') ?>"><i class="bi bi-diagram-2-fill"></i><span>Automation</span></a>
    <?php endif; ?>
    <?php if (\App\Core\Rbac::can('email_campaigns.manage')): ?>
    <a href="<?= base_url('settings/smtp') ?>" class="ab-nav-link <?= $nav('marketing-settings') ?>"><i class="bi bi-gear-fill"></i><span>SMTP Settings</span></a>
    <a href="<?= base_url('settings/business-lines') ?>" class="ab-nav-link <?= $nav('business-line-settings') ?>"><i class="bi bi-building-gear"></i><span>Company Details</span></a>
    <?php endif; ?>
    <?php endif; ?>

    <?php if (\App\Core\Rbac::can('ai_automation.view')): ?>
    <div class="ab-nav-label">AI &amp; Automation</div>
    <a href="<?= base_url('ai-assistant') ?>" class="ab-nav-link <?= $nav('ai-assistant') ?>"><i class="bi bi-robot"></i><span>AI Assistant</span></a>
    <a href="<?= base_url('chatbot-settings') ?>" class="ab-nav-link <?= $nav('chatbot') ?>"><i class="bi bi-chat-dots-fill"></i><span>Website Chatbot</span></a>
    <a href="<?= base_url('voice-agent') ?>" class="ab-nav-link <?= $nav('voice-agent') ?>"><i class="bi bi-telephone-fill"></i><span>AI Voice Agent</span></a>
    <a href="<?= base_url('conversation-logs') ?>" class="ab-nav-link <?= $nav('conversation-logs') ?>"><i class="bi bi-chat-square-text-fill"></i><span>Conversation Logs</span></a>
    <a href="<?= base_url('knowledge-base') ?>" class="ab-nav-link <?= $nav('knowledge-base') ?>"><i class="bi bi-book-fill"></i><span>Knowledge Base</span></a>
    <a href="<?= base_url('ai-prompts') ?>" class="ab-nav-link <?= $nav('ai-prompts') ?>"><i class="bi bi-chat-square-dots"></i><span>Prompt Management</span></a>
    <a href="<?= base_url('training-data') ?>" class="ab-nav-link <?= $nav('training-data') ?>"><i class="bi bi-database-fill"></i><span>Training Data</span></a>
    <a href="<?= base_url('integrations') ?>" class="ab-nav-link <?= $nav('integrations') ?>"><i class="bi bi-plug-fill"></i><span>Integrations</span></a>
    <?php if (\App\Core\Rbac::can('user_management.manage')): ?>
    <a href="<?= base_url('api-keys') ?>" class="ab-nav-link <?= $nav('api-keys') ?>"><i class="bi bi-key-fill"></i><span>API Keys</span></a>
    <?php endif; ?>
    <a href="<?= base_url('reports') ?>" class="ab-nav-link <?= $nav('reports') ?>"><i class="bi bi-graph-up"></i><span>Reports</span></a>
    <?php endif; ?>

    <?php if (\App\Core\Rbac::can('user_management.view')): ?>
    <div class="ab-nav-label">Administration</div>
    <a href="<?= base_url('users') ?>" class="ab-nav-link <?= $nav('users') ?>"><i class="bi bi-people-fill"></i><span>Users</span></a>
    <a href="<?= base_url('roles') ?>" class="ab-nav-link <?= $nav('roles') ?>"><i class="bi bi-shield-lock-fill"></i><span>Roles &amp; Permissions</span></a>
    <a href="<?= base_url('departments') ?>" class="ab-nav-link <?= $nav('departments') ?>"><i class="bi bi-diagram-3-fill"></i><span>Departments</span></a>
    <a href="<?= base_url('teams') ?>" class="ab-nav-link <?= $nav('teams') ?>"><i class="bi bi-people"></i><span>Teams</span></a>
    <a href="<?= base_url('activity-logs') ?>" class="ab-nav-link <?= $nav('activity-logs') ?>"><i class="bi bi-clock-history"></i><span>Activity Logs</span></a>
    <?php endif; ?>

    <div class="ab-nav-label">Account</div>
    <a href="<?= base_url('profile') ?>" class="ab-nav-link <?= $nav('profile') ?>"><i class="bi bi-person-circle"></i><span>My Profile</span></a>
    <a href="<?= base_url('notifications') ?>" class="ab-nav-link <?= $nav('notifications') ?>"><i class="bi bi-bell-fill"></i><span>Notifications</span></a>
  </nav>
  <div class="ab-sidebar-footer">
    <div class="ab-footer-full"><i class="bi bi-shield-check me-1"></i>v2.4.0 &middot; Phase 2</div>
  </div>
</aside>
