import { Injectable, signal } from '@angular/core'; import { UrlStateService } from './url-state.service'; export type SidebarSection = 'quick' | 'folders' | 'tags' | 'ai' | null; @Injectable({ providedIn: 'root' }) export class SidebarStateService { private openSectionSig = signal(null); constructor(private url: UrlStateService) {} openSection() { return this.openSectionSig(); } /** * Ouvre une section du sidebar. Pour 'ai', ne pas réinitialiser les filtres ni la recherche. */ open(section: Exclude) { const prev = this.openSectionSig(); if (prev !== section) { this.openSectionSig.set(section); } // Réinitialiser uniquement pour les sections de navigation principales if (section === 'quick' || section === 'folders' || section === 'tags') { this.url.showAllAndReset(); } } /** * Bascule l'ouverture de la section AI sans impacter la liste de notes. */ toggleAISection(): void { const curr = this.openSectionSig(); this.openSectionSig.set(curr === 'ai' ? null : 'ai'); } }