2026-10-13 19:18:05 -05:00
|
|
|
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
|
|
|
|
|
import { RouterLink, RouterLinkActive, RouterOutlet } from '@angular/router';
|
2026-10-19 09:56:48 -05:00
|
|
|
import { AccountSegmentsService } from '../core/sl/account-segments';
|
2026-10-13 19:18:05 -05:00
|
|
|
import { AuthService } from '../core/auth/auth.service';
|
|
|
|
|
import { SessionStore } from '../core/auth/session.store';
|
|
|
|
|
import { MenuService } from '../core/menu/menu.service';
|
|
|
|
|
import { ThemeSwitcher } from '../core/theme/theme-switcher';
|
|
|
|
|
|
|
|
|
|
/** Marco de la aplicación: barra superior, menú lateral filtrado por permisos y contenido. */
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'sbo-main-layout',
|
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
|
|
imports: [RouterOutlet, RouterLink, RouterLinkActive, ThemeSwitcher],
|
|
|
|
|
templateUrl: './main-layout.html',
|
|
|
|
|
styleUrl: './main-layout.css',
|
|
|
|
|
})
|
|
|
|
|
export class MainLayout {
|
|
|
|
|
private readonly auth = inject(AuthService);
|
|
|
|
|
protected readonly session = inject(SessionStore);
|
|
|
|
|
protected readonly menu = inject(MenuService);
|
|
|
|
|
|
|
|
|
|
protected readonly sidebarOpen = signal(false);
|
2026-10-19 09:56:48 -05:00
|
|
|
private readonly segments = inject(AccountSegmentsService);
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
void this.segments.ensureLoaded();
|
|
|
|
|
}
|
2026-10-13 19:18:05 -05:00
|
|
|
private readonly collapsed = signal<ReadonlySet<string>>(new Set());
|
|
|
|
|
|
|
|
|
|
protected isOpen(moduleId: string): boolean {
|
|
|
|
|
return !this.collapsed().has(moduleId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected toggle(moduleId: string): void {
|
|
|
|
|
this.collapsed.update((s) => {
|
|
|
|
|
const next = new Set(s);
|
|
|
|
|
if (!next.delete(moduleId)) next.add(moduleId);
|
|
|
|
|
return next;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected retryMenu(): void {
|
|
|
|
|
void this.menu.ensureLoaded();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected logout(): void {
|
|
|
|
|
void this.auth.logout();
|
|
|
|
|
}
|
|
|
|
|
}
|