/** * @fileoverview Application Header Component for Rantii * @author retoor * @description Main navigation header with search and user controls * @keywords header, navigation, search, menu, toolbar */ import { BaseComponent } from './base-component.js'; class AppHeader extends BaseComponent { static get observedAttributes() { return ['logged-in']; } init() { this.render(); this.bindEvents(); } render() { const isLoggedIn = this.isLoggedIn(); const user = this.getCurrentUser(); this.setHtml(`
${isLoggedIn ? ` ` : ` `}
`); } bindEvents() { this.on(this, 'click', this.handleClick); this.on(this, 'submit', this.handleSubmit); const searchInput = this.$('.search-input'); if (searchInput) { this.on(searchInput, 'keydown', this.handleSearchKeydown); } window.addEventListener('rantii:auth-change', () => this.render()); } handleClick(e) { const target = e.target.closest('button, a'); if (!target) return; if (target.classList.contains('menu-toggle')) { e.preventDefault(); this.emit('menu-toggle'); } else if (target.classList.contains('logo') || target.closest('.logo')) { e.preventDefault(); this.getRouter()?.goHome(); } else if (target.classList.contains('search-btn')) { this.performSearch(); } else if (target.classList.contains('notifications-btn')) { this.getRouter()?.goToNotifications(); } else if (target.classList.contains('post-btn')) { this.emit('create-post'); } else if (target.classList.contains('user-btn')) { this.emit('user-menu'); } else if (target.classList.contains('login-btn')) { this.getRouter()?.goToLogin(); } else if (target.classList.contains('theme-btn')) { this.getTheme()?.toggleDarkLight(); } } handleSearchKeydown(e) { if (e.key === 'Enter') { e.preventDefault(); this.performSearch(); } } handleSubmit(e) { e.preventDefault(); } performSearch() { const input = this.$('.search-input'); if (input && input.value.trim()) { this.getRouter()?.goToSearch(input.value.trim()); } } setNotificationCount(count) { const badge = this.$('.notification-badge'); if (badge) { badge.textContent = count > 99 ? '99+' : count; badge.hidden = count === 0; } } clearSearch() { const input = this.$('.search-input'); if (input) { input.value = ''; } } } customElements.define('app-header', AppHeader); export { AppHeader };