import { IEventBus } from '../types/CalendarTypes'; import { CoreEvents } from '../constants/CoreEvents'; /** * NavigationButtonsManager - Manages navigation button UI and state * * RESPONSIBILITY: * =============== * This manager owns all logic related to the UI element. * It follows the principle that each functional UI element has its own manager. * * RESPONSIBILITIES: * - Handles button clicks on swp-nav-button elements * - Validates navigation actions (prev, next, today) * - Emits NAV_BUTTON_CLICKED events * - Manages button UI listeners * * EVENT FLOW: * =========== * User clicks button → validateAction() → emit event → NavigationManager handles navigation * * SUBSCRIBERS: * ============ * - NavigationManager: Performs actual navigation logic (animations, grid updates, week calculations) */ export class NavigationButtons { private eventBus: IEventBus; private buttonListeners: Map = new Map(); constructor(eventBus: IEventBus) { this.eventBus = eventBus; this.setupButtonListeners(); } /** * Setup click listeners on all navigation buttons */ private setupButtonListeners(): void { const buttons = document.querySelectorAll('swp-nav-button[data-action]'); buttons.forEach(button => { const clickHandler = (event: Event) => { event.preventDefault(); const action = button.getAttribute('data-action'); if (action && this.isValidAction(action)) { this.handleNavigation(action); } }; button.addEventListener('click', clickHandler); this.buttonListeners.set(button, clickHandler); }); } /** * Handle navigation action */ private handleNavigation(action: string): void { // Emit navigation button clicked event this.eventBus.emit(CoreEvents.NAV_BUTTON_CLICKED, { action: action }); } /** * Validate if string is a valid navigation action */ private isValidAction(action: string): boolean { return ['prev', 'next', 'today'].includes(action); } }