export class ToastNotification extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = `
`; } connectedCallback() { // Ensure variables are defined, fallback if not if (!this.style.getPropertyValue('--primary-color')) { this.style.setProperty('--primary-color', '#003399'); this.style.setProperty('--secondary-color', '#CC0000'); this.style.setProperty('--accent-color', '#FFFFFF'); this.style.setProperty('--font-family', 'sans-serif'); } } show(message, type = 'info', duration = 3000) { const messageDiv = this.shadowRoot.getElementById('message'); messageDiv.textContent = message; this.className = ''; // Clear previous classes this.classList.add('show'); if (type === 'error') { this.classList.add('error'); } else if (type === 'success') { this.classList.add('success'); } setTimeout(() => { this.classList.remove('show'); this.classList.add('hide'); // Remove element after transition this.addEventListener('transitionend', () => this.remove(), { once: true }); }, duration); } } customElements.define('toast-notification', ToastNotification);