import { api } from '../lib/api.mjs'; class WoList extends HTMLElement { #data = []; connectedCallback() { this.attachShadow({ mode: 'open' }); this.#load(); } async #load() { const status = this.getAttribute('filter-status') || ''; this.#data = await api.get(`/work-orders?status=${status}`) ?? []; this.#render(); } refresh() { this.#load(); } #render() { this.shadowRoot.innerHTML = ` ${this.#data.length === 0 ? '
No work orders found.
' : `
${this.#data.map(wo => `
${wo.wo_number}
${wo.title}
${wo.site_name || '—'} · ${wo.steps_done}/${wo.step_count} steps
${wo.status.replace('_',' ')}
`).join('')}
`}`; this.shadowRoot.querySelectorAll('.card').forEach(c => c.addEventListener('click', () => this.dispatchEvent(new CustomEvent('wo:select', { detail: { id: +c.dataset.id }, bubbles: true, composed: true })))); } } customElements.define('wo-list', WoList);