class CustomApiKeyModal extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); } static get observedAttributes() { return ['open']; } attributeChangedCallback(name, oldValue, newValue) { if (name === 'open') { this.render(); } } connectedCallback() { this.render(); } render() { const isOpen = this.hasAttribute('open'); this.shadowRoot.innerHTML = ` `; if (isOpen) { setTimeout(() => { const apiKeyInput = this.shadowRoot.getElementById('api-key-input'); const cancelButton = this.shadowRoot.getElementById('cancel-button'); const saveButton = this.shadowRoot.getElementById('save-button'); // Load saved key if exists const savedKey = localStorage.getItem('deepseek_api_key'); if (savedKey) { apiKeyInput.value = savedKey; } cancelButton.addEventListener('click', () => { this.removeAttribute('open'); }); saveButton.addEventListener('click', () => { const apiKey = apiKeyInput.value.trim(); if (apiKey) { localStorage.setItem('deepseek_api_key', apiKey); this.removeAttribute('open'); } }); // Focus input when modal opens apiKeyInput.focus(); }, 0); } } } customElements.define('custom-api-key-modal', CustomApiKeyModal);