/** * @fileoverview Application Navigation Component for Rantii * @author retoor * @description Side navigation menu with main app sections * @keywords navigation, menu, sidebar, nav, links */ import { BaseComponent } from './base-component.js'; class AppNav extends BaseComponent { static get observedAttributes() { return ['active', 'expanded']; } init() { this.render(); this.bindEvents(); } render() { const active = this.getAttr('active') || 'home'; const isLoggedIn = this.isLoggedIn(); this.setHtml(` `); } bindEvents() { this.on(this, 'click', this.handleClick); window.addEventListener('rantii:auth-change', () => this.render()); window.addEventListener('rantii:route-change', (e) => { this.setAttr('active', e.detail.route); this.render(); }); } handleClick(e) { const link = e.target.closest('.nav-link'); if (!link) return; e.preventDefault(); const route = link.dataset.route; switch (route) { case 'home': this.getRouter()?.goHome(); break; case 'weekly': this.getRouter()?.goToWeekly(); break; case 'collabs': this.getRouter()?.goToCollabs(); break; case 'stories': this.getRouter()?.goToStories(); break; case 'search': this.getRouter()?.goToSearch(); break; case 'notifications': this.getRouter()?.goToNotifications(); break; case 'profile': const username = this.getCurrentUser()?.username; if (username) { this.getRouter()?.goToUser(username); } break; case 'settings': this.getRouter()?.goToSettings(); break; case 'login': this.getRouter()?.goToLogin(); break; case 'logout': this.getAuth()?.logout(); this.getRouter()?.goHome(); break; } this.emit('nav-click', { route }); } setActive(route) { this.setAttr('active', route); this.render(); } setNotificationBadge(count) { const badge = this.$('.nav-badge'); if (badge) { badge.textContent = count > 99 ? '99+' : count; badge.hidden = count === 0; } } expand() { this.setAttr('expanded', ''); } collapse() { this.removeAttribute('expanded'); } toggle() { if (this.hasAttr('expanded')) { this.collapse(); } else { this.expand(); } } } customElements.define('app-nav', AppNav); export { AppNav };