class StatusBar extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); this.currentTimeout = null; } connectedCallback() { this.render(); } render() { this.shadowRoot.innerHTML = `
`; } show(type, message, duration = 3000, actionText = null, actionCallback = null) { const statusBar = this.shadowRoot.getElementById('statusBar'); const statusText = this.shadowRoot.querySelector('.status-text'); const statusIcon = this.shadowRoot.querySelector('.status-icon'); const statusAction = this.shadowRoot.getElementById('statusAction'); // Clear any existing timeout if (this.currentTimeout) { clearTimeout(this.currentTimeout); } // Reset classes statusBar.className = 'status-bar'; // Set type-specific content switch (type) { case 'success': statusBar.classList.add('success'); statusIcon.innerHTML = ''; break; case 'error': statusBar.classList.add('error'); statusIcon.innerHTML = ''; break; case 'loading': statusBar.classList.add('loading'); statusIcon.innerHTML = ''; break; } // Set message statusText.textContent = message; // Handle action button if (actionText && actionCallback) { statusAction.textContent = actionText; statusAction.classList.remove('hidden'); statusAction.onclick = actionCallback; } else { statusAction.classList.add('hidden'); statusAction.onclick = null; } // Show status bar setTimeout(() => { statusBar.classList.add('visible'); }, 10); // Auto-hide after duration (except for loading) if (type !== 'loading' && duration > 0) { this.currentTimeout = setTimeout(() => { this.hide(); }, duration); } } hide() { const statusBar = this.shadowRoot.getElementById('statusBar'); statusBar.classList.remove('visible'); // Clear timeout if (this.currentTimeout) { clearTimeout(this.currentTimeout); this.currentTimeout = null; } } // Method to show success message success(message, duration = 3000) { this.show('success', message, duration); } // Method to show error message with retry error(message, retryCallback = null) { this.show('error', message, 5000, 'Retry', retryCallback); } // Method to show loading loading(message = 'Connecting...') { this.show('loading', message, 0); } } customElements.define('status-bar', StatusBar);