import { inject, Injectable, signal } from '@angular/core'; import EventService from './EventService'; @Injectable({ providedIn: 'root' }) export class ThemeService { private events = inject(EventService); private _current = signal<'light' | 'dark'>('dark'); get theme() { return this._current(); } set theme(value: 'light' | 'dark') { const previous = this._current(); if (previous == value) { return; } this._current.set(value); localStorage.setItem('ui-theme', value); this.events.emit('theme_change', { previous_theme: previous, current_theme: value, }); } isDarkTheme() { return this.theme == 'dark'; } isLightTheme() { return this.theme == 'light'; } toggle() { if (this.theme == 'light') { this.theme = 'dark'; } else { this.theme = 'light'; } } }