class AuthModal extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = ` `; this.bindEvents(); } bindEvents() { const overlay = this.shadowRoot.querySelector('.modal-overlay'); const closeBtn = this.shadowRoot.querySelector('.close-btn'); const tabButtons = this.shadowRoot.querySelectorAll('.tab-button'); const loginForm = this.shadowRoot.getElementById('login-form'); const signupForm = this.shadowRoot.getElementById('signup-form'); // Close modal closeBtn.addEventListener('click', () => this.hide()); overlay.addEventListener('click', (e) => { if (e.target === overlay) this.hide(); }); // Tab switching tabButtons.forEach(btn => { btn.addEventListener('click', () => { tabButtons.forEach(b => b.classList.remove('active')); btn.classList.add('active'); if (btn.dataset.tab === 'login') { loginForm.classList.remove('hidden'); signupForm.classList.add('hidden'); } else { loginForm.classList.add('hidden'); signupForm.classList.remove('hidden'); } }); }); // Form submissions loginForm.addEventListener('submit', (e) => this.handleLogin(e)); signupForm.addEventListener('submit', (e) => this.handleSignup(e)); } show() { this.shadowRoot.querySelector('.modal-overlay').classList.remove('hidden'); } hide() { this.shadowRoot.querySelector('.modal-overlay').classList.add('hidden'); } handleLogin(e) { e.preventDefault(); // Implement login logic this.hide(); } handleSignup(e) { e.preventDefault(); // Implement signup logic this.hide(); } } customElements.define('auth-modal', AuthModal);