class Toolbar extends HTMLElement { constructor() { super(); this.attachShadow({ mode: 'open' }); } connectedCallback() { this.render(); this.addEventListeners(); } addEventListeners() { const searchBtn = this.shadowRoot.querySelector('.search-btn'); const resetBtn = this.shadowRoot.querySelector('.reset-btn'); const addBtn = this.shadowRoot.querySelector('.add-btn'); const deleteBtn = this.shadowRoot.querySelector('.delete-btn'); const downloadBtn = this.shadowRoot.querySelector('.download-btn'); const importBtn = this.shadowRoot.querySelector('.import-btn'); searchBtn.addEventListener('click', () => { const searchInput = this.shadowRoot.querySelector('.search-input'); this.dispatchEvent(new CustomEvent('search', { detail: { keyword: searchInput.value } })); }); resetBtn.addEventListener('click', () => { const searchInput = this.shadowRoot.querySelector('.search-input'); searchInput.value = ''; this.dispatchEvent(new CustomEvent('reset-search')); }); addBtn.addEventListener('click', () => { const form = document.querySelector('variable-form'); if (form) { form.setMode('add'); form.show(); } }); deleteBtn.addEventListener('click', () => { this.dispatchEvent(new CustomEvent('delete-selected')); }); downloadBtn.addEventListener('click', () => { this.dispatchEvent(new CustomEvent('download-template')); }); importBtn.addEventListener('click', () => { const fileInput = this.shadowRoot.querySelector('.file-input'); fileInput.click(); }); const fileInput = this.shadowRoot.querySelector('.file-input'); fileInput.addEventListener('change', (e) => { const file = e.target.files[0]; if (file) { this.dispatchEvent(new CustomEvent('import-data', { detail: { file } })); } }); } render() { this.shadowRoot.innerHTML = `
`; } } customElements.define('interface-toolbar', Toolbar);