<?php
$accountUrl = accountUrl();
$accountName = currentUserDisplayName();
$accountTooltip = $accountName !== '' ? $accountName : t('Account');
$layoutAuth = is_array($viewAuth['layout'] ?? null) ? $viewAuth['layout'] : [];
$hasAdminPanel = layoutHasAdminPanel($layoutAuth);
?>
<aside class="aside-icon-bar" data-app-component="aside-panels" data-aside-storage="app-sidebar-panel">
    <nav aria-label="<?php e(t('Main menu')); ?>">
        <ul class="aside-icon-group" role="tablist" aria-orientation="vertical">
            <li>
                <button type="button" id="aside-tab-explorer" data-aside-target="explorer" role="tab"
                    aria-selected="true" aria-controls="aside-panel-explorer" aria-label="<?php e(t('Explorer')); ?>"
                    data-tooltip="<?php e(t('Explorer')); ?>" data-tooltip-pos="right" data-icon-swap>
                    <i class="bi bi-house" data-icon="outline"></i>
                    <i class="bi bi-house-fill" data-icon="fill"></i>
                </button>
            </li>
            <?php
            // ── Module-contributed aside tabs (aside.tab_panel slot) ──
            $moduleSlots = is_array($layoutNav['moduleSlots'] ?? null) ? $layoutNav['moduleSlots'] : [];
            $moduleTabSlots = is_array($moduleSlots['aside.tab_panel'] ?? null) ? $moduleSlots['aside.tab_panel'] : [];
            foreach ($moduleTabSlots as $slot):
                if (!is_array($slot)) { continue; }
                $slotKey = $slot['key'] ?? '';
                $slotLabel = $slot['label'] ?? '';
                $slotIcon = $slot['icon'] ?? 'bi-puzzle';
                $slotIconFill = $slot['icon_fill'] ?? ($slotIcon !== '' ? $slotIcon . '-fill' : 'bi-puzzle-fill');
                $slotHref = $slot['href'] ?? '';
                $slotPermission = $slot['permission'] ?? '';
                if ($slotPermission !== '' && empty($layoutAuth[$slotPermission])) { continue; }
                // Resolve relative route keys via lurl()
                if ($slotHref !== '' && !str_starts_with($slotHref, '/') && !str_starts_with($slotHref, 'http')) {
                    $slotHref = lurl($slotHref);
                }
            ?>
                <li>
                    <button type="button" id="aside-tab-<?php e($slotKey); ?>"
                        data-aside-target="<?php e($slotKey); ?>"
                        <?php if ($slotHref !== ''): ?>data-aside-href="<?php e($slotHref); ?>"<?php endif; ?>
                        role="tab" aria-selected="false"
                        aria-controls="aside-panel-<?php e($slotKey); ?>"
                        aria-label="<?php e(t($slotLabel)); ?>"
                        data-tooltip="<?php e(t($slotLabel)); ?>" data-tooltip-pos="right" data-icon-swap>
                        <i class="bi <?php e($slotIcon); ?>" data-icon="outline"></i>
                        <i class="bi <?php e($slotIconFill); ?>" data-icon="fill"></i>
                    </button>
                </li>
            <?php endforeach; ?>
        </ul>
        <div class="aside-icon-footer">
            <ul role="list">
                <li>
                    <a href="<?php e($accountUrl); ?>" aria-label="<?php e(t('Account')); ?>"
                        data-tooltip="<?php e($accountTooltip); ?>" data-tooltip-pos="right" data-aside-shortcut="account" data-icon-swap>
                        <i class="bi bi-person" data-icon="outline"></i>
                        <i class="bi bi-person-fill" data-icon="fill"></i>
                    </a>
                </li>
            </ul>
            <?php if ($hasAdminPanel): ?>
                <ul class="aside-icon-group" role="tablist" aria-orientation="vertical">
                    <li>
                        <button type="button" id="aside-tab-admin" data-aside-target="admin" role="tab" aria-selected="false"
                            aria-controls="aside-panel-admin" aria-label="<?php e(t('Admin')); ?>"
                            data-tooltip="<?php e(t('Admin')); ?>" data-tooltip-pos="right" data-icon-swap>
                            <i class="bi bi-gear" data-icon="outline"></i>
                            <i class="bi bi-gear-fill" data-icon="fill"></i>
                        </button>
                    </li>
                </ul>
            <?php endif; ?>
        </div>
    </nav>
</aside>
