import { Component, inject, signal, effect } from '@angular/core'; import { RouterOutlet, RouterLink, RouterLinkActive } from '@angular/router'; import { AuthService } from '../../services/auth.service'; import { MailService } from '../../services/mail.service'; import { Folder } from '../../models/mail.models'; const THEMES = [ { value: 'theme-cyber-magenta', label: '💖 Cyber Magenta' }, { value: 'theme-neon-cyan', label: '🩵 Neon Cyan' }, { value: 'theme-sunset-orange', label: '🧡 Sunset Orange' }, { value: 'theme-matrix-green', label: '💚 Matrix Green' }, ]; @Component({ selector: 'app-layout', standalone: true, imports: [RouterOutlet, RouterLink, RouterLinkActive], template: `
M

MAILSERVER

Synthwave Edition

SMTP: ONLINE
|
User: {{ email }}
|
Folders: {{ folders().length }}
`, styles: `` }) export default class LayoutComponent { authService = inject(AuthService); mailService = inject(MailService); email = this.authService.getEmail() || ''; folders = signal([]); isLightTheme = signal(false); isHighContrast = signal(false); currentTheme = signal('theme-cyber-magenta'); themes = THEMES; constructor() { this.loadFolders(); // Загружаем сохранённые настройки const savedTheme = localStorage.getItem('theme'); if (savedTheme === 'light') { this.isLightTheme.set(true); } const savedPalette = localStorage.getItem('palette'); if (savedPalette) { this.currentTheme.set(savedPalette); } const savedContrast = localStorage.getItem('highContrast'); if (savedContrast === 'true') { this.isHighContrast.set(true); } // Применяем тему при изменении effect(() => { const root = document.documentElement; // Удаляем все theme классы THEMES.forEach(t => root.classList.remove(t.value)); root.classList.add(this.currentTheme()); }); } onThemeChange(theme: string): void { this.currentTheme.set(theme); localStorage.setItem('palette', theme); } toggleTheme(): void { const isLight = !this.isLightTheme(); this.isLightTheme.set(isLight); if (isLight) { document.documentElement.classList.add('light-theme'); localStorage.setItem('theme', 'light'); } else { document.documentElement.classList.remove('light-theme'); localStorage.setItem('theme', 'dark'); } } toggleHighContrast(): void { const hc = !this.isHighContrast(); this.isHighContrast.set(hc); if (hc) { document.documentElement.classList.add('high-contrast'); localStorage.setItem('highContrast', 'true'); } else { document.documentElement.classList.remove('high-contrast'); localStorage.setItem('highContrast', 'false'); } } loadFolders(): void { this.mailService.getFolders().subscribe({ next: (folders) => this.folders.set(folders), error: () => console.error('Failed to load folders') }); } onLogout(): void { this.authService.logout(); window.location.href = '/login'; } }