import { api } from '../../lib/api.mjs'; import { toLocalDatetime } from '../../lib/format.mjs'; const STATUSES = ['draft','assigned','scheduled','in_progress','pending_review','closed']; const PRI_COLOR = { low:'var(--priority-low)', normal:'var(--priority-normal)', high:'var(--priority-high)', urgent:'var(--priority-urgent)' }; class WoForm extends HTMLElement { #woId = null; #wo = null; #dirty = false; static get observedAttributes() { return ['wo-id']; } attributeChangedCallback(_, __, val) { this.#woId = val ? +val : null; if (this.shadowRoot) this.#load(); } connectedCallback() { this.attachShadow({ mode: 'open' }); this.#render(); if (this.#woId) this.#load(); } async #load() { if (!this.#woId) return; try { this.#wo = await api.get(`/work-orders/${this.#woId}`); } catch { /* ignore */ } this.#render(); } #render() { const wo = this.#wo || {}; const isNew = !this.#woId; const s = this.shadowRoot; s.innerHTML = `${this.#html(wo, isNew)}`; this.#bind(); if (window.lucide) lucide.createIcons({ nodes: [s] }); } #css() { return ` :host { display: block; } .page-header { display:flex; align-items:center; gap:1rem; margin-bottom:1.25rem; } .back-btn { background:none; border:1px solid var(--border); color:var(--text); border-radius:var(--radius); padding:.4rem .75rem; font-size:.813rem; font-weight:500; cursor:pointer; display:flex; align-items:center; gap:.3rem; transition:background .15s; } .back-btn:hover { background:var(--surface-2); } h1 { font-size:1.25rem; font-weight:700; color:var(--text); } .layout { display:grid; grid-template-columns:2fr 1fr; gap:1.5rem; align-items:start; } .card { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:1.25rem; display:flex; flex-direction:column; gap:1rem; box-shadow:var(--shadow-sm); } .card-title { font-size:.813rem; font-weight:700; color:var(--text-muted); text-transform:uppercase; letter-spacing:.06em; padding-bottom:.75rem; border-bottom:1px solid var(--border); } label { display:flex; flex-direction:column; gap:.3rem; font-size:.813rem; font-weight:600; color:var(--text); } input, select, textarea { border:1px solid var(--border); border-radius:var(--radius-sm); padding:.5rem .75rem; background:var(--surface); color:var(--text); font-size:.875rem; width:100%; transition:border-color .15s,box-shadow .15s; color-scheme:inherit; } input:focus, select:focus, textarea:focus { outline:none; border-color:var(--teal); box-shadow:0 0 0 3px rgba(10,126,164,.15); } textarea { resize:vertical; min-height:80px; line-height:1.6; font-family:inherit; } .row2 { display:grid; grid-template-columns:1fr 1fr; gap:1rem; } select { appearance:none; cursor:pointer; background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat:no-repeat; background-position:right .6rem center; padding-right:2rem; } .priority-select-wrap { position:relative; } .pri-dot { width:8px; height:8px; border-radius:50%; position:absolute; left:.75rem; top:50%; transform:translateY(-50%); pointer-events:none; } .priority-select { padding-left:1.75rem; } .footer { display:flex; justify-content:flex-end; gap:.75rem; margin-top:.5rem; } .btn { display:inline-flex; align-items:center; gap:.4rem; padding:.5rem 1rem; border:none; border-radius:var(--radius); font-size:.875rem; font-weight:600; cursor:pointer; transition:opacity .15s; } .btn-primary { background:var(--teal); color:#fff; } .btn-primary:hover { opacity:.88; } .btn-ghost { background:transparent; border:1px solid var(--border); color:var(--text); } .btn-ghost:hover { background:var(--surface-2); } .btn:disabled { opacity:.5; cursor:not-allowed; } .err { color:var(--danger); font-size:.813rem; text-align:right; } @media (max-width:768px) { .layout { grid-template-columns:1fr; } .row2 { grid-template-columns:1fr; } } `; } #html(wo, isNew) { const v = (field, fallback = '') => this.#esc(wo[field] ?? fallback); return `