@php $workspace = session('workspace', 'ha'); @endphp

<ul class="navbar-nav active">

    {{-- ═══════════════════════════════════════════════════
         WORKSPACE SWITCHER — always visible
    ══════════════════════════════════════════════════════ --}}
    <li class="nav-item me-3 d-flex align-items-center">
        <div class="d-flex gap-1">
            @if(auth()->user()->canAccessWorkspace('ha'))
                <a href="{{ route('workspace.switch', 'ha') }}"
                   class="btn btn-sm {{ $workspace === 'ha' ? 'btn-primary' : 'btn-outline-secondary' }}">
                    HA
                </a>
            @endif
            @if(auth()->user()->canAccessWorkspace('pension'))
                <a href="{{ route('workspace.switch', 'pension') }}"
                   class="btn btn-sm {{ $workspace === 'pension' ? 'btn-warning' : 'btn-outline-secondary' }}">
                    CPF
                </a>
            @endif
            @if(auth()->user()->canAccessWorkspace('wills'))
                <a href="{{ route('workspace.switch', 'wills') }}"
                   class="btn btn-sm {{ $workspace === 'wills' ? 'btn-success' : 'btn-outline-secondary' }}">
                    W&amp;T
                </a>
            @endif
        </div>
    </li>

    {{-- ═══════════════════════════════════════════════════
         SHARED — Dashboard & Task Hub
    ══════════════════════════════════════════════════════ --}}
    @can('dashboard.view')
        <li class="nav-item">
            <a class="nav-link" href="{{ route('dashboard') }}">
                <i class="uil-home-alt me-2"></i> Dashboard
            </a>
        </li>
    @endcan

    @can('tasks.admin')
        <li class="nav-item">
            <a class="nav-link" href="{{ route('task-hub.index') }}">
                <i class="uil-check-square me-2"></i> Task Hub
            </a>
        </li>
    @endcan

    {{-- ═══════════════════════════════════════════════════
         HA WORKSPACE
    ══════════════════════════════════════════════════════ --}}
    @if($workspace === 'ha')

        @can('reports.view')
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle arrow-none" role="button">
                    <i class="uil-chart-bar me-2"></i> Reports
                    <div class="arrow-down"></div>
                </a>
                <div class="dropdown-menu">
                    @can('reports.tranches.view')
                        <a href="{{ route('reports.tranche.index') }}" class="dropdown-item">Tranche Report</a>
                    @endcan
                    @can('reports.status')
                        <a href="{{ route('reports.status') }}" class="dropdown-item">Status Report</a>
                    @endcan
                    @can('reports.status.days')
                        <a href="{{ route('reports.status.days') }}" class="dropdown-item">Days In Status Report</a>
                    @endcan
                </div>
            </li>
        @endcan

        @can('tranches.view')
            <li class="nav-item">
                <a class="nav-link" href="{{ route('tranches.index') }}">
                    <i class="uil-layers me-2"></i> Tranches
                </a>
            </li>
        @endcan

        @can('clients.view')
            <li class="nav-item">
                <a class="nav-link" href="{{ route('ha-claims.index') }}">
                    <i class="uil-folder-medical me-2"></i> HA Claims
                </a>
            </li>
        @endcan


        @can('institutions.view')
            <li class="nav-item">
                <a class="nav-link" href="{{ route('institutions.index') }}">
                    <i class="uil-building me-2"></i> Institutions
                </a>
            </li>
        @endcan

        @can('sources.view')
            <li class="nav-item">
                <a class="nav-link" href="{{ route('sources.index') }}">
                    <i class="uil-share me-2"></i> Lead Sources
                </a>
            </li>
        @endcan

        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle arrow-none" href="" role="button">
                <i class="uil-envelope me-2"></i> DSARs
                <div class="arrow-down"></div>
            </a>
            <div class="dropdown-menu">
                @can('dsars.view')
                    <a href="{{ route('dsars.outstanding') }}" class="dropdown-item">Outstanding DSARs</a>
                @endcan
                @can('dsars.types.view')
                    <a href="{{ route('dsars.types') }}" class="dropdown-item">DSAR Types</a>
                @endcan
            </div>
        </li>

        @can('sources.view')
            <li class="nav-item">
                <a class="nav-link" href="{{ route('print-queue.index') }}">
                    <i class="uil-print me-2"></i> Print Queue
                </a>
            </li>
        @endcan

        {{-- HA Settings --}}
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle arrow-none" href="#" role="button">
                <i class="uil-setting me-2"></i> Settings
                <div class="arrow-down"></div>
            </a>
            <div class="dropdown-menu">
                <a href="{{ route('statuses.index') }}" class="dropdown-item">Claim Statuses</a>
                <a href="{{ route('tags.index') }}" class="dropdown-item">Tags</a>
                <a href="{{ route('doc-types.index') }}" class="dropdown-item">Document Types</a>
                <a href="{{ route('institution-types.index') }}" class="dropdown-item">Institution Types</a>
                <a href="{{ route('key-dates.index') }}" class="dropdown-item">Key Dates</a>
                <a href="{{ route('institution-record-types.index') }}" class="dropdown-item">Institution Record Types</a>
                <div class="dropdown-divider"></div>
                <a href="{{ route('settings.email-senders') }}" class="dropdown-item">Email Senders</a>
                <a href="{{ route('settings.phone-numbers') }}" class="dropdown-item">Phone Numbers</a>
            </div>
        </li>

    @endif

    {{-- ═══════════════════════════════════════════════════
         PENSION WORKSPACE
    ══════════════════════════════════════════════════════ --}}
    @if($workspace === 'pension')

        @can('pension-cases.view')
            <li class="nav-item">
                <a class="nav-link" href="{{ route('pension-cases.index') }}">
                    <i class="uil-briefcase me-2"></i> CPF Cases
                </a>
            </li>
        @endcan

        {{-- Pension Settings --}}
        @can('statuses.view')
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle arrow-none" href="#" role="button">
                    <i class="uil-setting me-2"></i> Settings
                    <div class="arrow-down"></div>
                </a>
                <div class="dropdown-menu">
                    <a href="{{ route('pension-statuses.index') }}" class="dropdown-item">CPF Statuses</a>
                </div>
            </li>
        @endcan


        @can('sources.view')
            <li class="nav-item">
                <a class="nav-link" href="{{ route('sources.index') }}">
                    <i class="uil-share me-2"></i> Lead Sources
                </a>
            </li>
        @endcan

    @endif

    {{-- ═══════════════════════════════════════════════════
         WILLS & TRUSTS WORKSPACE
    ══════════════════════════════════════════════════════ --}}
    @if($workspace === 'wills')

        @can('wills-cases.view')
            <li class="nav-item">
                <a class="nav-link" href="{{ route('wills-cases.index') }}">
                    <i class="uil-file-contract me-2"></i> Wills &amp; Trusts
                </a>
            </li>
        @endcan

    @endif

    {{-- ═══════════════════════════════════════════════════
         SHARED — Monitoring & Users (admin)
    ══════════════════════════════════════════════════════ --}}
    @can('monitoring.view')
        <li class="nav-item">
            <a class="nav-link" href="{{ route('monitoring.index') }}">
                <i class="uil-monitor me-2"></i> Monitoring
            </a>
        </li>
    @endcan

    @can('users.view')
        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle arrow-none" href="{{ route('admin.users.index') }}" role="button">
                <i class="uil-users-alt me-2"></i> Users
                <div class="arrow-down"></div>
            </a>
            <div class="dropdown-menu">
                @can('users.view')
                    <a href="{{ route('admin.users.index') }}" class="dropdown-item">Users</a>
                @endcan
                @can('roles.view')
                    <a href="{{ route('admin.roles.index') }}" class="dropdown-item">Roles</a>
                @endcan
                @can('permissions.view')
                    <a href="{{ route('admin.permissions.index') }}" class="dropdown-item">Permission Centre</a>
                @endcan
            </div>
        </li>
    @endcan

</ul>
