bank20baht-ui 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4754 @@
1
+ import { nothing as h, html as n, svg as A } from "lit";
2
+ import { property as l, customElement as u, state as y, query as Et } from "lit/decorators.js";
3
+ import { B as $, b as ne, h as q, a as W } from "./base-CajA2aCO.js";
4
+ import { t as v } from "./i18n-BcPL9_Jh.js";
5
+ import { n as ve, k as Lt, o as ps, i as Rt, p as ds, d as se, a as as, m as Me, v as Ae, c as us, g as bs, l as fs } from "./display-DQRcvsn7.js";
6
+ import { repeat as Oe } from "lit/directives/repeat.js";
7
+ import { html as ee, unsafeStatic as is } from "lit/static-html.js";
8
+ import { c as ms, r as U } from "./baht-toast-CD1WrOYr.js";
9
+ import { live as rt } from "lit/directives/live.js";
10
+ import { ifDefined as L } from "lit/directives/if-defined.js";
11
+ import vs from "flatpickr";
12
+ var $s = Object.defineProperty, ys = Object.getOwnPropertyDescriptor, he = (t, e, i, a) => {
13
+ for (var s = a > 1 ? void 0 : a ? ys(e, i) : e, r = t.length - 1, o; r >= 0; r--)
14
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
15
+ return a && s && $s(e, i, s), s;
16
+ };
17
+ let zt = class extends $ {
18
+ constructor() {
19
+ super(...arguments), this.tone = "neutral", this.label = "", this.dot = null;
20
+ }
21
+ get showDot() {
22
+ return this.dot !== null ? this.dot : ["neutral", "success", "danger", "warning", "info"].includes(this.tone);
23
+ }
24
+ render() {
25
+ const t = this.tone === "neutral" ? "" : ` baht-badge--${this.tone}`;
26
+ return n`<span class="baht-badge${t}">
27
+ ${this.showDot ? n`<span class="baht-badge-dot" aria-hidden="true"></span>` : h}${this.label}
28
+ </span>`;
29
+ }
30
+ };
31
+ he([
32
+ l()
33
+ ], zt.prototype, "tone", 2);
34
+ he([
35
+ l()
36
+ ], zt.prototype, "label", 2);
37
+ he([
38
+ l({ attribute: !1 })
39
+ ], zt.prototype, "dot", 2);
40
+ zt = he([
41
+ u("baht-badge")
42
+ ], zt);
43
+ var gs = Object.defineProperty, ws = Object.getOwnPropertyDescriptor, Ie = (t, e, i, a) => {
44
+ for (var s = a > 1 ? void 0 : a ? ws(e, i) : e, r = t.length - 1, o; r >= 0; r--)
45
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
46
+ return a && s && gs(e, i, s), s;
47
+ };
48
+ let ae = class extends $ {
49
+ constructor() {
50
+ super(...arguments), this.variant = "inline", this.code = "";
51
+ }
52
+ firstUpdated() {
53
+ const t = this.renderRoot.querySelector(this.variant === "block" ? "pre" : "code");
54
+ t && ne(this, t);
55
+ }
56
+ render() {
57
+ return this.variant === "block" ? n`<pre class="baht-code baht-code--block" tabindex="0">${this.code}</pre>` : n`<code class="baht-code">${this.code}</code>`;
58
+ }
59
+ };
60
+ Ie([
61
+ l()
62
+ ], ae.prototype, "variant", 2);
63
+ Ie([
64
+ l()
65
+ ], ae.prototype, "code", 2);
66
+ ae = Ie([
67
+ u("baht-code")
68
+ ], ae);
69
+ var xs = Object.defineProperty, _s = Object.getOwnPropertyDescriptor, $t = (t, e, i, a) => {
70
+ for (var s = a > 1 ? void 0 : a ? _s(e, i) : e, r = t.length - 1, o; r >= 0; r--)
71
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
72
+ return a && s && xs(e, i, s), s;
73
+ };
74
+ let nt = class extends $ {
75
+ constructor() {
76
+ super(...arguments), this.page = 1, this.totalPages = 1, this.variant = "numbered", this.siblings = 1, this.hasNext = !1, this.hasPrev = !1;
77
+ }
78
+ go(t) {
79
+ const e = Math.min(Math.max(1, t), this.totalPages);
80
+ e !== this.page && this.dispatchEvent(
81
+ new CustomEvent("baht-page-change", {
82
+ detail: { page: e },
83
+ bubbles: !0,
84
+ composed: !0
85
+ })
86
+ );
87
+ }
88
+ goCursor(t) {
89
+ t === "next" && !this.hasNext || t === "prev" && !this.hasPrev || this.dispatchEvent(
90
+ new CustomEvent("baht-cursor-change", {
91
+ detail: { direction: t },
92
+ bubbles: !0,
93
+ composed: !0
94
+ })
95
+ );
96
+ }
97
+ /** Visible page numbers with `null` marking an ellipsis gap. */
98
+ get pageItems() {
99
+ const { page: t, totalPages: e, siblings: i } = this, a = /* @__PURE__ */ new Set([1, e]);
100
+ for (let c = t - i; c <= t + i; c++)
101
+ c >= 1 && c <= e && a.add(c);
102
+ const s = [...a].sort((c, m) => c - m), r = [];
103
+ let o = 0;
104
+ for (const c of s)
105
+ o && c - o === 2 ? r.push(o + 1) : o && c - o > 2 && r.push(null), r.push(c), o = c;
106
+ return r;
107
+ }
108
+ render() {
109
+ if (this.variant === "cursor")
110
+ return n`<nav class="baht-pagination baht-pagination--cursor" aria-label="Pagination">
111
+ <button type="button" ?disabled=${!this.hasPrev} @click=${() => this.goCursor("prev")}><span aria-hidden="true">« </span>Prev</button>
112
+ <button type="button" ?disabled=${!this.hasNext} @click=${() => this.goCursor("next")}>Next<span aria-hidden="true"> »</span></button>
113
+ </nav>`;
114
+ const t = this.page <= 1, e = this.page >= this.totalPages;
115
+ return n`<nav class="baht-pagination" aria-label="Pagination">
116
+ <button type="button" aria-label="Previous page" ?disabled=${t} @click=${() => this.go(this.page - 1)}><span aria-hidden="true">«</span></button>
117
+ ${this.variant === "compact" ? n`<span class="baht-pagination-label">Page ${this.page} of ${this.totalPages}</span>` : this.pageItems.map(
118
+ (i) => i === null ? n`<span class="baht-pagination-ellipsis" aria-hidden="true">…</span>` : n`<button
119
+ type="button"
120
+ aria-current=${i === this.page ? "page" : h}
121
+ aria-label="Page ${i}"
122
+ @click=${() => this.go(i)}
123
+ >${i}</button>`
124
+ )}
125
+ <button type="button" aria-label="Next page" ?disabled=${e} @click=${() => this.go(this.page + 1)}><span aria-hidden="true">»</span></button>
126
+ </nav>`;
127
+ }
128
+ };
129
+ $t([
130
+ l({ type: Number })
131
+ ], nt.prototype, "page", 2);
132
+ $t([
133
+ l({ type: Number, attribute: "total-pages" })
134
+ ], nt.prototype, "totalPages", 2);
135
+ $t([
136
+ l()
137
+ ], nt.prototype, "variant", 2);
138
+ $t([
139
+ l({ type: Number })
140
+ ], nt.prototype, "siblings", 2);
141
+ $t([
142
+ l({ type: Boolean, attribute: "has-next" })
143
+ ], nt.prototype, "hasNext", 2);
144
+ $t([
145
+ l({ type: Boolean, attribute: "has-prev" })
146
+ ], nt.prototype, "hasPrev", 2);
147
+ nt = $t([
148
+ u("baht-pagination")
149
+ ], nt);
150
+ var ks = Object.defineProperty, Ps = Object.getOwnPropertyDescriptor, C = (t, e, i, a) => {
151
+ for (var s = a > 1 ? void 0 : a ? Ps(e, i) : e, r = t.length - 1, o; r >= 0; r--)
152
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
153
+ return a && s && ks(e, i, s), s;
154
+ };
155
+ const Os = " › ", $e = (t) => t !== null && typeof t == "object" && !Array.isArray(t) && !(t instanceof Date), te = (t) => t.replace(/_/g, " ").replace(/\b\w/g, (e) => e.toUpperCase());
156
+ let P = class extends $ {
157
+ constructor() {
158
+ super(...arguments), this.items = [], this.columns = {}, this.loading = !1, this.error = !1, this.errorMessage = "Couldn't load data. Try again.", this.emptyMessage = "No records yet.", this.showIndex = !0, this.indexOffset = 0, this.skeletonRows = 10, this.rowKey = "", this.clickable = !0, this.renderers = {}, this.visibleColumns = [], this.columnPicker = !0, this.page = 1, this.totalPages = 1, this.cursorMode = !1, this.hasNext = !1, this.hasPrev = !1, this.pickerOpen = !1, this.pickedColumns = null, this.draftColumns = [], this.pickAvail = [], this.pickSel = [], this.expanded = [], this.pickerPreviousFocus = null, this.onPickerKeydown = (t) => {
159
+ t.key === "Escape" ? this.closePicker() : t.key === "Tab" && this.trapPickerFocus(t);
160
+ };
161
+ }
162
+ get pickerTitleId() {
163
+ return `baht-table-picker-title-${this.uid}`;
164
+ }
165
+ pickerFocusables() {
166
+ const t = this.querySelector(".baht-table-picker-modal");
167
+ return t ? Array.from(
168
+ t.querySelectorAll(
169
+ 'button:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])'
170
+ )
171
+ ) : [];
172
+ }
173
+ /** Keep Tab cycling inside the column-picker dialog (no escape to the page behind). */
174
+ trapPickerFocus(t) {
175
+ const e = this.pickerFocusables();
176
+ if (e.length === 0) return;
177
+ const i = e[0], a = e[e.length - 1], s = document.activeElement, r = this.querySelector(".baht-table-picker-modal");
178
+ r != null && r.contains(s) ? t.shiftKey && s === i ? (a.focus(), t.preventDefault()) : !t.shiftKey && s === a && (i.focus(), t.preventDefault()) : (i.focus(), t.preventDefault());
179
+ }
180
+ disconnectedCallback() {
181
+ super.disconnectedCallback(), q() && document.removeEventListener("keydown", this.onPickerKeydown);
182
+ }
183
+ willUpdate(t) {
184
+ t.has("visibleColumns") && !t.has("columns") && (this.pickedColumns = null);
185
+ }
186
+ // ---- column model ----------------------------------------------------
187
+ /** The declared map, or one derived from the first row (nested objects become reference columns). */
188
+ get spec() {
189
+ if (Object.keys(this.columns).length > 0) return this.columns;
190
+ const t = this.items[0];
191
+ if (!t) return {};
192
+ const e = {};
193
+ for (const [i, a] of Object.entries(t))
194
+ e[i] = $e(a) ? {
195
+ label: te(i),
196
+ fields: Object.fromEntries(Object.keys(a).map((s) => [s, te(s)]))
197
+ } : te(i);
198
+ return e;
199
+ }
200
+ /** Walk a dotted key through the spec; undefined when no such column exists. */
201
+ specAt(t) {
202
+ let e = this.spec, i;
203
+ for (const a of t.split(".")) {
204
+ const s = e == null ? void 0 : e[a];
205
+ if (s === void 0) return;
206
+ const r = typeof s == "string" ? { label: s } : s;
207
+ i = r, e = r.fields;
208
+ }
209
+ return i;
210
+ }
211
+ isReference(t) {
212
+ var e;
213
+ return (((e = this.specAt(t)) == null ? void 0 : e.fields) ?? void 0) !== void 0;
214
+ }
215
+ childrenOf(t) {
216
+ var e;
217
+ return Object.keys(((e = this.specAt(t)) == null ? void 0 : e.fields) ?? {}).map((i) => `${t}.${i}`);
218
+ }
219
+ /** Every pickable key, reference fields included (`requester`, `requester.name`, ...). */
220
+ allPaths(t = "") {
221
+ return (t ? this.childrenOf(t) : this.allColumnKeys).flatMap((i) => this.isReference(i) ? [i, ...this.allPaths(i)] : [i]);
222
+ }
223
+ get allColumnKeys() {
224
+ return Object.keys(this.spec);
225
+ }
226
+ get columnKeys() {
227
+ return (this.pickedColumns ?? (this.visibleColumns.length > 0 ? this.visibleColumns : this.allColumnKeys)).filter((e) => this.specAt(e) !== void 0);
228
+ }
229
+ /** "Requested by › Department" for a dotted key; the plain label otherwise. */
230
+ labelFor(t) {
231
+ const e = [];
232
+ let i = this.spec;
233
+ for (const a of t.split(".")) {
234
+ const s = i == null ? void 0 : i[a];
235
+ if (s === void 0) {
236
+ e.push(te(a)), i = void 0;
237
+ continue;
238
+ }
239
+ e.push(typeof s == "string" ? s : s.label), i = typeof s == "string" ? void 0 : s.fields;
240
+ }
241
+ return e.join(Os);
242
+ }
243
+ /** The row's value at a dotted key (`requester.department`). */
244
+ static valueAt(t, e) {
245
+ let i = t;
246
+ for (const a of e.split(".")) {
247
+ if (!$e(i)) return;
248
+ i = i[a];
249
+ }
250
+ return i;
251
+ }
252
+ // ---- picker -----------------------------------------------------------
253
+ openPicker() {
254
+ this.draftColumns = this.columnKeys.slice(), this.pickAvail = [], this.pickSel = [], this.pickerOpen = !0, this.pickerPreviousFocus = document.activeElement, q() && document.addEventListener("keydown", this.onPickerKeydown), this.updateComplete.then(() => {
255
+ var t;
256
+ this.pickerOpen && ((t = this.pickerFocusables()[0]) == null || t.focus());
257
+ });
258
+ }
259
+ closePicker() {
260
+ var e;
261
+ if (!this.pickerOpen) return;
262
+ this.pickerOpen = !1, q() && document.removeEventListener("keydown", this.onPickerKeydown);
263
+ const t = this.pickerPreviousFocus;
264
+ this.pickerPreviousFocus = null, t != null && t.isConnected && ((e = t.focus) == null || e.call(t));
265
+ }
266
+ static selectedValues(t) {
267
+ return Array.from(t.target.selectedOptions).map((e) => e.value);
268
+ }
269
+ toggleAvail(t) {
270
+ this.pickAvail = this.pickAvail.includes(t) ? this.pickAvail.filter((e) => e !== t) : [...this.pickAvail, t];
271
+ }
272
+ toggleExpanded(t) {
273
+ this.expanded = this.expanded.includes(t) ? this.expanded.filter((e) => e !== t) : [...this.expanded, t];
274
+ }
275
+ addToSelected() {
276
+ this.draftColumns = [
277
+ ...this.draftColumns,
278
+ ...this.pickAvail.filter((t) => !this.draftColumns.includes(t))
279
+ ], this.pickAvail = [];
280
+ }
281
+ removeFromSelected() {
282
+ this.draftColumns = this.draftColumns.filter((t) => !this.pickSel.includes(t)), this.pickSel = [];
283
+ }
284
+ moveSelected(t) {
285
+ const e = [...this.draftColumns], i = this.pickSel.map((a) => e.indexOf(a)).filter((a) => a >= 0).sort((a, s) => t === -1 ? a - s : s - a);
286
+ for (const a of i) {
287
+ const s = a + t;
288
+ s < 0 || s >= e.length || ([e[a], e[s]] = [e[s], e[a]]);
289
+ }
290
+ this.draftColumns = e;
291
+ }
292
+ confirmPicker() {
293
+ this.pickedColumns = this.draftColumns, this.closePicker();
294
+ const t = {
295
+ visibleColumns: this.pickedColumns,
296
+ columns: this.pickedColumns.map((e) => ({ key: e, label: this.labelFor(e) }))
297
+ };
298
+ this.dispatchEvent(
299
+ new CustomEvent("baht-columns-change", { detail: t, bubbles: !0, composed: !0 })
300
+ );
301
+ }
302
+ emitRow(t, e) {
303
+ this.clickable && this.dispatchEvent(
304
+ new CustomEvent("baht-row-click", {
305
+ detail: { row: t, index: e, id: this.rowKey ? t[this.rowKey] : void 0 },
306
+ bubbles: !0,
307
+ composed: !0
308
+ })
309
+ );
310
+ }
311
+ cell(t, e) {
312
+ const i = this.renderers[e], a = P.valueAt(t, e);
313
+ if (i) return i(a, t);
314
+ if ($e(a)) {
315
+ const s = a.name ?? a.label ?? a.title ?? a.id;
316
+ return s == null ? "" : String(s);
317
+ }
318
+ return a == null ? "" : String(a);
319
+ }
320
+ renderBody(t) {
321
+ const e = t.length + (this.showIndex ? 1 : 0);
322
+ return this.loading ? n`${Array.from(
323
+ { length: this.skeletonRows },
324
+ (i, a) => n`<tr>
325
+ ${this.showIndex ? n`<td class="baht-table-index">${this.indexOffset + a + 1}</td>` : h}
326
+ ${t.map(() => n`<td><span class="baht-skeleton" style="height:16px;"></span></td>`)}
327
+ </tr>`
328
+ )}` : this.error ? n`<tr><td colspan=${e}><div class="baht-table-state baht-table-state--error" role="alert">${this.errorMessage}</div></td></tr>` : this.items.length === 0 ? n`<tr><td colspan=${e}><div class="baht-table-state">${this.emptyMessage}</div></td></tr>` : n`${this.items.map(
329
+ (i, a) => n`<tr
330
+ tabindex=${this.clickable ? "0" : h}
331
+ @click=${() => this.emitRow(i, a)}
332
+ @keydown=${(s) => {
333
+ s.key !== "Enter" && s.key !== " " || (s.preventDefault(), this.emitRow(i, a));
334
+ }}
335
+ >
336
+ ${this.showIndex ? n`<td class="baht-table-index">${this.indexOffset + a + 1}</td>` : h}
337
+ ${t.map((s) => n`<td data-col=${s}>${this.cell(i, s)}</td>`)}
338
+ </tr>`
339
+ )}`;
340
+ }
341
+ renderColumnToggle() {
342
+ return n`<div class="baht-table-picker">
343
+ <button
344
+ type="button"
345
+ class="baht-table-picker-toggle"
346
+ aria-haspopup="dialog"
347
+ aria-expanded=${this.pickerOpen ? "true" : "false"}
348
+ @click=${() => this.openPicker()}
349
+ >Columns</button>
350
+ </div>`;
351
+ }
352
+ /**
353
+ * One row of the Available tree. A reference column gets an expander that
354
+ * unfolds its fields (the dot-walk); every row is a toggle button so the
355
+ * list works from the keyboard without the native multi-select.
356
+ */
357
+ renderAvailRow(t, e) {
358
+ const i = this.specAt(t), a = (i == null ? void 0 : i.fields) !== void 0, s = this.expanded.includes(t), r = this.draftColumns.includes(t);
359
+ return n`<li class="baht-table-picker-node" style="--baht-picker-depth:${e}">
360
+ <div class="baht-table-picker-row">
361
+ ${a ? n`<button
362
+ type="button"
363
+ class="baht-table-picker-expand"
364
+ aria-label=${s ? `Collapse ${i == null ? void 0 : i.label}` : `Expand ${i == null ? void 0 : i.label}`}
365
+ aria-expanded=${s ? "true" : "false"}
366
+ @click=${() => this.toggleExpanded(t)}
367
+ >${s ? "▾" : "▸"}</button>` : n`<span class="baht-table-picker-expand baht-table-picker-expand--leaf"></span>`}
368
+ <button
369
+ type="button"
370
+ class="baht-table-picker-option"
371
+ data-key=${t}
372
+ ?disabled=${r}
373
+ aria-pressed=${this.pickAvail.includes(t) ? "true" : "false"}
374
+ @click=${() => this.toggleAvail(t)}
375
+ >${e === 0 ? this.labelFor(t) : (i == null ? void 0 : i.label) ?? t}</button>
376
+ </div>
377
+ ${a && s ? n`<ul class="baht-table-picker-tree">
378
+ ${this.childrenOf(t).map((o) => this.renderAvailRow(o, e + 1))}
379
+ </ul>` : h}
380
+ </li>`;
381
+ }
382
+ renderColumnModal() {
383
+ const t = this.allColumnKeys, e = this.allPaths().filter((a) => !this.draftColumns.includes(a)).length, i = (a) => (s) => a(P.selectedValues(s));
384
+ return n`<div
385
+ class="baht-table-picker-scrim"
386
+ @click=${(a) => a.target === a.currentTarget && this.closePicker()}
387
+ >
388
+ <div class="baht-table-picker-modal" role="dialog" aria-modal="true" aria-labelledby=${this.pickerTitleId}>
389
+ <div class="baht-table-picker-modal-head">
390
+ <b id=${this.pickerTitleId}>Choose columns</b>
391
+ <button type="button" class="baht-table-picker-modal-close" aria-label="Close" @click=${() => this.closePicker()}>×</button>
392
+ </div>
393
+ <div class="baht-table-picker-grid">
394
+ <div>
395
+ <div class="baht-table-picker-collabel">Available (${e})</div>
396
+ <ul class="baht-table-picker-tree baht-table-picker-avail" aria-label="Available columns">
397
+ ${t.map((a) => this.renderAvailRow(a, 0))}
398
+ </ul>
399
+ </div>
400
+ <div class="baht-table-picker-btns">
401
+ <button type="button" ?disabled=${!this.pickAvail.length} @click=${() => this.addToSelected()}>› Add</button>
402
+ <button type="button" ?disabled=${!this.pickSel.length} @click=${() => this.removeFromSelected()}>‹ Remove</button>
403
+ <button type="button" ?disabled=${!this.pickSel.length} @click=${() => this.moveSelected(-1)}>↑ Up</button>
404
+ <button type="button" ?disabled=${!this.pickSel.length} @click=${() => this.moveSelected(1)}>↓ Down</button>
405
+ </div>
406
+ <div>
407
+ <div class="baht-table-picker-collabel">Selected (${this.draftColumns.length})</div>
408
+ <select multiple size="10" class="baht-table-picker-select" aria-label="Selected columns" @change=${i((a) => this.pickSel = a)}>
409
+ ${this.draftColumns.map(
410
+ (a) => n`<option value=${a} ?selected=${this.pickSel.includes(a)}>${this.labelFor(a)}</option>`
411
+ )}
412
+ </select>
413
+ </div>
414
+ </div>
415
+ <div class="baht-table-picker-modal-foot">
416
+ <button type="button" @click=${() => this.draftColumns = []}>Clear all</button>
417
+ <button type="button" @click=${() => this.draftColumns = t.slice()}>Select all</button>
418
+ <span class="baht-table-picker-spacer"></span>
419
+ <button type="button" @click=${() => this.closePicker()}>Cancel</button>
420
+ <button type="button" class="baht-table-picker-ok" @click=${() => this.confirmPicker()}>OK</button>
421
+ </div>
422
+ </div>
423
+ </div>`;
424
+ }
425
+ render() {
426
+ const t = this.columnKeys;
427
+ return n`<div
428
+ class="baht-table-wrap"
429
+ tabindex=${this.clickable ? h : "0"}
430
+ aria-busy=${this.loading ? "true" : h}
431
+ >
432
+ ${this.columnPicker ? this.renderColumnToggle() : h}
433
+ ${this.columnPicker && this.pickerOpen ? this.renderColumnModal() : h}
434
+ <table class="baht-table">
435
+ <thead>
436
+ <tr>
437
+ ${this.showIndex ? n`<th scope="col" class="baht-table-index">No.</th>` : h}
438
+ ${t.map((e) => n`<th scope="col" data-col=${e}>${this.labelFor(e)}</th>`)}
439
+ </tr>
440
+ </thead>
441
+ <tbody>${this.renderBody(t)}</tbody>
442
+ </table>
443
+ ${this.cursorMode ? n`<div class="baht-table-footer">
444
+ <baht-pagination
445
+ variant="cursor"
446
+ ?has-next=${this.hasNext}
447
+ ?has-prev=${this.hasPrev}
448
+ ></baht-pagination>
449
+ </div>` : this.totalPages > 1 ? n`<div class="baht-table-footer">
450
+ <baht-pagination
451
+ variant="compact"
452
+ page=${this.page}
453
+ total-pages=${this.totalPages}
454
+ ></baht-pagination>
455
+ </div>` : h}
456
+ </div>`;
457
+ }
458
+ };
459
+ C([
460
+ l({ attribute: !1 })
461
+ ], P.prototype, "items", 2);
462
+ C([
463
+ l({ attribute: !1 })
464
+ ], P.prototype, "columns", 2);
465
+ C([
466
+ l({ type: Boolean })
467
+ ], P.prototype, "loading", 2);
468
+ C([
469
+ l({ type: Boolean })
470
+ ], P.prototype, "error", 2);
471
+ C([
472
+ l({ attribute: "error-message" })
473
+ ], P.prototype, "errorMessage", 2);
474
+ C([
475
+ l({ attribute: "empty-message" })
476
+ ], P.prototype, "emptyMessage", 2);
477
+ C([
478
+ l({ type: Boolean, attribute: "show-index" })
479
+ ], P.prototype, "showIndex", 2);
480
+ C([
481
+ l({ type: Number, attribute: "index-offset" })
482
+ ], P.prototype, "indexOffset", 2);
483
+ C([
484
+ l({ type: Number, attribute: "skeleton-rows" })
485
+ ], P.prototype, "skeletonRows", 2);
486
+ C([
487
+ l({ attribute: "row-key" })
488
+ ], P.prototype, "rowKey", 2);
489
+ C([
490
+ l({ type: Boolean })
491
+ ], P.prototype, "clickable", 2);
492
+ C([
493
+ l({ attribute: !1 })
494
+ ], P.prototype, "renderers", 2);
495
+ C([
496
+ l({ attribute: !1 })
497
+ ], P.prototype, "visibleColumns", 2);
498
+ C([
499
+ l({ type: Boolean, attribute: "column-picker" })
500
+ ], P.prototype, "columnPicker", 2);
501
+ C([
502
+ l({ type: Number })
503
+ ], P.prototype, "page", 2);
504
+ C([
505
+ l({ type: Number, attribute: "total-pages" })
506
+ ], P.prototype, "totalPages", 2);
507
+ C([
508
+ l({ type: Boolean, attribute: "cursor-mode" })
509
+ ], P.prototype, "cursorMode", 2);
510
+ C([
511
+ l({ type: Boolean, attribute: "has-next" })
512
+ ], P.prototype, "hasNext", 2);
513
+ C([
514
+ l({ type: Boolean, attribute: "has-prev" })
515
+ ], P.prototype, "hasPrev", 2);
516
+ C([
517
+ y()
518
+ ], P.prototype, "pickerOpen", 2);
519
+ C([
520
+ y()
521
+ ], P.prototype, "pickedColumns", 2);
522
+ C([
523
+ y()
524
+ ], P.prototype, "draftColumns", 2);
525
+ C([
526
+ y()
527
+ ], P.prototype, "pickAvail", 2);
528
+ C([
529
+ y()
530
+ ], P.prototype, "pickSel", 2);
531
+ C([
532
+ y()
533
+ ], P.prototype, "expanded", 2);
534
+ P = C([
535
+ u("baht-table")
536
+ ], P);
537
+ var Cs = Object.defineProperty, Ds = Object.getOwnPropertyDescriptor, dt = (t, e, i, a) => {
538
+ for (var s = a > 1 ? void 0 : a ? Ds(e, i) : e, r = t.length - 1, o; r >= 0; r--)
539
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
540
+ return a && s && Cs(e, i, s), s;
541
+ };
542
+ let at = class extends $ {
543
+ constructor() {
544
+ super(...arguments), this.items = [], this.loading = !1, this.error = !1, this.errorMessage = "Couldn't load data. Try again.", this.emptyMessage = "Nothing here yet.", this.skeletonRows = 5, this.clickable = !0;
545
+ }
546
+ emitItem(t, e) {
547
+ this.clickable && this.dispatchEvent(
548
+ new CustomEvent("baht-item-click", {
549
+ detail: { item: t, index: e, id: t.id },
550
+ bubbles: !0,
551
+ composed: !0
552
+ })
553
+ );
554
+ }
555
+ renderRows() {
556
+ return this.loading ? n`${Array.from(
557
+ { length: this.skeletonRows },
558
+ () => n`<div class="baht-list-item">
559
+ <div class="baht-list-main">
560
+ <span class="baht-skeleton baht-skeleton--text" style="width:40%; margin-bottom:6px;"></span>
561
+ <span class="baht-skeleton baht-skeleton--text" style="width:65%;"></span>
562
+ </div>
563
+ </div>`
564
+ )}` : this.error ? n`<div class="baht-list-state baht-list-state--error" role="alert">${this.errorMessage}</div>` : this.items.length === 0 ? n`<div class="baht-list-state">${this.emptyMessage}</div>` : n`${this.items.map(
565
+ (t, e) => n`<div
566
+ class="baht-list-item"
567
+ role="listitem"
568
+ tabindex=${this.clickable ? "0" : h}
569
+ @click=${() => this.emitItem(t, e)}
570
+ @keydown=${(i) => {
571
+ i.key !== "Enter" && i.key !== " " || (i.preventDefault(), this.emitItem(t, e));
572
+ }}
573
+ >
574
+ <div class="baht-list-main">
575
+ <div class="baht-list-title">${t.title}</div>
576
+ ${t.subtitle ? n`<div class="baht-list-subtitle">${t.subtitle}</div>` : h}
577
+ </div>
578
+ ${t.badge ? n`<baht-badge tone=${t.badgeTone ?? "neutral"} label=${t.badge}></baht-badge>` : h}
579
+ ${t.meta ? n`<span class="baht-list-meta">${t.meta}</span>` : h}
580
+ </div>`
581
+ )}`;
582
+ }
583
+ render() {
584
+ const t = !this.loading && !this.error && this.items.length > 0;
585
+ return n`<div class="baht-list" role=${t ? "list" : h}>${this.renderRows()}</div>`;
586
+ }
587
+ };
588
+ dt([
589
+ l({ attribute: !1 })
590
+ ], at.prototype, "items", 2);
591
+ dt([
592
+ l({ type: Boolean })
593
+ ], at.prototype, "loading", 2);
594
+ dt([
595
+ l({ type: Boolean })
596
+ ], at.prototype, "error", 2);
597
+ dt([
598
+ l({ attribute: "error-message" })
599
+ ], at.prototype, "errorMessage", 2);
600
+ dt([
601
+ l({ attribute: "empty-message" })
602
+ ], at.prototype, "emptyMessage", 2);
603
+ dt([
604
+ l({ type: Number, attribute: "skeleton-rows" })
605
+ ], at.prototype, "skeletonRows", 2);
606
+ dt([
607
+ l({ type: Boolean })
608
+ ], at.prototype, "clickable", 2);
609
+ at = dt([
610
+ u("baht-list")
611
+ ], at);
612
+ var Fs = Object.defineProperty, Es = Object.getOwnPropertyDescriptor, Wt = (t, e, i, a) => {
613
+ for (var s = a > 1 ? void 0 : a ? Es(e, i) : e, r = t.length - 1, o; r >= 0; r--)
614
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
615
+ return a && s && Fs(e, i, s), s;
616
+ };
617
+ let _t = class extends $ {
618
+ constructor() {
619
+ super(...arguments), this.text = "", this.position = "top", this.dismissed = !1;
620
+ }
621
+ get tooltipId() {
622
+ return `baht-tooltip-${this.uid}`;
623
+ }
624
+ /**
625
+ * Point aria-describedby at the tooltip from the focusable child (light DOM,
626
+ * so the id reference works). No focusable child -> the anchor itself becomes
627
+ * one, so keyboard users can still surface the tooltip.
628
+ */
629
+ wireDescribedBy() {
630
+ const t = this.anchorEl.querySelector(
631
+ "button, a[href], input, select, textarea, [tabindex]"
632
+ );
633
+ t ? (t.setAttribute("aria-describedby", this.tooltipId), this.anchorEl.removeAttribute("tabindex"), this.anchorEl.removeAttribute("aria-describedby")) : (this.anchorEl.setAttribute("tabindex", "0"), this.anchorEl.setAttribute("aria-describedby", this.tooltipId));
634
+ }
635
+ firstUpdated() {
636
+ ne(this, this.anchorEl), this.wireDescribedBy(), setTimeout(() => this.isConnected && this.wireDescribedBy(), 0);
637
+ }
638
+ onKeydown(t) {
639
+ t.key === "Escape" && (this.dismissed = !0);
640
+ }
641
+ rearm() {
642
+ this.dismissed = !1;
643
+ }
644
+ render() {
645
+ return n`<span
646
+ class="baht-tooltip-host${this.dismissed ? " baht-tooltip-host--dismissed" : ""}"
647
+ @keydown=${this.onKeydown}
648
+ @mouseleave=${this.rearm}
649
+ @focusout=${this.rearm}
650
+ >
651
+ <span class="baht-tooltip-anchor"></span>
652
+ <span class="baht-tooltip baht-tooltip--${this.position}" id=${this.tooltipId} role="tooltip">${this.text}</span>
653
+ </span>`;
654
+ }
655
+ };
656
+ Wt([
657
+ l()
658
+ ], _t.prototype, "text", 2);
659
+ Wt([
660
+ l()
661
+ ], _t.prototype, "position", 2);
662
+ Wt([
663
+ Et(".baht-tooltip-anchor")
664
+ ], _t.prototype, "anchorEl", 2);
665
+ Wt([
666
+ y()
667
+ ], _t.prototype, "dismissed", 2);
668
+ _t = Wt([
669
+ u("baht-tooltip")
670
+ ], _t);
671
+ var Bs = Object.defineProperty, Is = Object.getOwnPropertyDescriptor, Bt = (t, e, i, a) => {
672
+ for (var s = a > 1 ? void 0 : a ? Is(e, i) : e, r = t.length - 1, o; r >= 0; r--)
673
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
674
+ return a && s && Bs(e, i, s), s;
675
+ };
676
+ let bt = class extends $ {
677
+ constructor() {
678
+ super(...arguments), this.tone = "info", this.heading = "", this.message = "", this.dismissible = !1, this.dismissed = !1, this.generation = 0;
679
+ }
680
+ willUpdate(t) {
681
+ (t.has("message") || t.has("heading")) && (this.dismissed = !1, this.generation++);
682
+ }
683
+ dismiss() {
684
+ this.dispatchEvent(new CustomEvent("baht-dismiss", { bubbles: !0, composed: !0 }));
685
+ const t = this.generation, e = () => {
686
+ t === this.generation && (this.dismissed = !0);
687
+ }, i = this.querySelector(".baht-alert");
688
+ if (!i) {
689
+ e();
690
+ return;
691
+ }
692
+ i.classList.add("baht-alert--leaving"), ms(i, e);
693
+ }
694
+ render() {
695
+ return this.dismissed ? h : n`<div class="baht-alert baht-alert--${this.tone}" role="alert">
696
+ <div class="baht-alert-main">
697
+ ${this.heading ? n`<div class="baht-alert-title">${this.heading}</div>` : h}
698
+ ${this.message ? n`<div class="baht-alert-message">${this.message}</div>` : h}
699
+ </div>
700
+ ${this.dismissible ? n`<button type="button" class="baht-alert-dismiss" aria-label=${v("dismiss")} @click=${() => this.dismiss()}>×</button>` : h}
701
+ </div>`;
702
+ }
703
+ };
704
+ Bt([
705
+ l()
706
+ ], bt.prototype, "tone", 2);
707
+ Bt([
708
+ l()
709
+ ], bt.prototype, "heading", 2);
710
+ Bt([
711
+ l()
712
+ ], bt.prototype, "message", 2);
713
+ Bt([
714
+ l({ type: Boolean })
715
+ ], bt.prototype, "dismissible", 2);
716
+ Bt([
717
+ y()
718
+ ], bt.prototype, "dismissed", 2);
719
+ bt = Bt([
720
+ u("baht-alert")
721
+ ], bt);
722
+ var js = Object.defineProperty, Ss = Object.getOwnPropertyDescriptor, It = (t, e, i, a) => {
723
+ for (var s = a > 1 ? void 0 : a ? Ss(e, i) : e, r = t.length - 1, o; r >= 0; r--)
724
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
725
+ return a && s && js(e, i, s), s;
726
+ };
727
+ let ft = class extends $ {
728
+ constructor() {
729
+ super(...arguments), this.value = 0, this.max = 5, this.readonly = !1, this.label = "Rating", this.hover = 0;
730
+ }
731
+ emitValue(t) {
732
+ this.dispatchEvent(
733
+ new CustomEvent("baht-change", { detail: { value: t }, bubbles: !0, composed: !0 })
734
+ );
735
+ }
736
+ pick(t) {
737
+ this.readonly || this.emitValue(t === this.value ? 0 : t);
738
+ }
739
+ /** APG radio-group keys: arrows move the value, Home/End jump the ends. */
740
+ onKeydown(t, e) {
741
+ var a;
742
+ if (this.readonly) return;
743
+ let i;
744
+ if (t.key === "ArrowRight" || t.key === "ArrowUp") i = Math.min(e + 1, this.max);
745
+ else if (t.key === "ArrowLeft" || t.key === "ArrowDown") i = Math.max(e - 1, 1);
746
+ else if (t.key === "Home") i = 1;
747
+ else if (t.key === "End") i = this.max;
748
+ else return;
749
+ t.preventDefault(), this.emitValue(i), (a = this.querySelectorAll("button")[i - 1]) == null || a.focus();
750
+ }
751
+ setHover(t) {
752
+ this.readonly || (this.hover = t);
753
+ }
754
+ render() {
755
+ const t = this.hover || this.value;
756
+ return n`<div
757
+ class="baht-rating"
758
+ role="radiogroup"
759
+ aria-label=${this.label}
760
+ @mouseleave=${() => this.setHover(0)}
761
+ >
762
+ ${Array.from({ length: this.max }, (e, i) => {
763
+ const a = i + 1, s = this.value || 1;
764
+ return n`<button
765
+ type="button"
766
+ class=${a <= t ? "baht-rating--on" : ""}
767
+ role="radio"
768
+ aria-checked=${a === this.value}
769
+ aria-label="${a} of ${this.max}"
770
+ tabindex=${a === s ? "0" : "-1"}
771
+ ?disabled=${this.readonly}
772
+ @mouseenter=${() => this.setHover(a)}
773
+ @click=${() => this.pick(a)}
774
+ @keydown=${(r) => this.onKeydown(r, a)}
775
+ >★</button>`;
776
+ })}
777
+ </div>`;
778
+ }
779
+ };
780
+ It([
781
+ l({ type: Number })
782
+ ], ft.prototype, "value", 2);
783
+ It([
784
+ l({ type: Number })
785
+ ], ft.prototype, "max", 2);
786
+ It([
787
+ l({ type: Boolean })
788
+ ], ft.prototype, "readonly", 2);
789
+ It([
790
+ l()
791
+ ], ft.prototype, "label", 2);
792
+ It([
793
+ y()
794
+ ], ft.prototype, "hover", 2);
795
+ ft = It([
796
+ u("baht-rating")
797
+ ], ft);
798
+ var Ts = Object.defineProperty, Ms = Object.getOwnPropertyDescriptor, ut = (t, e, i, a) => {
799
+ for (var s = a > 1 ? void 0 : a ? Ms(e, i) : e, r = t.length - 1, o; r >= 0; r--)
800
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
801
+ return a && s && Ts(e, i, s), s;
802
+ };
803
+ let it = class extends $ {
804
+ constructor() {
805
+ super(...arguments), this.value = 0, this.min = 0, this.max = 100, this.step = 1, this.label = "", this.disabled = !1, this.showValue = !0;
806
+ }
807
+ get inputId() {
808
+ return `baht-range-${this.uid}`;
809
+ }
810
+ onInput(t) {
811
+ const e = Number(t.target.value);
812
+ this.dispatchEvent(
813
+ new CustomEvent("baht-change", { detail: { value: e }, bubbles: !0, composed: !0 })
814
+ );
815
+ }
816
+ render() {
817
+ return n`<div class="baht-range">
818
+ ${this.label ? n`<label class="baht-label" for=${this.inputId}>${this.label}</label>` : h}
819
+ <div class="baht-range-row">
820
+ <input
821
+ type="range"
822
+ id=${this.inputId}
823
+ aria-label=${this.label ? h : "Value"}
824
+ .value=${rt(String(this.value))}
825
+ min=${this.min}
826
+ max=${this.max}
827
+ step=${this.step}
828
+ ?disabled=${this.disabled}
829
+ @input=${(t) => this.onInput(t)}
830
+ />
831
+ ${this.showValue ? n`<span class="baht-range-value">${this.value}</span>` : h}
832
+ </div>
833
+ </div>`;
834
+ }
835
+ };
836
+ ut([
837
+ l({ type: Number })
838
+ ], it.prototype, "value", 2);
839
+ ut([
840
+ l({ type: Number })
841
+ ], it.prototype, "min", 2);
842
+ ut([
843
+ l({ type: Number })
844
+ ], it.prototype, "max", 2);
845
+ ut([
846
+ l({ type: Number })
847
+ ], it.prototype, "step", 2);
848
+ ut([
849
+ l()
850
+ ], it.prototype, "label", 2);
851
+ ut([
852
+ l({ type: Boolean })
853
+ ], it.prototype, "disabled", 2);
854
+ ut([
855
+ l({ type: Boolean, attribute: "show-value" })
856
+ ], it.prototype, "showValue", 2);
857
+ it = ut([
858
+ u("baht-range")
859
+ ], it);
860
+ var As = Object.defineProperty, Ls = Object.getOwnPropertyDescriptor, jt = (t, e, i, a) => {
861
+ for (var s = a > 1 ? void 0 : a ? Ls(e, i) : e, r = t.length - 1, o; r >= 0; r--)
862
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
863
+ return a && s && As(e, i, s), s;
864
+ };
865
+ let mt = class extends $ {
866
+ constructor() {
867
+ super(...arguments), this.length = 6, this.value = "", this.disabled = !1, this.mode = "numeric", this.label = "One-time code", this._chars = [], this._lastValue = "", this._wasFull = !1;
868
+ }
869
+ inputs() {
870
+ return Array.from(this.querySelectorAll("input"));
871
+ }
872
+ clean(t) {
873
+ return this.mode === "numeric" ? t.replace(/\D/g, "") : t;
874
+ }
875
+ willUpdate(t) {
876
+ super.willUpdate(t);
877
+ const e = t.has("value") && this.value !== this._lastValue;
878
+ !this.hasUpdated || e ? (this._chars = Array.from({ length: this.length }, (i, a) => this.value[a] ?? ""), this._lastValue = this.value, this._wasFull = this._chars.length > 0 && this._chars.every((i) => i !== "")) : this._chars.length !== this.length && (this._chars = Array.from({ length: this.length }, (i, a) => this._chars[a] ?? ""));
879
+ }
880
+ /** Writes `text` into `_chars` starting at `start`. Returns the index just
881
+ * past the last box written (may equal `this.length`). */
882
+ fill(t, e) {
883
+ let i = t;
884
+ for (const a of e) {
885
+ if (i >= this.length) break;
886
+ this._chars[i] = a, i += 1;
887
+ }
888
+ return i;
889
+ }
890
+ commit() {
891
+ const t = this._chars.join("").slice(0, this.length);
892
+ this.value = t, this._lastValue = t, this.requestUpdate(), this.dispatchEvent(
893
+ new CustomEvent("baht-change", {
894
+ detail: { value: this.value },
895
+ bubbles: !0,
896
+ composed: !0
897
+ })
898
+ );
899
+ const e = this._chars.length > 0 && this._chars.every((i) => i !== "");
900
+ e && !this._wasFull && this.dispatchEvent(
901
+ new CustomEvent("baht-otp-complete", {
902
+ detail: { value: this.value },
903
+ bubbles: !0,
904
+ composed: !0
905
+ })
906
+ ), this._wasFull = e;
907
+ }
908
+ onInput(t, e) {
909
+ var r, o;
910
+ const i = e.target, a = this.clean(i.value);
911
+ if (a.length > 1) {
912
+ const c = this.fill(t, a);
913
+ i.value = this._chars[t] ?? "", this.commit(), (r = this.inputs()[Math.min(c, this.length - 1)]) == null || r.focus();
914
+ return;
915
+ }
916
+ const s = a.slice(-1);
917
+ i.value = s, this._chars[t] = s, this.commit(), s && t < this.length - 1 && ((o = this.inputs()[t + 1]) == null || o.focus());
918
+ }
919
+ onKeydown(t, e) {
920
+ var i;
921
+ e.key === "Backspace" && !this._chars[t] && t > 0 && (this._chars[t - 1] = "", this.commit(), (i = this.inputs()[t - 1]) == null || i.focus(), e.preventDefault());
922
+ }
923
+ onPaste(t) {
924
+ var a, s;
925
+ t.preventDefault();
926
+ const e = this.clean(((a = t.clipboardData) == null ? void 0 : a.getData("text")) ?? "").slice(0, this.length);
927
+ if (!e) return;
928
+ const i = this.fill(0, e);
929
+ this.commit(), (s = this.inputs()[Math.min(i, this.length - 1)]) == null || s.focus();
930
+ }
931
+ render() {
932
+ return n`<div class="baht-otp" role="group" aria-label=${this.label} @paste=${(t) => this.onPaste(t)}>
933
+ ${this._chars.map(
934
+ (t, e) => n`<input
935
+ type="text"
936
+ inputmode=${this.mode === "numeric" ? "numeric" : "text"}
937
+ maxlength="1"
938
+ autocomplete=${e === 0 ? "one-time-code" : "off"}
939
+ aria-label=${v("otpCharacter", { i: e + 1, n: this.length })}
940
+ .value=${t}
941
+ ?disabled=${this.disabled}
942
+ @input=${(i) => this.onInput(e, i)}
943
+ @keydown=${(i) => this.onKeydown(e, i)}
944
+ />`
945
+ )}
946
+ </div>`;
947
+ }
948
+ };
949
+ jt([
950
+ l({ type: Number })
951
+ ], mt.prototype, "length", 2);
952
+ jt([
953
+ l()
954
+ ], mt.prototype, "value", 2);
955
+ jt([
956
+ l({ type: Boolean })
957
+ ], mt.prototype, "disabled", 2);
958
+ jt([
959
+ l()
960
+ ], mt.prototype, "mode", 2);
961
+ jt([
962
+ l()
963
+ ], mt.prototype, "label", 2);
964
+ mt = jt([
965
+ u("baht-otp")
966
+ ], mt);
967
+ var Ns = Object.defineProperty, qs = Object.getOwnPropertyDescriptor, St = (t, e, i, a) => {
968
+ for (var s = a > 1 ? void 0 : a ? qs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
969
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
970
+ return a && s && Ns(e, i, s), s;
971
+ };
972
+ let vt = class extends $ {
973
+ constructor() {
974
+ super(...arguments), this.options = [], this.selected = [], this.multiple = !0, this.disabled = !1, this.label = "Filters";
975
+ }
976
+ toggle(t) {
977
+ const e = this.selected.includes(t);
978
+ let i;
979
+ this.multiple ? (i = e ? this.selected.filter((s) => s !== t) : [...this.selected, t], i = this.options.map((s) => s.key).filter((s) => i.includes(s))) : i = e ? [] : [t], this.dispatchEvent(
980
+ new CustomEvent("baht-change", { detail: { selected: i }, bubbles: !0, composed: !0 })
981
+ );
982
+ }
983
+ render() {
984
+ return n`<div class="baht-filter" role="group" aria-label=${this.label}>
985
+ ${this.options.map(
986
+ (t) => n`<button
987
+ type="button"
988
+ aria-pressed=${this.selected.includes(t.key)}
989
+ ?disabled=${this.disabled}
990
+ @click=${() => this.toggle(t.key)}
991
+ >${t.label}</button>`
992
+ )}
993
+ </div>`;
994
+ }
995
+ };
996
+ St([
997
+ l({ attribute: !1 })
998
+ ], vt.prototype, "options", 2);
999
+ St([
1000
+ l({ attribute: !1 })
1001
+ ], vt.prototype, "selected", 2);
1002
+ St([
1003
+ l({ type: Boolean })
1004
+ ], vt.prototype, "multiple", 2);
1005
+ St([
1006
+ l({ type: Boolean })
1007
+ ], vt.prototype, "disabled", 2);
1008
+ St([
1009
+ l()
1010
+ ], vt.prototype, "label", 2);
1011
+ vt = St([
1012
+ u("baht-filter")
1013
+ ], vt);
1014
+ var Rs = Object.defineProperty, zs = Object.getOwnPropertyDescriptor, ce = (t, e, i, a) => {
1015
+ for (var s = a > 1 ? void 0 : a ? zs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1016
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
1017
+ return a && s && Rs(e, i, s), s;
1018
+ };
1019
+ let Vt = class extends $ {
1020
+ constructor() {
1021
+ super(...arguments), this.variant = "rect", this.width = "100%", this.height = "";
1022
+ }
1023
+ render() {
1024
+ const t = this.height || (this.variant === "text" ? "1em" : "20px"), e = this.variant === "rect" ? "" : ` baht-skeleton--${this.variant}`;
1025
+ return n`<span
1026
+ class="baht-skeleton${e}"
1027
+ style="width:${this.width}; height:${t};"
1028
+ aria-hidden="true"
1029
+ ></span>`;
1030
+ }
1031
+ };
1032
+ ce([
1033
+ l()
1034
+ ], Vt.prototype, "variant", 2);
1035
+ ce([
1036
+ l()
1037
+ ], Vt.prototype, "width", 2);
1038
+ ce([
1039
+ l()
1040
+ ], Vt.prototype, "height", 2);
1041
+ Vt = ce([
1042
+ u("baht-skeleton")
1043
+ ], Vt);
1044
+ var Vs = Object.defineProperty, Ks = Object.getOwnPropertyDescriptor, Jt = (t, e, i, a) => {
1045
+ for (var s = a > 1 ? void 0 : a ? Ks(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1046
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
1047
+ return a && s && Vs(e, i, s), s;
1048
+ };
1049
+ let kt = class extends $ {
1050
+ constructor() {
1051
+ super(...arguments), this.value = null, this.tone = "primary", this.showLabel = !1, this.label = "Progress";
1052
+ }
1053
+ render() {
1054
+ const t = this.value == null || Number.isNaN(this.value), e = t ? 0 : Math.min(100, Math.max(0, this.value)), i = this.tone === "primary" ? "" : ` baht-progress--${this.tone}`;
1055
+ return n`<div>
1056
+ <div
1057
+ class="baht-progress${i}${t ? " baht-progress--indeterminate" : ""}"
1058
+ role="progressbar"
1059
+ aria-label=${this.label}
1060
+ aria-valuemin="0"
1061
+ aria-valuemax="100"
1062
+ aria-valuenow=${t ? h : e}
1063
+ >
1064
+ <div class="baht-progress-bar" style=${t ? h : `width:${e}%`}></div>
1065
+ </div>
1066
+ ${this.showLabel && !t ? n`<div class="baht-progress-label">${e}%</div>` : h}
1067
+ </div>`;
1068
+ }
1069
+ };
1070
+ Jt([
1071
+ l({ type: Number })
1072
+ ], kt.prototype, "value", 2);
1073
+ Jt([
1074
+ l()
1075
+ ], kt.prototype, "tone", 2);
1076
+ Jt([
1077
+ l({ type: Boolean, attribute: "show-label" })
1078
+ ], kt.prototype, "showLabel", 2);
1079
+ Jt([
1080
+ l()
1081
+ ], kt.prototype, "label", 2);
1082
+ kt = Jt([
1083
+ u("baht-progress")
1084
+ ], kt);
1085
+ var Us = Object.defineProperty, Hs = Object.getOwnPropertyDescriptor, je = (t, e, i, a) => {
1086
+ for (var s = a > 1 ? void 0 : a ? Hs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1087
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
1088
+ return a && s && Us(e, i, s), s;
1089
+ };
1090
+ let ie = class extends $ {
1091
+ constructor() {
1092
+ super(...arguments), this.size = "md", this.label = "Loading";
1093
+ }
1094
+ render() {
1095
+ const t = this.size === "md" ? "" : ` baht-spinner--${this.size}`;
1096
+ return n`<span class="baht-spinner${t}" role="status" aria-label=${this.label}></span>`;
1097
+ }
1098
+ };
1099
+ je([
1100
+ l()
1101
+ ], ie.prototype, "size", 2);
1102
+ je([
1103
+ l()
1104
+ ], ie.prototype, "label", 2);
1105
+ ie = je([
1106
+ u("baht-spinner")
1107
+ ], ie);
1108
+ var Gs = Object.defineProperty, Ws = Object.getOwnPropertyDescriptor, Yt = (t, e, i, a) => {
1109
+ for (var s = a > 1 ? void 0 : a ? Ws(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1110
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
1111
+ return a && s && Gs(e, i, s), s;
1112
+ };
1113
+ let Pt = class extends $ {
1114
+ constructor() {
1115
+ super(...arguments), this.heading = "", this.subtitle = "", this.hero = !1;
1116
+ }
1117
+ firstUpdated() {
1118
+ ne(this, this.bodyEl);
1119
+ }
1120
+ render() {
1121
+ return n`<div class="baht-card${this.hero ? " baht-card--hero" : ""}">
1122
+ ${this.heading ? n`<div class="baht-card-title">${this.heading}</div>` : h}
1123
+ ${this.subtitle ? n`<div class="baht-card-subtitle">${this.subtitle}</div>` : h}
1124
+ <div class="baht-card-body"></div>
1125
+ </div>`;
1126
+ }
1127
+ };
1128
+ Yt([
1129
+ l()
1130
+ ], Pt.prototype, "heading", 2);
1131
+ Yt([
1132
+ l()
1133
+ ], Pt.prototype, "subtitle", 2);
1134
+ Yt([
1135
+ l({ type: Boolean })
1136
+ ], Pt.prototype, "hero", 2);
1137
+ Yt([
1138
+ Et(".baht-card-body")
1139
+ ], Pt.prototype, "bodyEl", 2);
1140
+ Pt = Yt([
1141
+ u("baht-card")
1142
+ ], Pt);
1143
+ var Js = Object.defineProperty, Ys = Object.getOwnPropertyDescriptor, pe = (t, e, i, a) => {
1144
+ for (var s = a > 1 ? void 0 : a ? Ys(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1145
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
1146
+ return a && s && Js(e, i, s), s;
1147
+ };
1148
+ let Kt = class extends $ {
1149
+ constructor() {
1150
+ super(...arguments), this.legend = "", this.disabled = !1;
1151
+ }
1152
+ firstUpdated() {
1153
+ ne(this, this.bodyEl);
1154
+ }
1155
+ render() {
1156
+ return n`<fieldset class="baht-fieldset" ?disabled=${this.disabled}>
1157
+ ${this.legend ? n`<legend>${this.legend}</legend>` : h}
1158
+ <div class="baht-fieldset-body"></div>
1159
+ </fieldset>`;
1160
+ }
1161
+ };
1162
+ pe([
1163
+ l()
1164
+ ], Kt.prototype, "legend", 2);
1165
+ pe([
1166
+ l({ type: Boolean })
1167
+ ], Kt.prototype, "disabled", 2);
1168
+ pe([
1169
+ Et(".baht-fieldset-body")
1170
+ ], Kt.prototype, "bodyEl", 2);
1171
+ Kt = pe([
1172
+ u("baht-fieldset")
1173
+ ], Kt);
1174
+ var Xs = Object.defineProperty, Zs = Object.getOwnPropertyDescriptor, rs = (t, e, i, a) => {
1175
+ for (var s = a > 1 ? void 0 : a ? Zs(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1176
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
1177
+ return a && s && Xs(e, i, s), s;
1178
+ };
1179
+ let Ce = class extends $ {
1180
+ constructor() {
1181
+ super(...arguments), this.items = [];
1182
+ }
1183
+ render() {
1184
+ return n`<div class="baht-timeline" role="list">
1185
+ ${this.items.map(
1186
+ (t, e) => n`<div class="baht-timeline-item" role="listitem">
1187
+ <div class="baht-timeline-rail">
1188
+ <span class="baht-timeline-dot${t.tone && t.tone !== "primary" ? ` baht-timeline-dot--${t.tone}` : ""}"></span>
1189
+ ${e < this.items.length - 1 ? n`<span class="baht-timeline-line"></span>` : h}
1190
+ </div>
1191
+ <div class="baht-timeline-main">
1192
+ <div class="baht-timeline-title">
1193
+ ${t.title}
1194
+ ${t.time ? n`<span class="baht-timeline-time"> · ${t.time}</span>` : h}
1195
+ </div>
1196
+ ${t.description ? n`<div class="baht-timeline-desc">${t.description}</div>` : h}
1197
+ </div>
1198
+ </div>`
1199
+ )}
1200
+ </div>`;
1201
+ }
1202
+ };
1203
+ rs([
1204
+ l({ attribute: !1 })
1205
+ ], Ce.prototype, "items", 2);
1206
+ Ce = rs([
1207
+ u("baht-timeline")
1208
+ ], Ce);
1209
+ var Qs = Object.defineProperty, ta = Object.getOwnPropertyDescriptor, de = (t, e, i, a) => {
1210
+ for (var s = a > 1 ? void 0 : a ? ta(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1211
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
1212
+ return a && s && Qs(e, i, s), s;
1213
+ };
1214
+ let Ot = class extends $ {
1215
+ constructor() {
1216
+ super(...arguments), this.items = [], this.multiple = !1, this.openSet = /* @__PURE__ */ new Set(), this.itemsFingerprint = "";
1217
+ }
1218
+ static fingerprint(t) {
1219
+ return JSON.stringify(t.map((e) => [e.title, e.content]));
1220
+ }
1221
+ willUpdate(t) {
1222
+ if (t.has("items")) {
1223
+ const e = Ot.fingerprint(this.items);
1224
+ e !== this.itemsFingerprint && (this.itemsFingerprint = e, this.openSet = new Set(this.items.flatMap((i, a) => i.open ? [a] : [])));
1225
+ }
1226
+ }
1227
+ toggle(t) {
1228
+ const e = !this.openSet.has(t), i = this.multiple ? new Set(this.openSet) : /* @__PURE__ */ new Set();
1229
+ e ? i.add(t) : i.delete(t), this.openSet = i, this.dispatchEvent(
1230
+ new CustomEvent("baht-toggle", { detail: { index: t, open: e }, bubbles: !0, composed: !0 })
1231
+ );
1232
+ }
1233
+ render() {
1234
+ return n`<div class="baht-accordion">
1235
+ ${this.items.map((t, e) => {
1236
+ const i = this.openSet.has(e), a = `baht-acc-${this.uid}-t-${e}`, s = `baht-acc-${this.uid}-p-${e}`;
1237
+ return n`<div class="baht-accordion-item${i ? " baht-accordion-item--open" : ""}">
1238
+ <button
1239
+ type="button"
1240
+ class="baht-accordion-trigger"
1241
+ id=${a}
1242
+ aria-expanded=${i}
1243
+ aria-controls=${i ? s : h}
1244
+ @click=${() => this.toggle(e)}
1245
+ >
1246
+ <span>${t.title}</span>
1247
+ <span class="baht-accordion-chevron" aria-hidden="true">▾</span>
1248
+ </button>
1249
+ ${i ? n`<div class="baht-accordion-content" id=${s} role="region" aria-labelledby=${a}>${t.content}</div>` : h}
1250
+ </div>`;
1251
+ })}
1252
+ </div>`;
1253
+ }
1254
+ };
1255
+ de([
1256
+ l({ attribute: !1 })
1257
+ ], Ot.prototype, "items", 2);
1258
+ de([
1259
+ l({ type: Boolean })
1260
+ ], Ot.prototype, "multiple", 2);
1261
+ de([
1262
+ y()
1263
+ ], Ot.prototype, "openSet", 2);
1264
+ Ot = de([
1265
+ u("baht-accordion")
1266
+ ], Ot);
1267
+ var ea = Object.defineProperty, sa = Object.getOwnPropertyDescriptor, Xt = (t, e, i, a) => {
1268
+ for (var s = a > 1 ? void 0 : a ? sa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1269
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
1270
+ return a && s && ea(e, i, s), s;
1271
+ };
1272
+ let Ct = class extends $ {
1273
+ constructor() {
1274
+ super(...arguments), this.href = "", this.label = "", this.external = !1, this.externalHint = "opens in new tab";
1275
+ }
1276
+ render() {
1277
+ return n`<a
1278
+ class="baht-link"
1279
+ href=${this.href || h}
1280
+ target=${this.external ? "_blank" : h}
1281
+ rel=${this.external ? "noopener noreferrer" : h}
1282
+ >${this.label}${this.external ? n` <span class="baht-link-external" aria-hidden="true">↗</span><span class="baht-visually-hidden"> (${this.externalHint})</span>` : h}</a>`;
1283
+ }
1284
+ };
1285
+ Xt([
1286
+ l()
1287
+ ], Ct.prototype, "href", 2);
1288
+ Xt([
1289
+ l()
1290
+ ], Ct.prototype, "label", 2);
1291
+ Xt([
1292
+ l({ type: Boolean })
1293
+ ], Ct.prototype, "external", 2);
1294
+ Xt([
1295
+ l({ attribute: "external-hint" })
1296
+ ], Ct.prototype, "externalHint", 2);
1297
+ Ct = Xt([
1298
+ u("baht-link")
1299
+ ], Ct);
1300
+ var aa = Object.defineProperty, ia = Object.getOwnPropertyDescriptor, Se = (t, e, i, a) => {
1301
+ for (var s = a > 1 ? void 0 : a ? ia(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1302
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
1303
+ return a && s && aa(e, i, s), s;
1304
+ };
1305
+ let re = class extends $ {
1306
+ constructor() {
1307
+ super(...arguments), this.items = [], this.separator = "›";
1308
+ }
1309
+ navigate(t, e) {
1310
+ this.dispatchEvent(
1311
+ new CustomEvent("baht-navigate", { detail: { item: t, index: e }, bubbles: !0, composed: !0 })
1312
+ );
1313
+ }
1314
+ render() {
1315
+ const t = this.items.length - 1;
1316
+ return n`<nav class="baht-breadcrumbs" aria-label="Breadcrumb">
1317
+ ${this.items.map((e, i) => {
1318
+ const a = i < t ? n`<span class="baht-breadcrumbs-sep" aria-hidden="true">${this.separator}</span>` : h;
1319
+ return i === t ? n`<span class="baht-breadcrumbs-current" aria-current="page">${e.label}</span>${a}` : e.href ? n`<a class="baht-link" href=${e.href}>${e.label}</a>${a}` : n`<a
1320
+ class="baht-link"
1321
+ href="#"
1322
+ @click=${(s) => {
1323
+ s.preventDefault(), this.navigate(e, i);
1324
+ }}
1325
+ >${e.label}</a>${a}`;
1326
+ })}
1327
+ </nav>`;
1328
+ }
1329
+ };
1330
+ Se([
1331
+ l({ attribute: !1 })
1332
+ ], re.prototype, "items", 2);
1333
+ Se([
1334
+ l()
1335
+ ], re.prototype, "separator", 2);
1336
+ re = Se([
1337
+ u("baht-breadcrumbs")
1338
+ ], re);
1339
+ var ra = Object.getOwnPropertyDescriptor, oa = (t, e, i, a) => {
1340
+ for (var s = a > 1 ? void 0 : a ? ra(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1341
+ (o = t[r]) && (s = o(s) || s);
1342
+ return s;
1343
+ };
1344
+ let Le = class extends W {
1345
+ renderControl() {
1346
+ return n`<input
1347
+ class="baht-control baht-control--text"
1348
+ id=${this.controlId}
1349
+ type=${this.field.type === "email" ? "email" : this.field.type === "password" ? "password" : "text"}
1350
+ .value=${rt(this.shownValue == null ? "" : String(this.shownValue))}
1351
+ placeholder=${L(this.field.placeholder)}
1352
+ maxlength=${L(this.field.max_length)}
1353
+ autocomplete=${L(this.field.autocomplete)}
1354
+ ?disabled=${this.disabled}
1355
+ ?readonly=${this.readonly}
1356
+ ?required=${this.required}
1357
+ aria-invalid=${this.invalid}
1358
+ aria-describedby=${this.describedBy}
1359
+ @input=${(t) => this.emitTyped(t.target.value)}
1360
+ />`;
1361
+ }
1362
+ };
1363
+ Le = oa([
1364
+ u("baht-input")
1365
+ ], Le);
1366
+ var la = Object.getOwnPropertyDescriptor, na = (t, e, i, a) => {
1367
+ for (var s = a > 1 ? void 0 : a ? la(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1368
+ (o = t[r]) && (s = o(s) || s);
1369
+ return s;
1370
+ };
1371
+ let Ne = class extends W {
1372
+ renderControl() {
1373
+ return n`<textarea
1374
+ class="baht-control baht-control--textarea"
1375
+ id=${this.controlId}
1376
+ .value=${rt(this.shownValue == null ? "" : String(this.shownValue))}
1377
+ placeholder=${L(this.field.placeholder)}
1378
+ maxlength=${L(this.field.max_length)}
1379
+ rows=${this.field.rows ?? 3}
1380
+ autocomplete=${L(this.field.autocomplete)}
1381
+ ?disabled=${this.disabled}
1382
+ ?readonly=${this.readonly}
1383
+ ?required=${this.required}
1384
+ aria-invalid=${this.invalid}
1385
+ aria-describedby=${this.describedBy}
1386
+ @input=${(t) => this.emitTyped(t.target.value)}
1387
+ ></textarea>`;
1388
+ }
1389
+ };
1390
+ Ne = na([
1391
+ u("baht-textarea")
1392
+ ], Ne);
1393
+ var ha = Object.getOwnPropertyDescriptor, ca = (t, e, i, a) => {
1394
+ for (var s = a > 1 ? void 0 : a ? ha(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1395
+ (o = t[r]) && (s = o(s) || s);
1396
+ return s;
1397
+ };
1398
+ let qe = class extends W {
1399
+ renderControl() {
1400
+ return n`<input
1401
+ class="baht-control baht-control--number"
1402
+ id=${this.controlId}
1403
+ type="number"
1404
+ .value=${rt(this.shownValue == null ? "" : String(this.shownValue))}
1405
+ placeholder=${L(this.field.placeholder)}
1406
+ min=${L(this.field.min)}
1407
+ max=${L(this.field.max)}
1408
+ step=${L(this.field.step)}
1409
+ ?disabled=${this.disabled}
1410
+ ?readonly=${this.readonly}
1411
+ ?required=${this.required}
1412
+ aria-invalid=${this.invalid}
1413
+ aria-describedby=${this.describedBy}
1414
+ @input=${(t) => {
1415
+ const e = t.target.value;
1416
+ this.emitTyped(e === "" ? null : Number(e));
1417
+ }}
1418
+ />`;
1419
+ }
1420
+ };
1421
+ qe = ca([
1422
+ u("baht-number")
1423
+ ], qe);
1424
+ var pa = Object.defineProperty, da = Object.getOwnPropertyDescriptor, Te = (t, e, i, a) => {
1425
+ for (var s = a > 1 ? void 0 : a ? da(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1426
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
1427
+ return a && s && pa(e, i, s), s;
1428
+ };
1429
+ const ua = 500;
1430
+ let oe = class extends W {
1431
+ constructor() {
1432
+ super(...arguments), this.open = !1, this.active = 0, this.typeBuffer = "", this.onDocMousedown = (t) => {
1433
+ this.contains(t.target) || this.close();
1434
+ };
1435
+ }
1436
+ disconnectedCallback() {
1437
+ super.disconnectedCallback(), clearTimeout(this.typeTimer), q() && document.removeEventListener("mousedown", this.onDocMousedown);
1438
+ }
1439
+ get listId() {
1440
+ return `${this.controlId}-list`;
1441
+ }
1442
+ optionId(t) {
1443
+ return `${this.listId}-${t}`;
1444
+ }
1445
+ /** Placeholder row first (picks `null`), then the field's options. */
1446
+ get rows() {
1447
+ return [
1448
+ { key: "", label: this.field.placeholder ?? v("choose") },
1449
+ ...this.field.options ?? []
1450
+ ];
1451
+ }
1452
+ get currentKey() {
1453
+ return this.value == null ? "" : String(this.value);
1454
+ }
1455
+ get selectedIndex() {
1456
+ const t = this.rows.findIndex((e) => e.key === this.currentKey);
1457
+ return t < 0 ? 0 : t;
1458
+ }
1459
+ get interactive() {
1460
+ return !this.disabled && !this.readonly;
1461
+ }
1462
+ willUpdate(t) {
1463
+ super.willUpdate(t), this.field && t.has("value") && !this.open && (this.active = this.selectedIndex);
1464
+ }
1465
+ updated() {
1466
+ var e;
1467
+ if (!this.open) return;
1468
+ const t = this.querySelector(`#${this.optionId(this.active)}`);
1469
+ (e = t == null ? void 0 : t.scrollIntoView) == null || e.call(t, { block: "nearest" });
1470
+ }
1471
+ openList() {
1472
+ !this.interactive || this.open || (this.active = this.selectedIndex, this.open = !0, q() && document.addEventListener("mousedown", this.onDocMousedown));
1473
+ }
1474
+ close() {
1475
+ this.open && (this.open = !1, q() && document.removeEventListener("mousedown", this.onDocMousedown));
1476
+ }
1477
+ toggle() {
1478
+ this.open ? this.close() : this.openList();
1479
+ }
1480
+ commit(t) {
1481
+ const e = this.rows[t];
1482
+ this.close(), e && this.emitInput(e.key === "" ? null : e.key);
1483
+ }
1484
+ highlight(t) {
1485
+ this.active !== t && (this.active = t);
1486
+ }
1487
+ move(t) {
1488
+ const e = this.rows.length - 1;
1489
+ this.active = Math.min(e, Math.max(0, this.active + t));
1490
+ }
1491
+ /** Type-to-select: first option (after the highlighted one) starting with the buffer. */
1492
+ typeahead(t) {
1493
+ clearTimeout(this.typeTimer), this.typeBuffer += t.toLowerCase(), this.typeTimer = setTimeout(() => this.typeBuffer = "", ua);
1494
+ const e = this.rows, i = this.typeBuffer.length === 1 ? this.active + 1 : this.active;
1495
+ for (let a = 0; a < e.length; a++) {
1496
+ const s = (i + a) % e.length;
1497
+ if (s !== 0 && e[s].label.toLowerCase().startsWith(this.typeBuffer)) {
1498
+ this.open ? this.active = s : this.commit(s);
1499
+ return;
1500
+ }
1501
+ }
1502
+ }
1503
+ onKeydown(t) {
1504
+ if (!this.interactive) return;
1505
+ const { key: e } = t;
1506
+ if (!this.open) {
1507
+ e === "ArrowDown" || e === "ArrowUp" || e === "Enter" || e === " " ? (t.preventDefault(), this.openList()) : e === "Home" || e === "End" ? (t.preventDefault(), this.commit(e === "Home" ? Math.min(1, this.rows.length - 1) : this.rows.length - 1)) : e.length === 1 && !t.altKey && !t.ctrlKey && !t.metaKey && this.typeahead(e);
1508
+ return;
1509
+ }
1510
+ switch (e) {
1511
+ case "ArrowDown":
1512
+ t.preventDefault(), this.move(1);
1513
+ break;
1514
+ case "ArrowUp":
1515
+ t.preventDefault(), this.move(-1);
1516
+ break;
1517
+ case "Home":
1518
+ t.preventDefault(), this.active = 0;
1519
+ break;
1520
+ case "End":
1521
+ t.preventDefault(), this.active = this.rows.length - 1;
1522
+ break;
1523
+ case "Enter":
1524
+ case " ":
1525
+ t.preventDefault(), this.commit(this.active);
1526
+ break;
1527
+ case "Escape":
1528
+ t.preventDefault(), this.close();
1529
+ break;
1530
+ case "Tab":
1531
+ this.commit(this.active);
1532
+ break;
1533
+ default:
1534
+ e.length === 1 && !t.altKey && !t.ctrlKey && !t.metaKey && this.typeahead(e);
1535
+ }
1536
+ }
1537
+ renderControl() {
1538
+ const t = this.rows, e = this.selectedIndex, i = e === 0;
1539
+ return n`<div class="baht-select${this.open ? " baht-select--open" : ""}">
1540
+ <button
1541
+ type="button"
1542
+ class="baht-control baht-control--select baht-select-trigger${i ? " baht-select-trigger--placeholder" : ""}"
1543
+ id=${this.controlId}
1544
+ role="combobox"
1545
+ aria-haspopup="listbox"
1546
+ aria-expanded=${this.open ? "true" : "false"}
1547
+ aria-controls=${this.listId}
1548
+ aria-labelledby=${this.field.label ? this.labelId : h}
1549
+ aria-activedescendant=${this.open ? this.optionId(this.active) : h}
1550
+ aria-required=${this.required ? "true" : h}
1551
+ aria-invalid=${this.invalid}
1552
+ aria-describedby=${this.describedBy}
1553
+ ?disabled=${this.disabled}
1554
+ aria-readonly=${this.readonly && !this.disabled ? "true" : h}
1555
+ @click=${() => this.toggle()}
1556
+ @keydown=${(a) => this.onKeydown(a)}
1557
+ >
1558
+ <span class="baht-select-value">${t[e].label}</span>
1559
+ <span class="baht-select-chevron" aria-hidden="true">▾</span>
1560
+ </button>
1561
+ <div
1562
+ class="baht-listbox baht-select-list"
1563
+ id=${this.listId}
1564
+ role="listbox"
1565
+ aria-labelledby=${this.field.label ? this.labelId : h}
1566
+ ?hidden=${!this.open}
1567
+ >
1568
+ ${t.map(
1569
+ // eslint-disable-next-line lit-a11y/click-events-have-key-events -- keyboard lives on the combobox (aria-activedescendant pattern); options are never focused
1570
+ (a, s) => n`<div
1571
+ class="baht-listbox-option${s === this.active ? " baht-listbox-option--active" : ""}${s === 0 ? " baht-listbox-option--placeholder" : ""}"
1572
+ id=${this.optionId(s)}
1573
+ role="option"
1574
+ aria-selected=${s === e ? "true" : "false"}
1575
+ data-key=${a.key}
1576
+ @mousedown=${(r) => r.preventDefault()}
1577
+ @mousemove=${() => this.highlight(s)}
1578
+ @click=${() => this.commit(s)}
1579
+ >
1580
+ ${a.label}
1581
+ </div>`
1582
+ )}
1583
+ </div>
1584
+ </div>`;
1585
+ }
1586
+ };
1587
+ Te([
1588
+ y()
1589
+ ], oe.prototype, "open", 2);
1590
+ Te([
1591
+ y()
1592
+ ], oe.prototype, "active", 2);
1593
+ oe = Te([
1594
+ u("baht-select")
1595
+ ], oe);
1596
+ var ba = Object.getOwnPropertyDescriptor, fa = (t, e, i, a) => {
1597
+ for (var s = a > 1 ? void 0 : a ? ba(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1598
+ (o = t[r]) && (s = o(s) || s);
1599
+ return s;
1600
+ };
1601
+ let Re = class extends W {
1602
+ get selected() {
1603
+ return Array.isArray(this.value) ? this.value : [];
1604
+ }
1605
+ toggle(t, e) {
1606
+ const i = e ? [...this.selected, t] : this.selected.filter((s) => s !== t), a = (this.field.options ?? []).map((s) => s.key);
1607
+ this.emitInput(a.filter((s) => i.includes(s)));
1608
+ }
1609
+ renderControl() {
1610
+ return n`<div
1611
+ class="baht-control baht-control--multiselect"
1612
+ role="group"
1613
+ aria-labelledby=${this.field.label ? this.labelId : h}
1614
+ aria-describedby=${this.describedBy}
1615
+ >
1616
+ ${(this.field.options ?? []).map(
1617
+ (t) => n`<label class="baht-option">
1618
+ <input
1619
+ type="checkbox"
1620
+ value=${t.key}
1621
+ .checked=${rt(this.selected.includes(t.key))}
1622
+ ?disabled=${this.disabled || this.readonly}
1623
+ @change=${(e) => this.toggle(t.key, e.target.checked)}
1624
+ />
1625
+ <span>${t.label}</span>
1626
+ </label>`
1627
+ )}
1628
+ </div>`;
1629
+ }
1630
+ };
1631
+ Re = fa([
1632
+ u("baht-multiselect")
1633
+ ], Re);
1634
+ var ma = Object.getOwnPropertyDescriptor, va = (t, e, i, a) => {
1635
+ for (var s = a > 1 ? void 0 : a ? ma(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1636
+ (o = t[r]) && (s = o(s) || s);
1637
+ return s;
1638
+ };
1639
+ let ze = class extends W {
1640
+ /** Label sits beside the box, so suppress the block label. */
1641
+ renderLabel() {
1642
+ return h;
1643
+ }
1644
+ renderControl() {
1645
+ return n`<label class="baht-control baht-control--checkbox baht-option">
1646
+ <input
1647
+ type="checkbox"
1648
+ id=${this.controlId}
1649
+ .checked=${rt(this.value === !0)}
1650
+ ?disabled=${this.disabled || this.readonly}
1651
+ ?required=${this.required}
1652
+ aria-invalid=${this.invalid}
1653
+ aria-describedby=${this.describedBy}
1654
+ @change=${(t) => this.emitInput(t.target.checked)}
1655
+ />
1656
+ <span class="baht-label"
1657
+ >${this.field.label}${this.required ? n`<span class="baht-required-mark" aria-hidden="true">*</span>` : h}</span
1658
+ >
1659
+ </label>`;
1660
+ }
1661
+ };
1662
+ ze = va([
1663
+ u("baht-checkbox")
1664
+ ], ze);
1665
+ var $a = Object.getOwnPropertyDescriptor, ya = (t, e, i, a) => {
1666
+ for (var s = a > 1 ? void 0 : a ? $a(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1667
+ (o = t[r]) && (s = o(s) || s);
1668
+ return s;
1669
+ };
1670
+ let Ve = class extends W {
1671
+ renderControl() {
1672
+ return n`<div
1673
+ class="baht-control baht-control--radio"
1674
+ role="radiogroup"
1675
+ aria-labelledby=${this.field.label ? this.labelId : h}
1676
+ aria-required=${this.required ? "true" : h}
1677
+ aria-invalid=${this.invalid}
1678
+ aria-describedby=${this.describedBy}
1679
+ >
1680
+ ${(this.field.options ?? []).map(
1681
+ (t) => n`<label class="baht-option">
1682
+ <input
1683
+ type="radio"
1684
+ name=${this.controlId}
1685
+ value=${t.key}
1686
+ .checked=${rt(this.value === t.key)}
1687
+ ?disabled=${this.disabled || this.readonly}
1688
+ @change=${() => this.emitInput(t.key)}
1689
+ />
1690
+ <span>${t.label}</span>
1691
+ </label>`
1692
+ )}
1693
+ </div>`;
1694
+ }
1695
+ };
1696
+ Ve = ya([
1697
+ u("baht-radio")
1698
+ ], Ve);
1699
+ var ga = Object.getOwnPropertyDescriptor, wa = (t, e, i, a) => {
1700
+ for (var s = a > 1 ? void 0 : a ? ga(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1701
+ (o = t[r]) && (s = o(s) || s);
1702
+ return s;
1703
+ };
1704
+ let Ke = class extends W {
1705
+ renderLabel() {
1706
+ return h;
1707
+ }
1708
+ renderControl() {
1709
+ return n`<label class="baht-control baht-control--toggle baht-option">
1710
+ <input
1711
+ type="checkbox"
1712
+ role="switch"
1713
+ id=${this.controlId}
1714
+ aria-checked=${this.value === !0 ? "true" : "false"}
1715
+ .checked=${rt(this.value === !0)}
1716
+ ?disabled=${this.disabled || this.readonly}
1717
+ ?required=${this.required}
1718
+ aria-invalid=${this.invalid}
1719
+ aria-describedby=${this.describedBy}
1720
+ @change=${(t) => this.emitInput(t.target.checked)}
1721
+ />
1722
+ <span class="baht-toggle-track"><span class="baht-toggle-thumb"></span></span>
1723
+ <span class="baht-label"
1724
+ >${this.field.label}${this.required ? n`<span class="baht-required-mark" aria-hidden="true">*</span>` : h}</span
1725
+ >
1726
+ </label>`;
1727
+ }
1728
+ };
1729
+ Ke = wa([
1730
+ u("baht-toggle")
1731
+ ], Ke);
1732
+ var xa = Object.getOwnPropertyDescriptor, _a = (t, e, i, a) => {
1733
+ for (var s = a > 1 ? void 0 : a ? xa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1734
+ (o = t[r]) && (s = o(s) || s);
1735
+ return s;
1736
+ };
1737
+ let Ue = class extends W {
1738
+ constructor() {
1739
+ super(...arguments), this.lastEmitted = null;
1740
+ }
1741
+ renderControl() {
1742
+ return n`<input
1743
+ class="baht-control baht-control--date"
1744
+ id=${this.controlId}
1745
+ type="text"
1746
+ autocomplete="off"
1747
+ placeholder=${L(this.field.placeholder)}
1748
+ ?disabled=${this.disabled}
1749
+ ?readonly=${this.readonly}
1750
+ ?required=${this.required}
1751
+ aria-invalid=${this.invalid}
1752
+ aria-describedby=${this.describedBy}
1753
+ />`;
1754
+ }
1755
+ connectedCallback() {
1756
+ super.connectedCallback(), this.hasUpdated && this.requestUpdate();
1757
+ }
1758
+ disconnectedCallback() {
1759
+ super.disconnectedCallback(), this.teardown();
1760
+ }
1761
+ updated(t) {
1762
+ const e = this.querySelector("input.baht-control--date");
1763
+ if (!e) {
1764
+ this.teardown();
1765
+ return;
1766
+ }
1767
+ if (!this.fp || this.fp.input !== e || t.has("field") || t.has("disabled") || t.has("readonly")) {
1768
+ this.teardown(), this.fp = vs(e, this.options());
1769
+ return;
1770
+ }
1771
+ t.has("value") && (this.lastEmitted = null, this.syncValue());
1772
+ }
1773
+ teardown() {
1774
+ var t;
1775
+ (t = this.fp) == null || t.destroy(), this.fp = void 0, this.todayBtn = void 0, this.clearBtn = void 0;
1776
+ }
1777
+ /** Push the host-fed `value` into the calendar without echoing an event. */
1778
+ syncValue() {
1779
+ if (!this.fp) return;
1780
+ const t = this.datesOf(this.value);
1781
+ Ge(this.fp.selectedDates, t) || (t.length === 0 ? this.fp.clear(!1) : this.fp.setDate(t, !1));
1782
+ }
1783
+ options() {
1784
+ const t = this.field, e = ve(t), i = Lt(t.min), a = Lt(t.max);
1785
+ return {
1786
+ static: !0,
1787
+ disableMobile: !0,
1788
+ // our calendar everywhere — never the OS date wheel
1789
+ mode: e,
1790
+ dateFormat: t.date_format ?? "Y-m-d",
1791
+ allowInput: !0,
1792
+ clickOpens: !this.disabled && !this.readonly,
1793
+ defaultDate: this.datesOf(this.value),
1794
+ ...i ? { minDate: i } : {},
1795
+ ...a ? { maxDate: a } : {},
1796
+ disable: We(t),
1797
+ onReady: (s, r, o) => this.mountFooter(o),
1798
+ onOpen: () => this.refreshFooter(),
1799
+ onChange: (s) => {
1800
+ this.refreshFooter(), !(e === "range" && s.length === 1) && this.emitIfChanged(s);
1801
+ },
1802
+ onClose: (s) => {
1803
+ var r, o;
1804
+ e === "range" && s.length === 1 && ((r = this.fp) == null || r.clear(!1)), this.emitIfChanged(((o = this.fp) == null ? void 0 : o.selectedDates) ?? []);
1805
+ }
1806
+ };
1807
+ }
1808
+ // ---- footer: Today / Clear ------------------------------------------
1809
+ mountFooter(t) {
1810
+ const e = document.createElement("div");
1811
+ e.className = "baht-datepicker-footer";
1812
+ const i = document.createElement("button");
1813
+ i.type = "button", i.className = "baht-button baht-button--sm baht-datepicker-today", i.textContent = v("today"), i.addEventListener("click", () => this.pickToday());
1814
+ const a = document.createElement("button");
1815
+ a.type = "button", a.className = "baht-button baht-button--danger baht-button--sm baht-datepicker-clear", a.textContent = v("clear"), a.addEventListener("click", () => {
1816
+ var s, r;
1817
+ (s = this.fp) == null || s.clear(), (r = this.fp) == null || r.close();
1818
+ }), e.append(i, a), t.calendarContainer.appendChild(e), this.todayBtn = i, this.clearBtn = a, this.refreshFooter(t);
1819
+ }
1820
+ /** Today greys out when the rules exclude it; Clear when there is nothing to clear.
1821
+ * `fp` is passed explicitly from onReady — it fires inside the flatpickr()
1822
+ * call, before `this.fp` is assigned. */
1823
+ refreshFooter(t = this.fp) {
1824
+ t && (this.todayBtn && (this.todayBtn.disabled = !this.todayAllowed()), this.clearBtn && (this.clearBtn.disabled = t.selectedDates.length === 0));
1825
+ }
1826
+ todayAllowed() {
1827
+ const t = xt(/* @__PURE__ */ new Date()), e = Lt(this.field.min), i = Lt(this.field.max);
1828
+ if (e && t < xt(e) || i && t > xt(i)) return !1;
1829
+ for (const a of We(this.field) ?? [])
1830
+ if (a instanceof Date) {
1831
+ if (He(a, t)) return !1;
1832
+ } else if (typeof a == "function") {
1833
+ if (a(t)) return !1;
1834
+ } else if (typeof a == "object" && "from" in a) {
1835
+ const s = xt(new Date(a.from)), r = xt(new Date(a.to));
1836
+ if (t >= s && t <= r) return !1;
1837
+ }
1838
+ return !0;
1839
+ }
1840
+ pickToday() {
1841
+ const t = this.fp;
1842
+ if (!t || !this.todayAllowed()) return;
1843
+ const e = xt(/* @__PURE__ */ new Date());
1844
+ switch (ve(this.field)) {
1845
+ case "range":
1846
+ t.setDate([e, e], !0);
1847
+ break;
1848
+ case "multiple": {
1849
+ t.selectedDates.some((a) => He(a, e)) || t.setDate([...t.selectedDates, e], !0);
1850
+ break;
1851
+ }
1852
+ default:
1853
+ t.setDate(e, !0);
1854
+ }
1855
+ t.close();
1856
+ }
1857
+ emitIfChanged(t) {
1858
+ const e = this.lastEmitted ?? this.datesOf(this.value);
1859
+ Ge(t, e) || (this.lastEmitted = [...t], this.emitInput(this.toValue(t)));
1860
+ }
1861
+ /** Host value (any mode) -> the Date list flatpickr works with. */
1862
+ datesOf(t) {
1863
+ return ps(t).map(Lt).filter((e) => e !== null);
1864
+ }
1865
+ /** flatpickr's selection -> the value shape of the field's mode. */
1866
+ toValue(t) {
1867
+ const e = t.map(Rt);
1868
+ switch (ve(this.field)) {
1869
+ case "range":
1870
+ return e.length === 2 ? [e[0], e[1]] : null;
1871
+ case "multiple":
1872
+ return e;
1873
+ default:
1874
+ return e[0] ?? null;
1875
+ }
1876
+ }
1877
+ };
1878
+ Ue = _a([
1879
+ u("baht-datepicker")
1880
+ ], Ue);
1881
+ function xt(t) {
1882
+ return new Date(t.getFullYear(), t.getMonth(), t.getDate());
1883
+ }
1884
+ function He(t, e) {
1885
+ return Rt(t) === Rt(e);
1886
+ }
1887
+ function Ge(t, e) {
1888
+ return t.length !== e.length ? !1 : t.every((i, a) => Rt(i) === Rt(e[a]));
1889
+ }
1890
+ function We(t) {
1891
+ const e = [];
1892
+ for (const a of t.disabled_dates ?? []) {
1893
+ const s = ds(a);
1894
+ s && e.push(s[0].getTime() === s[1].getTime() ? s[0] : { from: s[0], to: s[1] });
1895
+ }
1896
+ const i = t.disabled_weekdays;
1897
+ return i != null && i.length && e.push((a) => i.includes(a.getDay())), e;
1898
+ }
1899
+ var ka = Object.defineProperty, Pa = Object.getOwnPropertyDescriptor, Zt = (t, e, i, a) => {
1900
+ for (var s = a > 1 ? void 0 : a ? Pa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
1901
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
1902
+ return a && s && ka(e, i, s), s;
1903
+ };
1904
+ function Je(t) {
1905
+ return t !== null && typeof t == "object" && typeof t.url == "string";
1906
+ }
1907
+ function ye(t) {
1908
+ return t >= 1024 * 1024 ? `${(t / 1024 / 1024).toFixed(1)} MB` : t >= 1024 ? `${Math.round(t / 1024)} KB` : `${t} B`;
1909
+ }
1910
+ let Dt = class extends W {
1911
+ constructor() {
1912
+ super(...arguments), this.uploadingCount = 0, this.uploadError = null, this.rejectedNames = [];
1913
+ }
1914
+ get refs() {
1915
+ return Array.isArray(this.value) ? this.value.filter(Je) : Je(this.value) ? [this.value] : [];
1916
+ }
1917
+ emitRefs(t) {
1918
+ this.emitInput(this.field.multiple ? t : t[0] ?? null);
1919
+ }
1920
+ async uploadAll(t) {
1921
+ if (!this.uploader) return;
1922
+ this.uploadError = null, this.uploadingCount += t.length;
1923
+ const e = this.field.multiple ? [...this.refs] : [];
1924
+ for (const i of t)
1925
+ try {
1926
+ e.push(await this.uploader(i));
1927
+ } catch {
1928
+ this.uploadError = v("uploadFailed");
1929
+ } finally {
1930
+ this.uploadingCount -= 1;
1931
+ }
1932
+ this.emitRefs(e);
1933
+ }
1934
+ onPick(t) {
1935
+ const e = t.target;
1936
+ this.take(Array.from(e.files ?? []), e);
1937
+ }
1938
+ take(t, e) {
1939
+ const i = this.field.max_size, a = i ? t.filter((r) => r.size <= i) : t, s = i ? t.filter((r) => r.size > i) : [];
1940
+ if (this.rejectedNames = s.map((r) => r.name), this.uploader) {
1941
+ e && (e.value = ""), this.uploadAll(a);
1942
+ return;
1943
+ }
1944
+ this.emitInput(this.field.multiple ? a : a[0] ?? null);
1945
+ }
1946
+ get captured() {
1947
+ return this.uploader ? [] : Array.isArray(this.value) ? this.value.filter((t) => t instanceof File) : this.value instanceof File ? [this.value] : [];
1948
+ }
1949
+ hintText() {
1950
+ const t = [];
1951
+ return this.field.accept && t.push(
1952
+ this.field.accept.split(",").map((e) => e.trim()).join(", ")
1953
+ ), this.field.max_size && t.push(v("uploadMaxSize", { size: ye(this.field.max_size) })), t.join(" · ");
1954
+ }
1955
+ renderControl() {
1956
+ const t = this.disabled || this.readonly || this.uploadingCount > 0, e = this.hintText(), i = [
1957
+ "baht-dropzone",
1958
+ t ? "baht-dropzone--disabled" : "",
1959
+ this.invalid === "true" ? "baht-dropzone--invalid" : ""
1960
+ ].filter(Boolean).join(" ");
1961
+ return n`<div
1962
+ class=${i}
1963
+ @dragover=${(a) => {
1964
+ t || (a.preventDefault(), a.currentTarget.classList.add("baht-dropzone--over"));
1965
+ }}
1966
+ @dragleave=${(a) => a.currentTarget.classList.remove("baht-dropzone--over")}
1967
+ @drop=${(a) => {
1968
+ var s;
1969
+ a.preventDefault(), a.currentTarget.classList.remove("baht-dropzone--over"), t || this.take(Array.from(((s = a.dataTransfer) == null ? void 0 : s.files) ?? []));
1970
+ }}
1971
+ >
1972
+ <input
1973
+ class="baht-control baht-control--file baht-dropzone-input"
1974
+ id=${this.controlId}
1975
+ type="file"
1976
+ accept=${L(this.field.accept)}
1977
+ ?multiple=${this.field.multiple}
1978
+ ?disabled=${t}
1979
+ ?required=${this.required}
1980
+ aria-invalid=${this.invalid}
1981
+ aria-describedby=${this.describedBy}
1982
+ @change=${(a) => this.onPick(a)}
1983
+ />
1984
+ <span class="baht-dropzone-icon" aria-hidden="true">${U("upload")}</span>
1985
+ <span class="baht-dropzone-text">
1986
+ <label class="baht-dropzone-action" for=${this.controlId}
1987
+ >${this.field.multiple ? v("chooseFiles") : v("chooseFile")}</label
1988
+ >
1989
+ <span class="baht-dropzone-or">${v("orDropHere")}</span>
1990
+ </span>
1991
+ ${e ? n`<span class="baht-dropzone-hint">${e}</span>` : h}
1992
+ </div>
1993
+ ${this.uploadingCount > 0 ? n`<p class="baht-file-status" role="status">${v("uploading")}</p>` : h}
1994
+ ${this.uploadError ? n`<p class="baht-error" role="alert">${this.uploadError}</p>` : h}
1995
+ ${this.rejectedNames.length > 0 ? n`<p class="baht-error baht-file-rejected" role="alert">
1996
+ ${v("fileRejectedTooLarge", { names: this.rejectedNames.join(", ") })}
1997
+ </p>` : h}
1998
+ ${this.captured.map(
1999
+ (a) => n`<span class="baht-file-chip">
2000
+ <span class="baht-file-name">${a.name}</span>
2001
+ <span class="baht-file-size">${ye(a.size)}</span>
2002
+ </span>`
2003
+ )}
2004
+ ${this.refs.map(
2005
+ (a) => n`<span class="baht-file-chip">
2006
+ <a href=${a.url} target="_blank" rel="noreferrer"
2007
+ >${a.name}<span class="baht-visually-hidden"> (${v("opensInNewTab")})</span></a
2008
+ >
2009
+ <span class="baht-file-size">${ye(a.size)}</span>
2010
+ ${this.disabled || this.readonly ? h : n`<button
2011
+ type="button"
2012
+ class="baht-file-remove"
2013
+ aria-label=${v("removeFile")}
2014
+ title=${v("removeFile")}
2015
+ @click=${() => this.emitRefs(this.refs.filter((s) => s !== a))}
2016
+ >
2017
+ ${U("close")}
2018
+ </button>`}
2019
+ </span>`
2020
+ )}`;
2021
+ }
2022
+ };
2023
+ Zt([
2024
+ l({ attribute: !1 })
2025
+ ], Dt.prototype, "uploader", 2);
2026
+ Zt([
2027
+ y()
2028
+ ], Dt.prototype, "uploadingCount", 2);
2029
+ Zt([
2030
+ y()
2031
+ ], Dt.prototype, "uploadError", 2);
2032
+ Zt([
2033
+ y()
2034
+ ], Dt.prototype, "rejectedNames", 2);
2035
+ Dt = Zt([
2036
+ u("baht-file")
2037
+ ], Dt);
2038
+ var Oa = Object.defineProperty, Ca = Object.getOwnPropertyDescriptor, I = (t, e, i, a) => {
2039
+ for (var s = a > 1 ? void 0 : a ? Ca(e, i) : e, r = t.length - 1, o; r >= 0; r--)
2040
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
2041
+ return a && s && Oa(e, i, s), s;
2042
+ };
2043
+ function Da(t, e) {
2044
+ return e.split(".").reduce((i, a) => {
2045
+ if (i !== null && typeof i == "object") return i[a];
2046
+ }, t);
2047
+ }
2048
+ function Fa(t, e) {
2049
+ const i = t.trim();
2050
+ if (!i) return null;
2051
+ try {
2052
+ const a = JSON.parse(i);
2053
+ if (typeof a == "string") return a;
2054
+ const s = e ? Da(a, e) : a;
2055
+ return typeof s == "string" && s ? s : null;
2056
+ } catch {
2057
+ return /^(https?:\/\/|\/|data:|blob:)/.test(i) ? i : null;
2058
+ }
2059
+ }
2060
+ function Ea(t) {
2061
+ const i = (t.split(/[?#]/)[0] ?? t).split("/").filter(Boolean).pop() ?? t;
2062
+ try {
2063
+ return decodeURIComponent(i);
2064
+ } catch {
2065
+ return i;
2066
+ }
2067
+ }
2068
+ function ge(t) {
2069
+ return t >= 1024 * 1024 ? `${(t / 1024 / 1024).toFixed(1)} MB` : t >= 1024 ? `${Math.round(t / 1024)} KB` : `${t} B`;
2070
+ }
2071
+ let F = class extends $ {
2072
+ constructor() {
2073
+ super(...arguments), this.url = "", this.method = "POST", this.fieldName = "file", this.responseKey = "url", this.headers = {}, this.withCredentials = !1, this.value = null, this.label = "", this.hint = "", this.multiple = !1, this.disabled = !1, this.required = !1, this.error = null, this.pending = [], this.rejectedNames = [], this.dragging = !1, this.known = /* @__PURE__ */ new Map(), this.seq = 0;
2074
+ }
2075
+ get urls() {
2076
+ return Array.isArray(this.value) ? this.value.filter((t) => typeof t == "string" && t) : typeof this.value == "string" && this.value ? [this.value] : [];
2077
+ }
2078
+ get inputId() {
2079
+ return `baht-upload-${this.uid}`;
2080
+ }
2081
+ fileFor(t) {
2082
+ return this.known.get(t) ?? { name: Ea(t), size: 0, url: t };
2083
+ }
2084
+ /** Empty the value (does not delete anything on the server). */
2085
+ clear() {
2086
+ this.emitValue([]);
2087
+ }
2088
+ emitValue(t) {
2089
+ const e = this.multiple ? t : t[0] ?? null;
2090
+ this.value = e, this.dispatchEvent(
2091
+ new CustomEvent("baht-change", {
2092
+ detail: { value: e, files: t.map((i) => this.fileFor(i)) },
2093
+ bubbles: !0,
2094
+ composed: !0
2095
+ })
2096
+ );
2097
+ }
2098
+ accept_(t) {
2099
+ if (this.disabled || t.length === 0) return;
2100
+ const e = this.maxSize, i = e ? t.filter((s) => s.size <= e) : t;
2101
+ this.rejectedNames = e ? t.filter((s) => s.size > e).map((s) => s.name) : [];
2102
+ const a = this.multiple ? i : i.slice(0, 1);
2103
+ for (const s of a) this.start(s);
2104
+ }
2105
+ onPick(t) {
2106
+ const e = t.target;
2107
+ this.accept_(Array.from(e.files ?? [])), e.value = "";
2108
+ }
2109
+ onDragOver(t) {
2110
+ this.disabled || (t.preventDefault(), this.dragging = !0);
2111
+ }
2112
+ onDragLeave() {
2113
+ this.dragging = !1;
2114
+ }
2115
+ onDrop(t) {
2116
+ var e;
2117
+ t.preventDefault(), this.dragging = !1, this.accept_(Array.from(((e = t.dataTransfer) == null ? void 0 : e.files) ?? []));
2118
+ }
2119
+ start(t) {
2120
+ const e = { id: ++this.seq, file: t, percent: 0, error: null };
2121
+ this.pending = this.multiple ? [...this.pending, e] : [e], this.dispatchEvent(
2122
+ new CustomEvent("baht-upload-start", { detail: { file: t }, bubbles: !0, composed: !0 })
2123
+ ), this.send(e);
2124
+ }
2125
+ patch(t, e) {
2126
+ this.pending = this.pending.map((i) => i.id === t ? { ...i, ...e } : i);
2127
+ }
2128
+ send(t) {
2129
+ const e = new XMLHttpRequest();
2130
+ e.open(this.method || "POST", this.url);
2131
+ for (const [a, s] of Object.entries(this.headers ?? {})) e.setRequestHeader(a, s);
2132
+ e.withCredentials = this.withCredentials, e.upload.onprogress = (a) => {
2133
+ const s = a.total > 0 ? Math.round(a.loaded / a.total * 100) : 0;
2134
+ this.patch(t.id, { percent: s }), this.dispatchEvent(
2135
+ new CustomEvent("baht-upload-progress", {
2136
+ detail: { file: t.file, loaded: a.loaded, total: a.total, percent: s },
2137
+ bubbles: !0,
2138
+ composed: !0
2139
+ })
2140
+ );
2141
+ }, e.onload = () => {
2142
+ const a = e.status >= 200 && e.status < 300, s = a ? Fa(e.responseText, this.responseKey) : null;
2143
+ if (!a || !s) return this.failed(t, a ? 0 : e.status);
2144
+ this.known.set(s, {
2145
+ name: t.file.name,
2146
+ size: t.file.size,
2147
+ type: t.file.type || void 0,
2148
+ url: s
2149
+ }), this.pending = this.pending.filter((r) => r.id !== t.id), this.emitValue(this.multiple ? [...this.urls, s] : [s]);
2150
+ }, e.onerror = () => this.failed(t, 0);
2151
+ const i = new FormData();
2152
+ i.append(this.fieldName || "file", t.file, t.file.name), e.send(i);
2153
+ }
2154
+ failed(t, e) {
2155
+ const i = v("uploadFailed");
2156
+ this.patch(t.id, { error: i, percent: 0 }), this.dispatchEvent(
2157
+ new CustomEvent("baht-upload-error", {
2158
+ detail: { file: t.file, status: e, message: i },
2159
+ bubbles: !0,
2160
+ composed: !0
2161
+ })
2162
+ );
2163
+ }
2164
+ retry(t) {
2165
+ this.patch(t.id, { error: null, percent: 0 }), this.send({ ...t, error: null, percent: 0 });
2166
+ }
2167
+ dismiss(t) {
2168
+ this.pending = this.pending.filter((e) => e.id !== t.id);
2169
+ }
2170
+ defaultHint() {
2171
+ const t = [];
2172
+ return this.accept && t.push(
2173
+ this.accept.split(",").map((e) => e.trim()).join(", ")
2174
+ ), this.maxSize && t.push(v("uploadMaxSize", { size: ge(this.maxSize) })), t.join(" · ");
2175
+ }
2176
+ render() {
2177
+ const t = this.pending.some((c) => !c.error), e = !!this.error, i = this.hint || this.defaultHint(), a = i ? `${this.inputId}-hint` : void 0, s = this.error ? `${this.inputId}-error` : void 0, r = [a, s].filter(Boolean).join(" ") || void 0, o = [
2178
+ "baht-dropzone",
2179
+ this.dragging ? "baht-dropzone--over" : "",
2180
+ this.disabled ? "baht-dropzone--disabled" : "",
2181
+ e ? "baht-dropzone--invalid" : ""
2182
+ ].filter(Boolean).join(" ");
2183
+ return n`<div class="baht-field baht-field--upload">
2184
+ ${this.label ? n`<label class="baht-label" for=${this.inputId}
2185
+ >${this.label}${this.required ? n`<span class="baht-required-mark" aria-hidden="true">*</span>` : h}</label
2186
+ >` : h}
2187
+ <div
2188
+ class=${o}
2189
+ @dragover=${this.onDragOver}
2190
+ @dragleave=${this.onDragLeave}
2191
+ @drop=${this.onDrop}
2192
+ >
2193
+ <input
2194
+ class="baht-dropzone-input"
2195
+ id=${this.inputId}
2196
+ type="file"
2197
+ accept=${L(this.accept)}
2198
+ ?multiple=${this.multiple}
2199
+ ?disabled=${this.disabled}
2200
+ ?required=${this.required}
2201
+ aria-invalid=${e ? "true" : "false"}
2202
+ aria-describedby=${L(r)}
2203
+ @change=${(c) => this.onPick(c)}
2204
+ />
2205
+ <span class="baht-dropzone-icon" aria-hidden="true">${U("upload")}</span>
2206
+ <span class="baht-dropzone-text">
2207
+ <label class="baht-dropzone-action" for=${this.inputId}
2208
+ >${this.multiple ? v("chooseFiles") : v("chooseFile")}</label
2209
+ >
2210
+ <span class="baht-dropzone-or">${v("orDropHere")}</span>
2211
+ </span>
2212
+ ${i ? n`<span class="baht-dropzone-hint" id=${L(a)}>${i}</span>` : h}
2213
+ </div>
2214
+
2215
+ ${this.pending.length > 0 || this.urls.length > 0 ? n`<ul class="baht-upload-list" aria-live="polite" aria-busy=${t ? "true" : "false"}>
2216
+ ${this.urls.map((c) => this.renderStored(c))}
2217
+ ${this.pending.map((c) => this.renderPending(c))}
2218
+ </ul>` : h}
2219
+ ${this.rejectedNames.length > 0 ? n`<p class="baht-error" role="alert">
2220
+ ${v("fileRejectedTooLarge", { names: this.rejectedNames.join(", ") })}
2221
+ </p>` : h}
2222
+ ${this.error ? n`<p class="baht-error" id=${L(s)} role="alert">${this.error}</p>` : h}
2223
+ </div>`;
2224
+ }
2225
+ renderStored(t) {
2226
+ const e = this.fileFor(t);
2227
+ return n`<li class="baht-file-chip baht-file-chip--done">
2228
+ <span class="baht-file-chip-icon" aria-hidden="true">${U("check")}</span>
2229
+ <a class="baht-file-name" href=${t} target="_blank" rel="noreferrer"
2230
+ >${e.name}<span class="baht-visually-hidden"> (${v("opensInNewTab")})</span></a
2231
+ >
2232
+ ${e.size > 0 ? n`<span class="baht-file-size">${ge(e.size)}</span>` : h}
2233
+ ${this.disabled ? h : n`<button
2234
+ type="button"
2235
+ class="baht-file-remove"
2236
+ aria-label=${v("removeFile")}
2237
+ title=${v("removeFile")}
2238
+ @click=${() => this.emitValue(this.urls.filter((i) => i !== t))}
2239
+ >
2240
+ ${U("close")}
2241
+ </button>`}
2242
+ </li>`;
2243
+ }
2244
+ renderPending(t) {
2245
+ return n`<li class="baht-file-chip ${t.error ? "baht-file-chip--error" : "baht-file-chip--busy"}">
2246
+ <span class="baht-file-name">${t.file.name}</span>
2247
+ <span class="baht-file-size">${ge(t.file.size)}</span>
2248
+ ${t.error ? n`<span class="baht-file-status baht-file-status--error" role="alert">${t.error}</span>
2249
+ <button type="button" class="baht-upload-retry" @click=${() => this.retry(t)}>
2250
+ ${v("retry")}
2251
+ </button>
2252
+ <button
2253
+ type="button"
2254
+ class="baht-file-remove"
2255
+ aria-label=${v("removeFile")}
2256
+ title=${v("removeFile")}
2257
+ @click=${() => this.dismiss(t)}
2258
+ >
2259
+ ${U("close")}
2260
+ </button>` : n`<span
2261
+ class="baht-upload-bar"
2262
+ role="progressbar"
2263
+ aria-label=${v("uploading")}
2264
+ aria-valuemin="0"
2265
+ aria-valuemax="100"
2266
+ aria-valuenow=${String(t.percent)}
2267
+ ><span class="baht-upload-bar-fill" style="width:${t.percent}%"></span
2268
+ ></span>`}
2269
+ </li>`;
2270
+ }
2271
+ };
2272
+ I([
2273
+ l()
2274
+ ], F.prototype, "url", 2);
2275
+ I([
2276
+ l()
2277
+ ], F.prototype, "method", 2);
2278
+ I([
2279
+ l({ attribute: "field-name" })
2280
+ ], F.prototype, "fieldName", 2);
2281
+ I([
2282
+ l({ attribute: "response-key" })
2283
+ ], F.prototype, "responseKey", 2);
2284
+ I([
2285
+ l({ attribute: !1 })
2286
+ ], F.prototype, "headers", 2);
2287
+ I([
2288
+ l({ type: Boolean, attribute: "with-credentials" })
2289
+ ], F.prototype, "withCredentials", 2);
2290
+ I([
2291
+ l({ attribute: !1 })
2292
+ ], F.prototype, "value", 2);
2293
+ I([
2294
+ l()
2295
+ ], F.prototype, "label", 2);
2296
+ I([
2297
+ l()
2298
+ ], F.prototype, "hint", 2);
2299
+ I([
2300
+ l()
2301
+ ], F.prototype, "accept", 2);
2302
+ I([
2303
+ l({ type: Boolean })
2304
+ ], F.prototype, "multiple", 2);
2305
+ I([
2306
+ l({ type: Number, attribute: "max-size" })
2307
+ ], F.prototype, "maxSize", 2);
2308
+ I([
2309
+ l({ type: Boolean })
2310
+ ], F.prototype, "disabled", 2);
2311
+ I([
2312
+ l({ type: Boolean })
2313
+ ], F.prototype, "required", 2);
2314
+ I([
2315
+ l()
2316
+ ], F.prototype, "error", 2);
2317
+ I([
2318
+ y()
2319
+ ], F.prototype, "pending", 2);
2320
+ I([
2321
+ y()
2322
+ ], F.prototype, "rejectedNames", 2);
2323
+ I([
2324
+ y()
2325
+ ], F.prototype, "dragging", 2);
2326
+ F = I([
2327
+ u("baht-upload")
2328
+ ], F);
2329
+ var Ba = Object.defineProperty, Ia = Object.getOwnPropertyDescriptor, os = (t, e, i, a) => {
2330
+ for (var s = a > 1 ? void 0 : a ? Ia(e, i) : e, r = t.length - 1, o; r >= 0; r--)
2331
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
2332
+ return a && s && Ba(e, i, s), s;
2333
+ };
2334
+ let De = class extends $ {
2335
+ render() {
2336
+ if (!this.field) return h;
2337
+ const t = this.field.variant ?? "body";
2338
+ return n`<div class="baht-text baht-text--${t}">${this.field.text ?? this.field.label ?? ""}</div>`;
2339
+ }
2340
+ };
2341
+ os([
2342
+ l({ attribute: !1 })
2343
+ ], De.prototype, "field", 2);
2344
+ De = os([
2345
+ u("baht-text")
2346
+ ], De);
2347
+ var ja = Object.defineProperty, Sa = Object.getOwnPropertyDescriptor, ls = (t, e, i, a) => {
2348
+ for (var s = a > 1 ? void 0 : a ? Sa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
2349
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
2350
+ return a && s && ja(e, i, s), s;
2351
+ };
2352
+ let Fe = class extends $ {
2353
+ render() {
2354
+ return this.field ? n`<div class="baht-section">
2355
+ <span class="baht-section-label">${this.field.text ?? this.field.label ?? ""}</span>
2356
+ </div>` : h;
2357
+ }
2358
+ };
2359
+ ls([
2360
+ l({ attribute: !1 })
2361
+ ], Fe.prototype, "field", 2);
2362
+ Fe = ls([
2363
+ u("baht-section")
2364
+ ], Fe);
2365
+ var Ta = Object.defineProperty, Ma = Object.getOwnPropertyDescriptor, ue = (t, e, i, a) => {
2366
+ for (var s = a > 1 ? void 0 : a ? Ma(e, i) : e, r = t.length - 1, o; r >= 0; r--)
2367
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
2368
+ return a && s && Ta(e, i, s), s;
2369
+ };
2370
+ let Ut = class extends $ {
2371
+ constructor() {
2372
+ super(...arguments), this.total = 0, this.label = "", this.color = "";
2373
+ }
2374
+ render() {
2375
+ return n`<div class="baht-stat-chart">
2376
+ <div
2377
+ class="baht-stat-chart-total"
2378
+ style=${this.color ? `color:${this.color}` : h}
2379
+ >${this.total.toLocaleString("en-US")}</div>
2380
+ ${this.label ? n`<div class="baht-stat-chart-label">${this.label}</div>` : h}
2381
+ </div>`;
2382
+ }
2383
+ };
2384
+ ue([
2385
+ l({ type: Number })
2386
+ ], Ut.prototype, "total", 2);
2387
+ ue([
2388
+ l()
2389
+ ], Ut.prototype, "label", 2);
2390
+ ue([
2391
+ l()
2392
+ ], Ut.prototype, "color", 2);
2393
+ Ut = ue([
2394
+ u("baht-stat-chart")
2395
+ ], Ut);
2396
+ var Aa = Object.defineProperty, Tt = (t, e, i, a) => {
2397
+ for (var s = void 0, r = t.length - 1, o; r >= 0; r--)
2398
+ (o = t[r]) && (s = o(e, i, s) || s);
2399
+ return s && Aa(e, i, s), s;
2400
+ };
2401
+ const La = 10;
2402
+ function lt(t, e) {
2403
+ return e && t === 0 ? e : `var(--baht-chart-${t % La + 1})`;
2404
+ }
2405
+ function Ye(t, e = 5) {
2406
+ return `var(--baht-chart-seq-${Math.min(e - 1, Math.max(0, t)) + 1})`;
2407
+ }
2408
+ function qt(t, e = "number", i = "THB") {
2409
+ if (!Number.isFinite(t)) return "—";
2410
+ switch (e) {
2411
+ case "currency":
2412
+ return new Intl.NumberFormat("en-US", {
2413
+ style: "currency",
2414
+ currency: i || "THB",
2415
+ currencyDisplay: "narrowSymbol",
2416
+ maximumFractionDigits: 0
2417
+ }).format(t).replace(/THB\s?/, "฿");
2418
+ case "percent":
2419
+ return new Intl.NumberFormat("en-US", {
2420
+ style: "percent",
2421
+ maximumFractionDigits: 1
2422
+ }).format(t);
2423
+ case "compact":
2424
+ return new Intl.NumberFormat("en-US", {
2425
+ notation: "compact",
2426
+ maximumFractionDigits: 1
2427
+ }).format(t);
2428
+ default:
2429
+ return new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(t);
2430
+ }
2431
+ }
2432
+ function Ee(t, e = 4) {
2433
+ if (!Number.isFinite(t) || t <= 0) return [0, 1];
2434
+ const i = t / (Math.max(1, e) + 1), a = 10 ** Math.floor(Math.log10(i)), s = [1, 2, 2.5, 5, 10].map((c) => c * a).find((c) => c >= i - 1e-9) ?? 10 * a, r = Math.ceil(t / s) * s, o = [];
2435
+ for (let c = 0; c <= r + s / 1e3; c += s) o.push(Number(c.toFixed(10)));
2436
+ return o;
2437
+ }
2438
+ function le(t, e) {
2439
+ const [i, a] = t, [s, r] = e, o = a - i;
2440
+ return !Number.isFinite(o) || o === 0 ? () => s : (c) => s + (c - i) / o * (r - s);
2441
+ }
2442
+ function Na(t, e, i = "Other") {
2443
+ if (t.length <= e) return t;
2444
+ const a = t.slice(0, e - 1), s = t.slice(e - 1).reduce((r, o) => r + o.count, 0);
2445
+ return [...a, { label: i, count: s }];
2446
+ }
2447
+ function be(t, e, i, a = "View as table") {
2448
+ return n`<details class="baht-chart-table">
2449
+ <summary>${a}</summary>
2450
+ <table>
2451
+ <caption>${t}</caption>
2452
+ <thead>
2453
+ <tr>
2454
+ ${e.map((s) => n`<th scope="col">${s}</th>`)}
2455
+ </tr>
2456
+ </thead>
2457
+ <tbody>
2458
+ ${i.map(
2459
+ (s) => n`<tr>
2460
+ ${s.map(
2461
+ (r, o) => o === 0 ? n`<th scope="row">${r}</th>` : n`<td class="baht-chart-num">${r}</td>`
2462
+ )}
2463
+ </tr>`
2464
+ )}
2465
+ </tbody>
2466
+ </table>
2467
+ </details>`;
2468
+ }
2469
+ class Q extends $ {
2470
+ constructor() {
2471
+ super(...arguments), this.emptyMessage = "No data to chart", this.loading = !1, this.showTable = !0, this.format = "number", this.currency = "THB", this.held = null;
2472
+ }
2473
+ /** Value → display text using this chart's `format` / `currency`. */
2474
+ fmt(e) {
2475
+ return qt(e, this.format, this.currency);
2476
+ }
2477
+ /**
2478
+ * The snapshot to draw. While `loading` is set the previous one is returned,
2479
+ * so a refetch dims the chart instead of emptying it.
2480
+ */
2481
+ hold(e) {
2482
+ return this.loading ? this.held ?? e : (this.held = e, e);
2483
+ }
2484
+ /** Root class list: `baht-chart` plus the loading modifier. */
2485
+ rootClass(e) {
2486
+ return `baht-chart ${e}${this.loading ? " baht-chart--loading" : ""}`;
2487
+ }
2488
+ /** The single floating tooltip node; rendered by the template, never appended. */
2489
+ renderTooltip() {
2490
+ return n`<div class="baht-chart-tooltip" role="status" aria-live="polite" hidden></div>`;
2491
+ }
2492
+ /**
2493
+ * Show `text` near the pointer (or, on keyboard focus, near the mark).
2494
+ * Content is assigned with `textContent`: category and series names are
2495
+ * untrusted data (interaction.md).
2496
+ */
2497
+ showTip(e, i) {
2498
+ var g;
2499
+ const a = this.tipEl;
2500
+ if (!a) return;
2501
+ a.textContent = i, a.hidden = !1;
2502
+ const s = this.querySelector(".baht-chart");
2503
+ if (!s || typeof s.getBoundingClientRect != "function") return;
2504
+ const r = s.getBoundingClientRect(), o = e;
2505
+ let c, m;
2506
+ if (typeof o.clientX == "number" && (o.clientX !== 0 || o.clientY !== 0))
2507
+ c = o.clientX - r.left, m = o.clientY - r.top;
2508
+ else {
2509
+ const _ = e.currentTarget, p = (g = _ == null ? void 0 : _.getBoundingClientRect) == null ? void 0 : g.call(_);
2510
+ c = p ? p.left + p.width / 2 - r.left : 0, m = p ? p.top - r.top : 0;
2511
+ }
2512
+ a.style.left = `${Math.round(c)}px`, a.style.top = `${Math.round(m)}px`;
2513
+ }
2514
+ /** Hide the tooltip (pointerleave / blur). */
2515
+ hideTip() {
2516
+ const e = this.tipEl;
2517
+ e && (e.hidden = !0, e.textContent = "");
2518
+ }
2519
+ /** The empty placeholder, or `nothing` when there is data. */
2520
+ renderEmpty() {
2521
+ return n`<div class="baht-chart-empty">${this.emptyMessage}</div>`;
2522
+ }
2523
+ /** Legend rows — only ever rendered for 2+ series (marks-and-anatomy.md). */
2524
+ renderLegend(e, i = "rect") {
2525
+ return e.length < 2 ? h : n`<div class="baht-chart-legend">
2526
+ ${e.map(
2527
+ (a) => n`<div class="baht-chart-legend-row">
2528
+ <span
2529
+ class="baht-chart-swatch${i === "line" ? " baht-chart-swatch--line" : ""}"
2530
+ style="background:${a.color}"
2531
+ aria-hidden="true"
2532
+ ></span>
2533
+ <span class="baht-chart-legend-label">${a.label}</span>
2534
+ ${a.value ? n`<span class="baht-chart-legend-count">${a.value}</span>` : h}
2535
+ ${a.share ? n`<span class="baht-chart-legend-pct">${a.share}</span>` : h}
2536
+ </div>`
2537
+ )}
2538
+ </div>`;
2539
+ }
2540
+ }
2541
+ Tt([
2542
+ l({ attribute: "empty-message" })
2543
+ ], Q.prototype, "emptyMessage");
2544
+ Tt([
2545
+ l({ type: Boolean, reflect: !0 })
2546
+ ], Q.prototype, "loading");
2547
+ Tt([
2548
+ l({ type: Boolean, attribute: "show-table" })
2549
+ ], Q.prototype, "showTable");
2550
+ Tt([
2551
+ l()
2552
+ ], Q.prototype, "format");
2553
+ Tt([
2554
+ l()
2555
+ ], Q.prototype, "currency");
2556
+ Tt([
2557
+ Et(".baht-chart-tooltip")
2558
+ ], Q.prototype, "tipEl");
2559
+ var qa = Object.defineProperty, Ra = Object.getOwnPropertyDescriptor, yt = (t, e, i, a) => {
2560
+ for (var s = a > 1 ? void 0 : a ? Ra(e, i) : e, r = t.length - 1, o; r >= 0; r--)
2561
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
2562
+ return a && s && qa(e, i, s), s;
2563
+ };
2564
+ let ht = class extends $ {
2565
+ constructor() {
2566
+ super(...arguments), this.values = [], this.width = 96, this.height = 24, this.accentLast = !0, this.color = "", this.label = "";
2567
+ }
2568
+ render() {
2569
+ const t = (this.values ?? []).filter((k) => Number.isFinite(k));
2570
+ if (t.length < 2) return h;
2571
+ const e = Math.max(16, this.width), i = Math.max(8, this.height), a = 3, s = Math.min(...t), r = Math.max(...t), o = le([0, t.length - 1], [a, e - a]), c = le([s, r === s ? s + 1 : r], [i - a, a]), m = t.map((k, b) => `${o(b).toFixed(2)},${c(k).toFixed(2)}`).join(" "), g = o(t.length - 1), _ = c(t[t.length - 1]), p = this.color || "var(--baht-chart-muted)", f = this.label || `Trend of ${t.length} points`;
2572
+ return n`<svg
2573
+ class="baht-sparkline"
2574
+ width=${e}
2575
+ height=${i}
2576
+ viewBox="0 0 ${e} ${i}"
2577
+ role="img"
2578
+ aria-label=${f}
2579
+ >
2580
+ ${A`<polyline class="baht-sparkline-line" points=${m} fill="none" stroke=${p}/>`}
2581
+ ${this.accentLast ? A`<circle class="baht-sparkline-dot" cx=${g.toFixed(2)} cy=${_.toFixed(2)} r="3"
2582
+ fill="var(--baht-chart-1)"/>` : h}
2583
+ </svg>`;
2584
+ }
2585
+ };
2586
+ yt([
2587
+ l({ type: Array })
2588
+ ], ht.prototype, "values", 2);
2589
+ yt([
2590
+ l({ type: Number })
2591
+ ], ht.prototype, "width", 2);
2592
+ yt([
2593
+ l({ type: Number })
2594
+ ], ht.prototype, "height", 2);
2595
+ yt([
2596
+ l({ type: Boolean, attribute: "accent-last" })
2597
+ ], ht.prototype, "accentLast", 2);
2598
+ yt([
2599
+ l()
2600
+ ], ht.prototype, "color", 2);
2601
+ yt([
2602
+ l()
2603
+ ], ht.prototype, "label", 2);
2604
+ ht = yt([
2605
+ u("baht-sparkline")
2606
+ ], ht);
2607
+ var za = Object.defineProperty, Va = Object.getOwnPropertyDescriptor, J = (t, e, i, a) => {
2608
+ for (var s = a > 1 ? void 0 : a ? Va(e, i) : e, r = t.length - 1, o; r >= 0; r--)
2609
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
2610
+ return a && s && za(e, i, s), s;
2611
+ };
2612
+ let z = class extends $ {
2613
+ constructor() {
2614
+ super(...arguments), this.label = "", this.value = 0, this.format = "number", this.currency = "THB", this.delta = null, this.deltaKind = "pct", this.deltaLabel = "", this.upIsGood = !0, this.trend = [], this.size = "md";
2615
+ }
2616
+ /** Direction of the delta paired with whether up is good. */
2617
+ get tone() {
2618
+ const t = this.delta;
2619
+ return t == null || !Number.isFinite(t) || t === 0 ? "flat" : t > 0 === this.upIsGood ? "good" : "bad";
2620
+ }
2621
+ get arrow() {
2622
+ const t = this.delta ?? 0;
2623
+ return t > 0 ? "↑" : t < 0 ? "↓" : "→";
2624
+ }
2625
+ get deltaText() {
2626
+ const t = this.delta ?? 0, e = Math.abs(t);
2627
+ return this.deltaKind === "pct" ? `${qt(e / 100, "percent")}` : qt(e, this.format, this.currency);
2628
+ }
2629
+ render() {
2630
+ const t = this.delta != null && Number.isFinite(this.delta), e = this.tone, i = (this.delta ?? 0) > 0 ? "up" : (this.delta ?? 0) < 0 ? "down" : "flat";
2631
+ return n`<div class="baht-stat${this.size === "hero" ? " baht-stat--hero" : ""}">
2632
+ ${this.label ? n`<div class="baht-stat-label">${this.label}</div>` : h}
2633
+ <div class="baht-stat-value">${qt(this.value, this.format, this.currency)}</div>
2634
+ ${t ? n`<div class="baht-stat-delta baht-stat-delta--${e}">
2635
+ <span class="baht-stat-arrow" aria-hidden="true">${this.arrow}</span>
2636
+ <span class="baht-stat-delta-value">${this.deltaText}</span>
2637
+ <span class="baht-visually-hidden">${i}</span>
2638
+ ${this.deltaLabel ? n`<span class="baht-stat-delta-label">${this.deltaLabel}</span>` : h}
2639
+ </div>` : h}
2640
+ ${this.trend.length > 1 ? n`<baht-sparkline
2641
+ class="baht-stat-trend"
2642
+ .values=${this.trend}
2643
+ label=${`${this.label || "Value"} trend, ${this.trend.length} points`}
2644
+ ></baht-sparkline>` : h}
2645
+ </div>`;
2646
+ }
2647
+ };
2648
+ J([
2649
+ l()
2650
+ ], z.prototype, "label", 2);
2651
+ J([
2652
+ l({ type: Number })
2653
+ ], z.prototype, "value", 2);
2654
+ J([
2655
+ l()
2656
+ ], z.prototype, "format", 2);
2657
+ J([
2658
+ l()
2659
+ ], z.prototype, "currency", 2);
2660
+ J([
2661
+ l({ type: Number })
2662
+ ], z.prototype, "delta", 2);
2663
+ J([
2664
+ l({ attribute: "delta-kind" })
2665
+ ], z.prototype, "deltaKind", 2);
2666
+ J([
2667
+ l({ attribute: "delta-label" })
2668
+ ], z.prototype, "deltaLabel", 2);
2669
+ J([
2670
+ l({ type: Boolean, attribute: "up-is-good" })
2671
+ ], z.prototype, "upIsGood", 2);
2672
+ J([
2673
+ l({ type: Array })
2674
+ ], z.prototype, "trend", 2);
2675
+ J([
2676
+ l()
2677
+ ], z.prototype, "size", 2);
2678
+ z = J([
2679
+ u("baht-stat")
2680
+ ], z);
2681
+ var Ka = Object.defineProperty, Ua = Object.getOwnPropertyDescriptor, Mt = (t, e, i, a) => {
2682
+ for (var s = a > 1 ? void 0 : a ? Ua(e, i) : e, r = t.length - 1, o; r >= 0; r--)
2683
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
2684
+ return a && s && Ka(e, i, s), s;
2685
+ };
2686
+ const Xe = 6;
2687
+ let H = class extends Q {
2688
+ constructor() {
2689
+ super(...arguments), this.groups = [], this.total = null, this.color = "", this.centerLabel = "records", this.otherLabel = "Other";
2690
+ }
2691
+ render() {
2692
+ const t = this.hold(this.groups ?? []);
2693
+ if (t.length === 0)
2694
+ return n`<div class=${this.rootClass("baht-donut-chart")}>${this.renderEmpty()}</div>`;
2695
+ const e = Na(t, Xe, this.otherLabel), i = e.reduce((p, f) => p + f.count, 0) || 1, a = this.total ?? t.reduce((p, f) => p + f.count, 0), s = H.R, r = 2 * Math.PI * s, o = e.length > 1 ? H.GAP : 0, c = t.length > Xe;
2696
+ let m = 0;
2697
+ const g = e.map((p, f) => {
2698
+ const k = p.count / i, b = Math.max(0, k * r - o), w = {
2699
+ ...p,
2700
+ frac: k,
2701
+ dash: `${b} ${r - b}`,
2702
+ offset: -m * r,
2703
+ // the folded tail is grey — never a generated ninth hue
2704
+ color: c && f === e.length - 1 ? "var(--baht-chart-muted)" : lt(f, this.color || void 0)
2705
+ };
2706
+ return m += k, w;
2707
+ }), _ = `${a} ${this.centerLabel}: ${g.map((p) => `${p.label || "(empty)"} ${p.count} (${Math.round(p.frac * 100)}%)`).join(", ")}`;
2708
+ return n`<div class=${this.rootClass("baht-donut-chart")}>
2709
+ <svg width="160" height="160" viewBox="0 0 160 160" role="img" aria-label=${_}>
2710
+ <g transform="translate(80,80) rotate(-90)">
2711
+ ${g.map(
2712
+ (p) => A`<circle r=${s} cx="0" cy="0" fill="none" stroke=${p.color}
2713
+ stroke-width="22" stroke-dasharray=${p.dash} stroke-dashoffset=${p.offset}/>`
2714
+ )}
2715
+ </g>
2716
+ <text x="80" y="76" text-anchor="middle" class="baht-donut-chart-total">${this.fmt(a)}</text>
2717
+ <text x="80" y="94" text-anchor="middle" class="baht-donut-chart-sub">${this.centerLabel}</text>
2718
+ </svg>
2719
+ <div class="baht-chart-legend">
2720
+ ${g.map(
2721
+ (p) => n`<div class="baht-chart-legend-row">
2722
+ <span class="baht-chart-swatch" style="background:${p.color}" aria-hidden="true"></span>
2723
+ <span class="baht-chart-legend-label">${p.label || "(empty)"}</span>
2724
+ <span class="baht-chart-legend-count">${this.fmt(p.count)}</span>
2725
+ <span class="baht-chart-legend-pct">(${Math.round(p.frac * 100)}%)</span>
2726
+ </div>`
2727
+ )}
2728
+ </div>
2729
+ ${this.showTable ? be(
2730
+ `${a} ${this.centerLabel}`,
2731
+ ["Slice", "Value", "Share"],
2732
+ g.map((p) => [
2733
+ p.label || "(empty)",
2734
+ this.fmt(p.count),
2735
+ `${Math.round(p.frac * 100)}%`
2736
+ ])
2737
+ ) : h}
2738
+ </div>`;
2739
+ }
2740
+ };
2741
+ H.R = 54;
2742
+ H.GAP = 2;
2743
+ Mt([
2744
+ l({ attribute: !1 })
2745
+ ], H.prototype, "groups", 2);
2746
+ Mt([
2747
+ l({ type: Number })
2748
+ ], H.prototype, "total", 2);
2749
+ Mt([
2750
+ l()
2751
+ ], H.prototype, "color", 2);
2752
+ Mt([
2753
+ l({ attribute: "center-label" })
2754
+ ], H.prototype, "centerLabel", 2);
2755
+ Mt([
2756
+ l({ attribute: "other-label" })
2757
+ ], H.prototype, "otherLabel", 2);
2758
+ H = Mt([
2759
+ u("baht-donut-chart")
2760
+ ], H);
2761
+ var Ha = Object.defineProperty, Ga = Object.getOwnPropertyDescriptor, K = (t, e, i, a) => {
2762
+ for (var s = a > 1 ? void 0 : a ? Ga(e, i) : e, r = t.length - 1, o; r >= 0; r--)
2763
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
2764
+ return a && s && Ha(e, i, s), s;
2765
+ };
2766
+ const Ze = 24;
2767
+ let R = class extends Q {
2768
+ constructor() {
2769
+ super(...arguments), this.groups = [], this.series = [], this.categories = [], this.orientation = "horizontal", this.stacked = !1, this.compare = [], this.markers = [], this.labelValues = "ends", this.emphasis = null, this.color = "", this.label = "";
2770
+ }
2771
+ /** The series actually drawn — `groups` is normalised into one series. */
2772
+ get model() {
2773
+ var e;
2774
+ if ((e = this.series) != null && e.length)
2775
+ return { series: this.series, categories: this.categories ?? [], legacy: !1 };
2776
+ const t = this.groups ?? [];
2777
+ return {
2778
+ series: t.length ? [{ name: this.label || "Value", values: t.map((i) => i.count) }] : [],
2779
+ categories: t.map((i) => i.label),
2780
+ legacy: !0
2781
+ };
2782
+ }
2783
+ colorFor(t, e, i) {
2784
+ const a = this.model.series[t];
2785
+ return this.emphasis != null && !(i ? t === this.emphasis : e === this.emphasis) ? "var(--baht-chart-muted)" : lt(i ? t : 0, this.color || (a == null ? void 0 : a.color) || void 0);
2786
+ }
2787
+ render() {
2788
+ const t = this.hold(this.model);
2789
+ return t.series.length === 0 ? n`<div class=${this.rootClass("baht-bar-chart")}>${this.renderEmpty()}</div>` : this.orientation === "vertical" ? this.renderVertical(t) : this.renderHorizontal(t);
2790
+ }
2791
+ /** Largest value a bar can reach: the raw max for `groups`, a clean tick otherwise. */
2792
+ domainMax(t, e, i) {
2793
+ const a = Math.max(...t.map((c) => c.values.length)), s = Array.from(
2794
+ { length: a },
2795
+ (c, m) => e ? t.reduce((g, _) => g + (_.values[m] ?? 0), 0) : Math.max(...t.map((g) => g.values[m] ?? 0))
2796
+ ), r = Math.max(
2797
+ 1,
2798
+ ...s,
2799
+ ...this.compare ?? [],
2800
+ ...(this.markers ?? []).map((c) => c.value)
2801
+ );
2802
+ if (i) return r;
2803
+ const o = Ee(r, 4);
2804
+ return o[o.length - 1] ?? r;
2805
+ }
2806
+ tableTwin(t, e, i) {
2807
+ var s;
2808
+ if (!this.showTable) return h;
2809
+ const a = ["Category", ...t.map((r) => r.name || "Value")];
2810
+ return (s = this.compare) != null && s.length && a.push("Previous"), be(
2811
+ this.label || "Bar chart data",
2812
+ a,
2813
+ Array.from({ length: i }, (r, o) => {
2814
+ var m;
2815
+ const c = [
2816
+ e[o] || "(empty)",
2817
+ ...t.map((g) => this.fmt(g.values[o] ?? 0))
2818
+ ];
2819
+ return (m = this.compare) != null && m.length && c.push(this.fmt(this.compare[o] ?? 0)), c;
2820
+ })
2821
+ );
2822
+ }
2823
+ /** Markers with no `category` span the chart; the rest ride their own row. */
2824
+ markersFor(t) {
2825
+ return (this.markers ?? []).filter((e) => !e.category || e.category === t);
2826
+ }
2827
+ markerOverlay(t, e) {
2828
+ return this.markersFor(e).map(
2829
+ (i) => n`<span
2830
+ class="baht-bar-chart-marker"
2831
+ style=${`left:${Math.min(100, i.value / t * 100).toFixed(2)}%`}
2832
+ title=${i.label ?? this.fmt(i.value)}
2833
+ aria-hidden="true"
2834
+ ></span>`
2835
+ );
2836
+ }
2837
+ renderHorizontal(t) {
2838
+ const { series: e, categories: i, legacy: a } = t, s = e.length > 1, r = Math.max(...e.map((p) => p.values.length)), o = this.domainMax(e, this.stacked, a), c = (this.compare ?? []).length > 0, m = (this.stacked ? 1 : e.length) + (c ? 1 : 0), g = Math.min(Ze, Math.max(6, Math.floor(48 / m))), _ = Array.from({ length: r }, (p, f) => {
2839
+ const k = i[f] || "(empty)", b = e.reduce((O, At) => O + (At.values[f] ?? 0), 0), w = `${k}: ${e.map((O) => `${O.name ? `${O.name} ` : ""}${this.fmt(O.values[f] ?? 0)}`).join(", ")}${c ? `, previous ${this.fmt(this.compare[f] ?? 0)}` : ""}`, D = e.map((O, At) => ({
2840
+ value: O.values[f] ?? 0,
2841
+ color: this.colorFor(At, f, s),
2842
+ name: O.name
2843
+ }));
2844
+ return n`<div class="baht-bar-chart-row">
2845
+ <span class="baht-bar-chart-label" title=${k}>${k}</span>
2846
+ <div
2847
+ class="baht-bar-chart-track${this.stacked ? " baht-bar-chart-track--stacked" : ""}"
2848
+ tabindex="0"
2849
+ role="button"
2850
+ aria-label=${w}
2851
+ @pointermove=${(O) => this.showTip(O, w)}
2852
+ @pointerleave=${() => this.hideTip()}
2853
+ @focus=${(O) => this.showTip(O, w)}
2854
+ @blur=${() => this.hideTip()}
2855
+ >
2856
+ ${this.markerOverlay(o, k)}
2857
+ <div class="baht-bar-chart-bars">
2858
+ ${this.stacked ? n`<div class="baht-bar-chart-stack" style=${`height:${g}px`}>
2859
+ ${D.map(
2860
+ (O) => n`<div
2861
+ class="baht-bar-chart-bar baht-bar-chart-bar--segment"
2862
+ style=${`width:${Math.max(0, O.value / o * 100)}%;background:${O.color}`}
2863
+ ></div>`
2864
+ )}
2865
+ </div>` : D.map(
2866
+ (O) => n`<div
2867
+ class="baht-bar-chart-bar"
2868
+ style=${`width:${Math.max(2, O.value / o * 100)}%;height:${g}px;background:${O.color}`}
2869
+ ></div>`
2870
+ )}
2871
+ ${c ? n`<div
2872
+ class="baht-bar-chart-bar baht-bar-chart-bar--compare"
2873
+ style=${`width:${Math.max(2, (this.compare[f] ?? 0) / o * 100)}%;height:${Math.min(8, g)}px`}
2874
+ ></div>` : h}
2875
+ </div>
2876
+ </div>
2877
+ ${this.labelValues === "ends" ? n`<span class="baht-bar-chart-count"
2878
+ >${a ? e[0].values[f] ?? 0 : this.fmt(this.stacked ? b : e[0].values[f] ?? 0)}</span
2879
+ >` : h}
2880
+ </div>`;
2881
+ });
2882
+ return n`<div class=${this.rootClass("baht-bar-chart")}>
2883
+ ${_}
2884
+ ${this.renderTooltip()}
2885
+ ${this.renderLegend(e.map((p, f) => ({ label: p.name, color: lt(f, p.color) })))}
2886
+ ${this.tableTwin(e, i, r)}
2887
+ </div>`;
2888
+ }
2889
+ renderVertical(t) {
2890
+ const { series: e, categories: i, legacy: a } = t, s = e.length > 1, r = Math.max(...e.map((f) => f.values.length)), o = this.domainMax(e, this.stacked, a), c = Ee(o, 4), m = (this.compare ?? []).length > 0, g = (this.stacked ? 1 : e.length) + (m ? 1 : 0), _ = Math.min(Ze, Math.max(4, Math.floor(48 / g))), p = this.label || `Column chart, ${r} categories. ${i.map((f, k) => `${f} ${this.fmt(e[0].values[k] ?? 0)}`).join(", ")}`;
2891
+ return n`<div class=${this.rootClass("baht-bar-chart baht-bar-chart--vertical")}>
2892
+ <div class="baht-bar-chart-plot" role="img" aria-label=${p}>
2893
+ <div class="baht-bar-chart-yaxis" aria-hidden="true">
2894
+ ${[...c].reverse().map((f) => n`<span class="baht-chart-tick-text">${this.fmt(f)}</span>`)}
2895
+ </div>
2896
+ <div class="baht-bar-chart-grid">
2897
+ ${(this.markers ?? []).filter((f) => !f.category).map(
2898
+ (f) => n`<span
2899
+ class="baht-bar-chart-marker baht-bar-chart-marker--horizontal"
2900
+ style=${`bottom:${Math.min(100, f.value / o * 100).toFixed(2)}%`}
2901
+ title=${f.label ?? this.fmt(f.value)}
2902
+ aria-hidden="true"
2903
+ ></span>`
2904
+ )}
2905
+ ${[...c].reverse().map(() => n`<span class="baht-chart-grid-rule" aria-hidden="true"></span>`)}
2906
+ <div class="baht-bar-chart-columns">
2907
+ ${Array.from({ length: r }, (f, k) => {
2908
+ const b = i[k] || "(empty)", w = `${b}: ${e.map((D) => `${D.name ? `${D.name} ` : ""}${this.fmt(D.values[k] ?? 0)}`).join(", ")}`;
2909
+ return n`<div
2910
+ class="baht-bar-chart-column"
2911
+ tabindex="0"
2912
+ role="button"
2913
+ aria-label=${w}
2914
+ @pointermove=${(D) => this.showTip(D, w)}
2915
+ @pointerleave=${() => this.hideTip()}
2916
+ @focus=${(D) => this.showTip(D, w)}
2917
+ @blur=${() => this.hideTip()}
2918
+ >
2919
+ <div class="baht-bar-chart-column-bars">
2920
+ ${e.map(
2921
+ (D, O) => n`<div
2922
+ class="baht-bar-chart-col"
2923
+ style=${`height:${Math.max(1, (D.values[k] ?? 0) / o * 100)}%;width:${_}px;background:${this.colorFor(O, k, s)}`}
2924
+ ></div>`
2925
+ )}
2926
+ ${m ? n`<div
2927
+ class="baht-bar-chart-col baht-bar-chart-col--compare"
2928
+ style=${`height:${Math.max(1, (this.compare[k] ?? 0) / o * 100)}%;width:${Math.min(8, _)}px`}
2929
+ ></div>` : h}
2930
+ </div>
2931
+ <span class="baht-bar-chart-xlabel">${b}</span>
2932
+ </div>`;
2933
+ })}
2934
+ </div>
2935
+ </div>
2936
+ </div>
2937
+ ${this.renderTooltip()}
2938
+ ${this.renderLegend(e.map((f, k) => ({ label: f.name, color: lt(k, f.color) })))}
2939
+ ${this.tableTwin(e, i, r)}
2940
+ </div>`;
2941
+ }
2942
+ };
2943
+ K([
2944
+ l({ attribute: !1 })
2945
+ ], R.prototype, "groups", 2);
2946
+ K([
2947
+ l({ attribute: !1 })
2948
+ ], R.prototype, "series", 2);
2949
+ K([
2950
+ l({ attribute: !1 })
2951
+ ], R.prototype, "categories", 2);
2952
+ K([
2953
+ l()
2954
+ ], R.prototype, "orientation", 2);
2955
+ K([
2956
+ l({ type: Boolean })
2957
+ ], R.prototype, "stacked", 2);
2958
+ K([
2959
+ l({ attribute: !1 })
2960
+ ], R.prototype, "compare", 2);
2961
+ K([
2962
+ l({ attribute: !1 })
2963
+ ], R.prototype, "markers", 2);
2964
+ K([
2965
+ l({ attribute: "label-values" })
2966
+ ], R.prototype, "labelValues", 2);
2967
+ K([
2968
+ l({ type: Number })
2969
+ ], R.prototype, "emphasis", 2);
2970
+ K([
2971
+ l()
2972
+ ], R.prototype, "color", 2);
2973
+ K([
2974
+ l()
2975
+ ], R.prototype, "label", 2);
2976
+ R = K([
2977
+ u("baht-bar-chart")
2978
+ ], R);
2979
+ var Wa = Object.defineProperty, Ja = Object.getOwnPropertyDescriptor, ot = (t, e, i, a) => {
2980
+ for (var s = a > 1 ? void 0 : a ? Ja(e, i) : e, r = t.length - 1, o; r >= 0; r--)
2981
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
2982
+ return a && s && Wa(e, i, s), s;
2983
+ };
2984
+ const Qe = 640, we = 260, B = { top: 14, right: 72, bottom: 30, left: 60 };
2985
+ let Z = class extends Q {
2986
+ constructor() {
2987
+ super(...arguments), this.series = [], this.categories = [], this.area = !1, this.markers = [], this.forecast = 0, this.baseline = null, this.labelValues = "ends", this.label = "", this.crosshairAt = null;
2988
+ }
2989
+ get plot() {
2990
+ return { w: Qe - B.left - B.right, h: we - B.top - B.bottom };
2991
+ }
2992
+ render() {
2993
+ const t = this.hold({
2994
+ series: (this.series ?? []).filter((d) => {
2995
+ var x;
2996
+ return d && ((x = d.values) == null ? void 0 : x.length);
2997
+ }),
2998
+ categories: this.categories ?? []
2999
+ }), { series: e, categories: i } = t;
3000
+ if (e.length === 0)
3001
+ return n`<div class=${this.rootClass("baht-line-chart")}>${this.renderEmpty()}</div>`;
3002
+ const a = Math.max(...e.map((d) => d.values.length)), s = e.flatMap((d) => d.values).filter((d) => Number.isFinite(d)), r = Math.max(0, ...s, ...(this.markers ?? []).map((d) => d.value)), o = Ee(r, 4), c = o[o.length - 1] ?? 1, { w: m, h: g } = this.plot, _ = le([0, Math.max(1, a - 1)], [B.left, B.left + m]), p = le([0, c], [B.top + g, B.top]), f = Math.max(0, a - 1 - Math.max(0, this.forecast)), k = (d, x, X) => d.slice(x, X + 1).map((et, st) => `${st === 0 ? "M" : "L"}${_(x + st).toFixed(2)},${p(et).toFixed(2)}`).join(" "), b = e.map((d, x) => ({
3003
+ i: x,
3004
+ name: d.name,
3005
+ value: d.values[d.values.length - 1] ?? 0,
3006
+ yPos: p(d.values[d.values.length - 1] ?? 0),
3007
+ color: lt(x, d.color)
3008
+ })), w = [...b].sort((d, x) => d.yPos - x.yPos), D = w.some((d, x) => x > 0 && d.yPos - w[x - 1].yPos < 15), O = this.labelValues === "ends" && !D, At = Math.max(1, Math.ceil(a / 8)), cs = this.label || `Line chart, ${e.length} series over ${a} points. ${e.map((d, x) => `${d.name}: ${this.fmt(b[x].value)} at the end`).join(". ")}`;
3009
+ return n`<div class=${this.rootClass("baht-line-chart")}>
3010
+ <svg
3011
+ class="baht-chart-svg"
3012
+ viewBox="0 0 ${Qe} ${we}"
3013
+ preserveAspectRatio="xMidYMid meet"
3014
+ role="img"
3015
+ aria-label=${cs}
3016
+ >
3017
+ ${o.map(
3018
+ (d) => A`
3019
+ <line class="baht-chart-grid-line" x1=${B.left} x2=${B.left + m}
3020
+ y1=${p(d).toFixed(2)} y2=${p(d).toFixed(2)}/>
3021
+ <text class="baht-chart-tick" x=${B.left - 8} y=${(p(d) + 4).toFixed(2)}
3022
+ text-anchor="end">${this.fmt(d)}</text>`
3023
+ )}
3024
+ ${this.baseline != null ? [
3025
+ A`<line class="baht-chart-baseline" x1=${B.left} x2=${B.left + m}
3026
+ y1=${p(this.baseline).toFixed(2)} y2=${p(this.baseline).toFixed(2)}/>`
3027
+ ] : []}
3028
+ ${(this.markers ?? []).map(
3029
+ (d) => A`
3030
+ <line class="baht-chart-marker-line" x1=${B.left} x2=${B.left + m}
3031
+ y1=${p(d.value).toFixed(2)} y2=${p(d.value).toFixed(2)}/>
3032
+ <text class="baht-chart-marker-label" x=${B.left + m} y=${(p(d.value) - 5).toFixed(2)}
3033
+ text-anchor="end">${d.label ?? this.fmt(d.value)}</text>`
3034
+ )}
3035
+ ${this.area && e.length === 1 ? A`<path class="baht-chart-area" fill=${lt(0, e[0].color)}
3036
+ d=${`${k(e[0].values, 0, a - 1)} L${_(a - 1).toFixed(2)},${p(0).toFixed(2)} L${_(0).toFixed(2)},${p(0).toFixed(2)} Z`}/>` : h}
3037
+ ${e.map((d, x) => {
3038
+ const X = lt(x, d.color), et = [
3039
+ A`<path class="baht-chart-line" d=${k(d.values, 0, f)} stroke=${X} fill="none"/>`
3040
+ ];
3041
+ return f < a - 1 && et.push(
3042
+ A`<path class="baht-chart-line baht-chart-line--forecast" d=${k(d.values, f, a - 1)}
3043
+ stroke=${X} fill="none"/>`
3044
+ ), et.push(
3045
+ A`<circle class="baht-chart-end-dot" cx=${_(a - 1).toFixed(2)}
3046
+ cy=${p(d.values[d.values.length - 1] ?? 0).toFixed(2)} r="4" fill=${X}/>`
3047
+ ), et;
3048
+ })}
3049
+ ${O ? b.map(
3050
+ (d) => A`
3051
+ <text class="baht-chart-end-label" x=${_(a - 1) + 10} y=${(d.yPos + 4).toFixed(2)}
3052
+ text-anchor="start">${this.fmt(d.value)}</text>`
3053
+ ) : h}
3054
+ ${i.map(
3055
+ (d, x) => x % At === 0 ? A`<text class="baht-chart-tick" x=${_(x).toFixed(2)} y=${we - 10} text-anchor="middle">${d}</text>` : h
3056
+ )}
3057
+ ${Array.from({ length: a }, (d, x) => {
3058
+ const X = m / Math.max(1, a - 1), et = `${i[x] ?? `Point ${x + 1}`}: ${e.map((st) => `${st.name} ${this.fmt(st.values[x] ?? 0)}`).join(", ")}`;
3059
+ return A`<rect class="baht-chart-hit" x=${(_(x) - X / 2).toFixed(2)} y=${B.top}
3060
+ width=${Math.max(24, X).toFixed(2)} height=${g} tabindex="0" role="button"
3061
+ aria-label=${et}
3062
+ @pointermove=${(st) => this.onHover(st, x, et)}
3063
+ @pointerleave=${() => this.onLeave()}
3064
+ @focus=${(st) => this.onHover(st, x, et)}
3065
+ @blur=${() => this.onLeave()}/>`;
3066
+ })}
3067
+ ${this.crosshairAt != null ? A`<line class="baht-chart-crosshair" x1=${_(this.crosshairAt).toFixed(2)}
3068
+ x2=${_(this.crosshairAt).toFixed(2)} y1=${B.top} y2=${B.top + g}/>` : h}
3069
+ </svg>
3070
+ ${this.renderTooltip()}
3071
+ ${this.renderLegend(
3072
+ e.map((d, x) => ({ label: d.name, color: lt(x, d.color) })),
3073
+ "line"
3074
+ )}
3075
+ ${this.showTable ? be(
3076
+ this.label || "Line chart data",
3077
+ ["Point", ...e.map((d) => d.name)],
3078
+ Array.from({ length: a }, (d, x) => [
3079
+ i[x] ?? `Point ${x + 1}`,
3080
+ ...e.map((X) => this.fmt(X.values[x] ?? 0))
3081
+ ])
3082
+ ) : h}
3083
+ </div>`;
3084
+ }
3085
+ onHover(t, e, i) {
3086
+ this.crosshairAt = e, this.requestUpdate(), this.showTip(t, i);
3087
+ }
3088
+ onLeave() {
3089
+ this.crosshairAt = null, this.requestUpdate(), this.hideTip();
3090
+ }
3091
+ };
3092
+ ot([
3093
+ l({ attribute: !1 })
3094
+ ], Z.prototype, "series", 2);
3095
+ ot([
3096
+ l({ attribute: !1 })
3097
+ ], Z.prototype, "categories", 2);
3098
+ ot([
3099
+ l({ type: Boolean })
3100
+ ], Z.prototype, "area", 2);
3101
+ ot([
3102
+ l({ attribute: !1 })
3103
+ ], Z.prototype, "markers", 2);
3104
+ ot([
3105
+ l({ type: Number })
3106
+ ], Z.prototype, "forecast", 2);
3107
+ ot([
3108
+ l({ type: Number })
3109
+ ], Z.prototype, "baseline", 2);
3110
+ ot([
3111
+ l({ attribute: "label-values" })
3112
+ ], Z.prototype, "labelValues", 2);
3113
+ ot([
3114
+ l()
3115
+ ], Z.prototype, "label", 2);
3116
+ Z = ot([
3117
+ u("baht-line-chart")
3118
+ ], Z);
3119
+ var Ya = Object.defineProperty, Xa = Object.getOwnPropertyDescriptor, gt = (t, e, i, a) => {
3120
+ for (var s = a > 1 ? void 0 : a ? Xa(e, i) : e, r = t.length - 1, o; r >= 0; r--)
3121
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
3122
+ return a && s && Ya(e, i, s), s;
3123
+ };
3124
+ const xe = 22, Nt = 24, ts = 34, _e = 18, Za = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
3125
+ function ke(t) {
3126
+ const e = /^(\d{4})-(\d{2})-(\d{2})/.exec(t ?? "");
3127
+ return e ? new Date(Date.UTC(+e[1], +e[2] - 1, +e[3])) : null;
3128
+ }
3129
+ function Pe(t) {
3130
+ return t.toISOString().slice(0, 10);
3131
+ }
3132
+ let ct = class extends Q {
3133
+ constructor() {
3134
+ super(...arguments), this.values = [], this.from = "", this.to = "", this.lessLabel = "Less", this.moreLabel = "More", this.label = "";
3135
+ }
3136
+ get range() {
3137
+ const t = (this.values ?? []).map((a) => ke(a.date)).filter((a) => !!a), e = ke(this.from) ?? (t.length ? new Date(Math.min(...t.map((a) => +a))) : null), i = ke(this.to) ?? (t.length ? new Date(Math.max(...t.map((a) => +a))) : null);
3138
+ return !e || !i || +i < +e ? null : { start: e, end: i };
3139
+ }
3140
+ render() {
3141
+ const t = this.hold({ values: this.values ?? [], range: this.range }), e = t.range;
3142
+ if (!e || t.values.length === 0)
3143
+ return n`<div class=${this.rootClass("baht-heatmap")}>${this.renderEmpty()}</div>`;
3144
+ const i = new Map(t.values.map((b) => [b.date.slice(0, 10), b.value])), a = [], s = new Date(e.start), r = (e.start.getUTCDay() + 6) % 7;
3145
+ let o = 0;
3146
+ for (; +s <= +e.end; ) {
3147
+ const b = Pe(s), w = (s.getUTCDay() + 6) % 7, D = Math.floor((r + o) / 7);
3148
+ a.push({ iso: b, value: i.has(b) ? i.get(b) : null, col: D, row: w }), s.setUTCDate(s.getUTCDate() + 1), o += 1;
3149
+ }
3150
+ const c = Math.max(1, ...a.map((b) => b.col + 1)), m = ts + c * Nt, g = _e + 7 * Nt + 4, _ = Math.max(1, ...a.map((b) => b.value ?? 0)), p = (b) => Math.min(4, Math.max(0, Math.ceil(b / _ * 5) - 1)), f = a.reduce((b, w) => b + (w.value ?? 0), 0), k = this.label || `Calendar heatmap, ${a.length} days from ${Pe(e.start)} to ${Pe(e.end)}, total ${this.fmt(f)}`;
3151
+ return n`<div class=${this.rootClass("baht-heatmap")}>
3152
+ <svg
3153
+ class="baht-chart-svg baht-heatmap-svg"
3154
+ width=${m}
3155
+ height=${g}
3156
+ viewBox="0 0 ${m} ${g}"
3157
+ preserveAspectRatio="xMinYMin meet"
3158
+ role="img"
3159
+ aria-label=${k}
3160
+ >
3161
+ ${Za.map(
3162
+ (b, w) => w % 2 === 0 ? A`<text class="baht-chart-tick" x="0" y=${_e + w * Nt + xe / 2 + 4}>${b}</text>` : h
3163
+ )}
3164
+ ${a.map((b) => {
3165
+ const w = b.value == null ? `${b.iso}: no activity` : `${b.iso}: ${this.fmt(b.value)}`, D = b.value == null || b.value <= 0 ? "var(--baht-chart-grid)" : Ye(p(b.value));
3166
+ return A`<rect class="baht-heatmap-cell" x=${ts + b.col * Nt} y=${_e + b.row * Nt}
3167
+ width=${xe} height=${xe} rx="3" fill=${D} tabindex="0" role="button" aria-label=${w}
3168
+ @pointermove=${(O) => this.showTip(O, w)}
3169
+ @pointerleave=${() => this.hideTip()}
3170
+ @focus=${(O) => this.showTip(O, w)}
3171
+ @blur=${() => this.hideTip()}/>`;
3172
+ })}
3173
+ </svg>
3174
+ ${this.renderTooltip()}
3175
+ <div class="baht-heatmap-scale">
3176
+ <span class="baht-heatmap-scale-label">${this.lessLabel}</span>
3177
+ ${[0, 1, 2, 3, 4].map(
3178
+ (b) => n`<span
3179
+ class="baht-chart-swatch"
3180
+ style=${`background:${Ye(b)}`}
3181
+ aria-hidden="true"
3182
+ ></span>`
3183
+ )}
3184
+ <span class="baht-heatmap-scale-label">${this.moreLabel}</span>
3185
+ </div>
3186
+ ${this.showTable ? be(
3187
+ this.label || "Calendar heatmap data",
3188
+ ["Date", "Value"],
3189
+ a.map((b) => [b.iso, b.value == null ? "—" : this.fmt(b.value)])
3190
+ ) : h}
3191
+ </div>`;
3192
+ }
3193
+ };
3194
+ gt([
3195
+ l({ attribute: !1 })
3196
+ ], ct.prototype, "values", 2);
3197
+ gt([
3198
+ l()
3199
+ ], ct.prototype, "from", 2);
3200
+ gt([
3201
+ l()
3202
+ ], ct.prototype, "to", 2);
3203
+ gt([
3204
+ l({ attribute: "less-label" })
3205
+ ], ct.prototype, "lessLabel", 2);
3206
+ gt([
3207
+ l({ attribute: "more-label" })
3208
+ ], ct.prototype, "moreLabel", 2);
3209
+ gt([
3210
+ l()
3211
+ ], ct.prototype, "label", 2);
3212
+ ct = gt([
3213
+ u("baht-heatmap")
3214
+ ], ct);
3215
+ var Qa = Object.defineProperty, ti = Object.getOwnPropertyDescriptor, tt = (t, e, i, a) => {
3216
+ for (var s = a > 1 ? void 0 : a ? ti(e, i) : e, r = t.length - 1, o; r >= 0; r--)
3217
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
3218
+ return a && s && Qa(e, i, s), s;
3219
+ };
3220
+ let G = class extends $ {
3221
+ constructor() {
3222
+ super(...arguments), this.value = 0, this.max = 100, this.label = "", this.format = "number", this.currency = "THB", this.thresholds = { warning: 0.8, danger: 1 }, this.expected = null, this.overLabel = "Over budget", this.nearLabel = "Near limit";
3223
+ }
3224
+ get fraction() {
3225
+ const t = this.max || 1, e = this.value / t;
3226
+ return Number.isFinite(e) ? Math.max(0, e) : 0;
3227
+ }
3228
+ /** `ok` | `warning` | `danger`, from the fraction and the thresholds. */
3229
+ get severity() {
3230
+ const { warning: t, danger: e } = this.thresholds ?? { warning: 0.8, danger: 1 }, i = this.fraction;
3231
+ return i >= e ? "danger" : i >= t ? "warning" : "ok";
3232
+ }
3233
+ get statusText() {
3234
+ const t = this.severity;
3235
+ return t === "danger" ? this.overLabel : t === "warning" ? this.nearLabel : "";
3236
+ }
3237
+ render() {
3238
+ const t = this.severity, e = Math.min(100, this.fraction * 100), i = (o) => qt(o, this.format, this.currency), a = this.expected != null && Number.isFinite(this.expected) && this.max ? Math.min(100, Math.max(0, this.expected / this.max * 100)) : null, s = `${i(this.value)} of ${i(this.max)}`, r = t === "danger" ? "!" : t === "warning" ? "△" : "";
3239
+ return n`<div class="baht-meter baht-meter--${t}">
3240
+ <div class="baht-meter-head">
3241
+ ${this.label ? n`<span class="baht-meter-label">${this.label}</span>` : h}
3242
+ <span class="baht-meter-value">${s}</span>
3243
+ ${this.statusText ? n`<span class="baht-meter-status"
3244
+ ><span class="baht-meter-icon" aria-hidden="true">${r}</span
3245
+ >${this.statusText}</span
3246
+ >` : h}
3247
+ </div>
3248
+ <div
3249
+ class="baht-meter-track"
3250
+ role="meter"
3251
+ aria-label=${this.label || "Meter"}
3252
+ aria-valuemin="0"
3253
+ aria-valuemax=${this.max}
3254
+ aria-valuenow=${this.value}
3255
+ aria-valuetext=${`${s}${this.statusText ? `, ${this.statusText}` : ""}`}
3256
+ >
3257
+ <div class="baht-meter-fill" style=${`width:${e.toFixed(2)}%`}></div>
3258
+ ${a != null ? n`<span
3259
+ class="baht-meter-expected"
3260
+ style=${`left:${a.toFixed(2)}%`}
3261
+ aria-hidden="true"
3262
+ ></span>` : h}
3263
+ </div>
3264
+ ${a != null ? n`<div class="baht-meter-pace">Expected by now ${i(this.expected)}</div>` : h}
3265
+ </div>`;
3266
+ }
3267
+ };
3268
+ tt([
3269
+ l({ type: Number })
3270
+ ], G.prototype, "value", 2);
3271
+ tt([
3272
+ l({ type: Number })
3273
+ ], G.prototype, "max", 2);
3274
+ tt([
3275
+ l()
3276
+ ], G.prototype, "label", 2);
3277
+ tt([
3278
+ l()
3279
+ ], G.prototype, "format", 2);
3280
+ tt([
3281
+ l()
3282
+ ], G.prototype, "currency", 2);
3283
+ tt([
3284
+ l({ attribute: !1 })
3285
+ ], G.prototype, "thresholds", 2);
3286
+ tt([
3287
+ l({ type: Number })
3288
+ ], G.prototype, "expected", 2);
3289
+ tt([
3290
+ l({ attribute: "over-label" })
3291
+ ], G.prototype, "overLabel", 2);
3292
+ tt([
3293
+ l({ attribute: "near-label" })
3294
+ ], G.prototype, "nearLabel", 2);
3295
+ G = tt([
3296
+ u("baht-meter")
3297
+ ], G);
3298
+ var ei = Object.defineProperty, si = Object.getOwnPropertyDescriptor, fe = (t, e, i, a) => {
3299
+ for (var s = a > 1 ? void 0 : a ? si(e, i) : e, r = t.length - 1, o; r >= 0; r--)
3300
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
3301
+ return a && s && ei(e, i, s), s;
3302
+ };
3303
+ let Ht = class extends $ {
3304
+ constructor() {
3305
+ super(...arguments), this.icon = "🗂️", this.message = "Nothing to display", this.hint = "";
3306
+ }
3307
+ render() {
3308
+ return n`<div class="baht-empty-state">
3309
+ ${this.icon ? n`<div class="baht-empty-state-icon" aria-hidden="true">${this.icon}</div>` : h}
3310
+ <div class="baht-empty-state-message">${this.message}</div>
3311
+ ${this.hint ? n`<div class="baht-empty-state-hint">${this.hint}</div>` : h}
3312
+ </div>`;
3313
+ }
3314
+ };
3315
+ fe([
3316
+ l()
3317
+ ], Ht.prototype, "icon", 2);
3318
+ fe([
3319
+ l()
3320
+ ], Ht.prototype, "message", 2);
3321
+ fe([
3322
+ l()
3323
+ ], Ht.prototype, "hint", 2);
3324
+ Ht = fe([
3325
+ u("baht-empty-state")
3326
+ ], Ht);
3327
+ var ai = Object.defineProperty, ii = Object.getOwnPropertyDescriptor, Qt = (t, e, i, a) => {
3328
+ for (var s = a > 1 ? void 0 : a ? ii(e, i) : e, r = t.length - 1, o; r >= 0; r--)
3329
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
3330
+ return a && s && ai(e, i, s), s;
3331
+ };
3332
+ let Ft = class extends $ {
3333
+ constructor() {
3334
+ super(...arguments), this.icon = "⚠️", this.heading = "Something went wrong", this.message = "", this.retryLabel = "";
3335
+ }
3336
+ onRetry() {
3337
+ this.dispatchEvent(new CustomEvent("baht-retry", { bubbles: !0, composed: !0 }));
3338
+ }
3339
+ render() {
3340
+ return n`<div class="baht-error-state" role="alert">
3341
+ ${this.icon ? n`<div class="baht-error-state-icon" aria-hidden="true">${this.icon}</div>` : h}
3342
+ <div class="baht-error-state-heading">${this.heading}</div>
3343
+ ${this.message ? n`<div class="baht-error-state-message">${this.message}</div>` : h}
3344
+ ${this.retryLabel ? n`<baht-button size="sm" label=${this.retryLabel} @click=${this.onRetry}></baht-button>` : h}
3345
+ </div>`;
3346
+ }
3347
+ };
3348
+ Qt([
3349
+ l()
3350
+ ], Ft.prototype, "icon", 2);
3351
+ Qt([
3352
+ l()
3353
+ ], Ft.prototype, "heading", 2);
3354
+ Qt([
3355
+ l()
3356
+ ], Ft.prototype, "message", 2);
3357
+ Qt([
3358
+ l({ attribute: "retry-label" })
3359
+ ], Ft.prototype, "retryLabel", 2);
3360
+ Ft = Qt([
3361
+ u("baht-error-state")
3362
+ ], Ft);
3363
+ var ri = Object.defineProperty, oi = Object.getOwnPropertyDescriptor, wt = (t, e, i, a) => {
3364
+ for (var s = a > 1 ? void 0 : a ? oi(e, i) : e, r = t.length - 1, o; r >= 0; r--)
3365
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
3366
+ return a && s && ri(e, i, s), s;
3367
+ };
3368
+ let pt = class extends $ {
3369
+ constructor() {
3370
+ super(...arguments), this.value = {}, this.keyPlaceholder = "key", this.valuePlaceholder = "value", this.add_label = "Add row", this.disabled = !1, this.rows = [{ k: "", v: "" }], this.syncedJson = "";
3371
+ }
3372
+ willUpdate(t) {
3373
+ if (!t.has("value")) return;
3374
+ const e = JSON.stringify(this.value ?? {});
3375
+ e !== this.syncedJson && (this.syncedJson = e, this.rows = this.toRows(this.value));
3376
+ }
3377
+ toRows(t) {
3378
+ const e = Object.entries(t ?? {}).map(([i, a]) => ({
3379
+ k: i,
3380
+ v: typeof a == "string" ? a : JSON.stringify(a)
3381
+ }));
3382
+ return e.length > 0 ? e : [{ k: "", v: "" }];
3383
+ }
3384
+ commit(t) {
3385
+ this.rows = t.length > 0 ? t : [{ k: "", v: "" }];
3386
+ const e = {};
3387
+ for (const i of t) i.k.trim() && (e[i.k.trim()] = i.v);
3388
+ this.syncedJson = JSON.stringify(e), this.dispatchEvent(
3389
+ new CustomEvent("baht-change", { detail: { value: e }, bubbles: !0, composed: !0 })
3390
+ );
3391
+ }
3392
+ edit(t, e) {
3393
+ this.commit(this.rows.map((i, a) => a === t ? { ...i, ...e } : i));
3394
+ }
3395
+ addRow() {
3396
+ this.rows = [...this.rows, { k: "", v: "" }];
3397
+ }
3398
+ render() {
3399
+ return n`<div class="baht-keyvalue">
3400
+ ${this.rows.map(
3401
+ (t, e) => n`<div class="baht-keyvalue-row">
3402
+ <input
3403
+ class="baht-control baht-keyvalue-key"
3404
+ placeholder=${this.keyPlaceholder}
3405
+ aria-label="${this.keyPlaceholder} ${e + 1}"
3406
+ .value=${t.k}
3407
+ ?disabled=${this.disabled}
3408
+ @input=${(i) => this.edit(e, { k: i.target.value })}
3409
+ />
3410
+ <span class="baht-keyvalue-eq" aria-hidden="true">=</span>
3411
+ <input
3412
+ class="baht-control baht-keyvalue-value"
3413
+ placeholder=${this.valuePlaceholder}
3414
+ aria-label="${this.valuePlaceholder} ${e + 1}"
3415
+ .value=${t.v}
3416
+ ?disabled=${this.disabled}
3417
+ @input=${(i) => this.edit(e, { v: i.target.value })}
3418
+ />
3419
+ <button
3420
+ type="button"
3421
+ class="baht-keyvalue-remove"
3422
+ aria-label="Remove row ${e + 1}"
3423
+ ?disabled=${this.disabled}
3424
+ @click=${() => this.commit(this.rows.filter((i, a) => a !== e))}
3425
+ >${U("close")}</button>
3426
+ </div>`
3427
+ )}
3428
+ <button
3429
+ type="button"
3430
+ class="baht-keyvalue-add"
3431
+ ?disabled=${this.disabled}
3432
+ @click=${this.addRow}
3433
+ >${U("plus")}${this.add_label}</button>
3434
+ </div>`;
3435
+ }
3436
+ };
3437
+ wt([
3438
+ l({ attribute: !1 })
3439
+ ], pt.prototype, "value", 2);
3440
+ wt([
3441
+ l({ attribute: "key-placeholder" })
3442
+ ], pt.prototype, "keyPlaceholder", 2);
3443
+ wt([
3444
+ l({ attribute: "value-placeholder" })
3445
+ ], pt.prototype, "valuePlaceholder", 2);
3446
+ wt([
3447
+ l({ attribute: "add-label" })
3448
+ ], pt.prototype, "add_label", 2);
3449
+ wt([
3450
+ l({ type: Boolean })
3451
+ ], pt.prototype, "disabled", 2);
3452
+ wt([
3453
+ y()
3454
+ ], pt.prototype, "rows", 2);
3455
+ pt = wt([
3456
+ u("baht-keyvalue-editor")
3457
+ ], pt);
3458
+ var li = Object.defineProperty, ni = Object.getOwnPropertyDescriptor, M = (t, e, i, a) => {
3459
+ for (var s = a > 1 ? void 0 : a ? ni(e, i) : e, r = t.length - 1, o; r >= 0; r--)
3460
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
3461
+ return a && s && li(e, i, s), s;
3462
+ };
3463
+ let S = class extends $ {
3464
+ constructor() {
3465
+ super(...arguments), this.label = "Reference", this.value = "", this.display = "", this.placeholder = "", this.disabled = !1, this.invalid = !1, this.href = "", this.lookupLabel = "Look up records", this.debounce = 200, this.fetcher = null, this.open = !1, this.term = "", this.options = [], this.loading = !1, this.activeIndex = -1, this.fetchSeq = 0, this.onDocMousedown = (t) => {
3466
+ this.contains(t.target) || this.close();
3467
+ };
3468
+ }
3469
+ get listboxId() {
3470
+ return `baht-refpicker-list-${this.uid}`;
3471
+ }
3472
+ disconnectedCallback() {
3473
+ super.disconnectedCallback(), clearTimeout(this.timer), q() && document.removeEventListener("mousedown", this.onDocMousedown);
3474
+ }
3475
+ openLookup() {
3476
+ this.disabled || this.open || (this.open = !0, this.term = "", this.activeIndex = -1, q() && document.addEventListener("mousedown", this.onDocMousedown), this.search(""), this.updateComplete.then(() => {
3477
+ var t;
3478
+ return (t = this.inputEl) == null ? void 0 : t.focus();
3479
+ }));
3480
+ }
3481
+ close() {
3482
+ this.open && (this.open = !1, this.loading = !1, clearTimeout(this.timer), q() && document.removeEventListener("mousedown", this.onDocMousedown));
3483
+ }
3484
+ search(t) {
3485
+ clearTimeout(this.timer), this.timer = setTimeout(async () => {
3486
+ if (!this.fetcher) return;
3487
+ const e = ++this.fetchSeq;
3488
+ this.loading = !0;
3489
+ try {
3490
+ const i = await this.fetcher(t);
3491
+ e === this.fetchSeq && (this.options = i);
3492
+ } catch {
3493
+ e === this.fetchSeq && (this.options = []);
3494
+ } finally {
3495
+ e === this.fetchSeq && (this.loading = !1);
3496
+ }
3497
+ }, this.debounce);
3498
+ }
3499
+ pick(t) {
3500
+ this.close(), this.emitChange(t.key, t.label);
3501
+ }
3502
+ clear() {
3503
+ this.close(), this.emitChange("", "");
3504
+ }
3505
+ emitChange(t, e) {
3506
+ this.dispatchEvent(
3507
+ new CustomEvent("baht-change", {
3508
+ detail: { value: t, label: e },
3509
+ bubbles: !0,
3510
+ composed: !0
3511
+ })
3512
+ );
3513
+ }
3514
+ onInput(t) {
3515
+ this.term = t.target.value, this.activeIndex = -1, this.search(this.term);
3516
+ }
3517
+ onKeydown(t) {
3518
+ if (this.open)
3519
+ if (t.key === "ArrowDown" || t.key === "ArrowUp") {
3520
+ t.preventDefault();
3521
+ const e = t.key === "ArrowDown" ? 1 : -1, i = this.options.length;
3522
+ i > 0 && (this.activeIndex = (this.activeIndex + e + i) % i);
3523
+ } else if (t.key === "Enter") {
3524
+ t.preventDefault();
3525
+ const e = this.options[this.activeIndex];
3526
+ e && this.pick(e);
3527
+ } else t.key === "Escape" && (t.preventDefault(), this.close());
3528
+ }
3529
+ render() {
3530
+ const t = this.open ? this.term : this.display || this.value;
3531
+ return n`<div class="baht-refpicker${this.open ? " baht-refpicker--open" : ""}">
3532
+ <div class="baht-refpicker-field">
3533
+ <input
3534
+ class="baht-control baht-refpicker-input"
3535
+ type="text"
3536
+ role="combobox"
3537
+ aria-label=${this.label}
3538
+ aria-expanded=${this.open ? "true" : "false"}
3539
+ aria-controls=${this.listboxId}
3540
+ aria-autocomplete="list"
3541
+ aria-invalid=${this.invalid ? "true" : h}
3542
+ aria-activedescendant=${this.activeIndex >= 0 ? `${this.listboxId}-${this.activeIndex}` : h}
3543
+ placeholder=${this.open ? this.placeholder || "Search…" : this.placeholder}
3544
+ .value=${t}
3545
+ ?disabled=${this.disabled}
3546
+ ?readonly=${!this.open}
3547
+ @focus=${() => this.openLookup()}
3548
+ @input=${this.onInput}
3549
+ @keydown=${this.onKeydown}
3550
+ />
3551
+ ${this.value && !this.disabled ? n`<button
3552
+ type="button"
3553
+ class="baht-refpicker-clear"
3554
+ aria-label="Clear"
3555
+ @mousedown=${(e) => e.preventDefault()}
3556
+ @click=${() => this.clear()}
3557
+ >${U("close")}</button>` : h}
3558
+ </div>
3559
+ <button
3560
+ type="button"
3561
+ class="baht-refpicker-lookup"
3562
+ aria-label=${this.lookupLabel}
3563
+ title=${this.lookupLabel}
3564
+ ?disabled=${this.disabled}
3565
+ @click=${() => this.open ? this.close() : this.openLookup()}
3566
+ >${U("search")}</button>
3567
+ ${this.value && this.href ? n`<a
3568
+ class="baht-refpicker-open"
3569
+ href=${this.href}
3570
+ aria-label="Open record"
3571
+ title="Open record"
3572
+ >${U("external")}</a>` : h}
3573
+ <div
3574
+ class="baht-refpicker-list"
3575
+ id=${this.listboxId}
3576
+ role="listbox"
3577
+ aria-label=${this.label}
3578
+ aria-busy=${this.loading ? "true" : h}
3579
+ ?hidden=${!this.open}
3580
+ >
3581
+ ${this.loading ? n`<div class="baht-refpicker-note" role="option" aria-disabled="true" aria-selected="false">Searching…</div>` : this.options.length === 0 ? n`<div class="baht-refpicker-note" role="option" aria-disabled="true" aria-selected="false">No matches</div>` : this.options.map(
3582
+ (e, i) => n`<button
3583
+ type="button"
3584
+ class="baht-refpicker-option${i === this.activeIndex ? " baht-refpicker-option--active" : ""}"
3585
+ id="${this.listboxId}-${i}"
3586
+ role="option"
3587
+ aria-selected=${e.key === this.value ? "true" : "false"}
3588
+ @mousedown=${(a) => a.preventDefault()}
3589
+ @click=${() => this.pick(e)}
3590
+ >
3591
+ <span class="baht-refpicker-option-label">${e.label}</span>
3592
+ ${e.sub ? n`<span class="baht-refpicker-option-sub">${e.sub}</span>` : h}
3593
+ </button>`
3594
+ )}
3595
+ </div>
3596
+ </div>`;
3597
+ }
3598
+ };
3599
+ M([
3600
+ l()
3601
+ ], S.prototype, "label", 2);
3602
+ M([
3603
+ l()
3604
+ ], S.prototype, "value", 2);
3605
+ M([
3606
+ l()
3607
+ ], S.prototype, "display", 2);
3608
+ M([
3609
+ l()
3610
+ ], S.prototype, "placeholder", 2);
3611
+ M([
3612
+ l({ type: Boolean })
3613
+ ], S.prototype, "disabled", 2);
3614
+ M([
3615
+ l({ type: Boolean })
3616
+ ], S.prototype, "invalid", 2);
3617
+ M([
3618
+ l()
3619
+ ], S.prototype, "href", 2);
3620
+ M([
3621
+ l({ attribute: "lookup-label" })
3622
+ ], S.prototype, "lookupLabel", 2);
3623
+ M([
3624
+ l({ type: Number })
3625
+ ], S.prototype, "debounce", 2);
3626
+ M([
3627
+ l({ attribute: !1 })
3628
+ ], S.prototype, "fetcher", 2);
3629
+ M([
3630
+ y()
3631
+ ], S.prototype, "open", 2);
3632
+ M([
3633
+ y()
3634
+ ], S.prototype, "term", 2);
3635
+ M([
3636
+ y()
3637
+ ], S.prototype, "options", 2);
3638
+ M([
3639
+ y()
3640
+ ], S.prototype, "loading", 2);
3641
+ M([
3642
+ y()
3643
+ ], S.prototype, "activeIndex", 2);
3644
+ M([
3645
+ Et("input")
3646
+ ], S.prototype, "inputEl", 2);
3647
+ S = M([
3648
+ u("baht-reference-picker")
3649
+ ], S);
3650
+ var hi = Object.defineProperty, ci = Object.getOwnPropertyDescriptor, j = (t, e, i, a) => {
3651
+ for (var s = a > 1 ? void 0 : a ? ci(e, i) : e, r = t.length - 1, o; r >= 0; r--)
3652
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
3653
+ return a && s && hi(e, i, s), s;
3654
+ };
3655
+ let E = class extends $ {
3656
+ constructor() {
3657
+ super(...arguments), this.label = "Search", this.value = "", this.placeholder = "", this.disabled = !1, this.invalid = !1, this.options = [], this.fetcher = null, this.debounce = 150, this.minChars = 1, this.maxItems = 8, this.freeText = !0, this.autocomplete = "off", this.term = "", this.open = !1, this.results = [], this.loading = !1, this.activeIndex = -1, this.fetchSeq = 0, this.picked = null, this.lastPicked = null, this.onDocMousedown = (t) => {
3658
+ this.contains(t.target) || this.close();
3659
+ };
3660
+ }
3661
+ get inputId() {
3662
+ return `baht-typeahead-${this.uid}`;
3663
+ }
3664
+ get listboxId() {
3665
+ return `${this.inputId}-list`;
3666
+ }
3667
+ optionId(t) {
3668
+ return `${this.listboxId}-${t}`;
3669
+ }
3670
+ disconnectedCallback() {
3671
+ super.disconnectedCallback(), clearTimeout(this.timer), q() && document.removeEventListener("mousedown", this.onDocMousedown);
3672
+ }
3673
+ willUpdate(t) {
3674
+ super.willUpdate(t), t.has("value") && this.timer === void 0 && (this.term = this.value);
3675
+ }
3676
+ updated() {
3677
+ var t, e;
3678
+ !this.open || this.activeIndex < 0 || (e = (t = this.querySelector(`#${this.optionId(this.activeIndex)}`)) == null ? void 0 : t.scrollIntoView) == null || e.call(t, {
3679
+ block: "nearest"
3680
+ });
3681
+ }
3682
+ // ---- suggestions -----------------------------------------------------
3683
+ filterStatic(t) {
3684
+ var s;
3685
+ const e = t.trim().toLowerCase();
3686
+ if (!e) return this.options.slice(0, this.maxItems);
3687
+ const i = [], a = [];
3688
+ for (const r of this.options) {
3689
+ const o = r.label.toLowerCase();
3690
+ o.startsWith(e) ? i.push(r) : (o.includes(e) || (s = r.sub) != null && s.toLowerCase().includes(e)) && a.push(r);
3691
+ }
3692
+ return [...i, ...a].slice(0, this.maxItems);
3693
+ }
3694
+ async suggest(t) {
3695
+ if (t.length < this.minChars) {
3696
+ this.results = [], this.loading = !1, this.close();
3697
+ return;
3698
+ }
3699
+ if (!this.fetcher) {
3700
+ this.results = this.filterStatic(t), this.activeIndex = -1, this.open = !0, this.listen();
3701
+ return;
3702
+ }
3703
+ const e = ++this.fetchSeq;
3704
+ this.loading = !0, this.open = !0, this.listen();
3705
+ try {
3706
+ const i = await this.fetcher(t);
3707
+ e === this.fetchSeq && (this.results = i.slice(0, this.maxItems));
3708
+ } catch {
3709
+ e === this.fetchSeq && (this.results = []);
3710
+ } finally {
3711
+ e === this.fetchSeq && (this.loading = !1, this.activeIndex = -1);
3712
+ }
3713
+ }
3714
+ highlight(t) {
3715
+ this.activeIndex !== t && (this.activeIndex = t);
3716
+ }
3717
+ listen() {
3718
+ q() && document.addEventListener("mousedown", this.onDocMousedown);
3719
+ }
3720
+ close() {
3721
+ q() && document.removeEventListener("mousedown", this.onDocMousedown), this.open && (this.open = !1, this.activeIndex = -1);
3722
+ }
3723
+ // ---- events ------------------------------------------------------------
3724
+ emitChange(t, e) {
3725
+ this.dispatchEvent(
3726
+ new CustomEvent("baht-change", {
3727
+ detail: { value: t, option: e },
3728
+ bubbles: !0,
3729
+ composed: !0
3730
+ })
3731
+ );
3732
+ }
3733
+ onInput(t) {
3734
+ this.term = t.target.value, this.picked = null, clearTimeout(this.timer), this.timer = setTimeout(
3735
+ () => {
3736
+ this.timer = void 0, this.emitChange(this.term, null), this.suggest(this.term);
3737
+ },
3738
+ Math.max(0, this.debounce)
3739
+ );
3740
+ }
3741
+ /** Hand pending text to the host now (blur, Enter). */
3742
+ flush() {
3743
+ this.timer !== void 0 && (clearTimeout(this.timer), this.timer = void 0, this.emitChange(this.term, null));
3744
+ }
3745
+ pick(t) {
3746
+ clearTimeout(this.timer), this.timer = void 0, this.picked = t, this.lastPicked = t, this.term = t.label, this.close(), this.emitChange(t.label, t), this.dispatchEvent(
3747
+ new CustomEvent("baht-select", { detail: { option: t }, bubbles: !0, composed: !0 })
3748
+ );
3749
+ }
3750
+ onBlur() {
3751
+ if (!this.freeText && !this.picked) {
3752
+ clearTimeout(this.timer), this.timer = void 0;
3753
+ const t = this.lastPicked;
3754
+ this.term = (t == null ? void 0 : t.label) ?? "", this.picked = t, this.value !== this.term && this.emitChange(this.term, t);
3755
+ return;
3756
+ }
3757
+ this.flush();
3758
+ }
3759
+ onKeydown(t) {
3760
+ const e = this.results.length;
3761
+ switch (t.key) {
3762
+ case "ArrowDown":
3763
+ if (t.preventDefault(), !this.open) {
3764
+ this.suggest(this.term);
3765
+ return;
3766
+ }
3767
+ e > 0 && (this.activeIndex = (this.activeIndex + 1) % e);
3768
+ break;
3769
+ case "ArrowUp":
3770
+ t.preventDefault(), this.open && e > 0 && (this.activeIndex = (this.activeIndex - 1 + e) % e);
3771
+ break;
3772
+ case "Enter": {
3773
+ const i = this.open ? this.results[this.activeIndex] : void 0;
3774
+ i ? (t.preventDefault(), this.pick(i)) : (this.flush(), this.close());
3775
+ break;
3776
+ }
3777
+ case "Escape":
3778
+ this.open && (t.preventDefault(), this.close());
3779
+ break;
3780
+ case "Tab":
3781
+ this.flush(), this.close();
3782
+ break;
3783
+ }
3784
+ }
3785
+ render() {
3786
+ const t = this.open, e = !this.loading && this.results.length === 0;
3787
+ return n`<div class="baht-typeahead${this.open ? " baht-typeahead--open" : ""}">
3788
+ <input
3789
+ class="baht-control baht-typeahead-input"
3790
+ id=${this.inputId}
3791
+ type="text"
3792
+ role="combobox"
3793
+ aria-label=${this.label}
3794
+ aria-autocomplete="list"
3795
+ aria-expanded=${t ? "true" : "false"}
3796
+ aria-controls=${this.listboxId}
3797
+ aria-activedescendant=${t && this.activeIndex >= 0 ? this.optionId(this.activeIndex) : h}
3798
+ aria-invalid=${this.invalid ? "true" : h}
3799
+ autocomplete=${this.autocomplete}
3800
+ placeholder=${this.placeholder || h}
3801
+ .value=${rt(this.term)}
3802
+ ?disabled=${this.disabled}
3803
+ @input=${(i) => this.onInput(i)}
3804
+ @keydown=${(i) => this.onKeydown(i)}
3805
+ @blur=${() => this.onBlur()}
3806
+ />
3807
+ <div
3808
+ class="baht-listbox baht-typeahead-list"
3809
+ id=${this.listboxId}
3810
+ role="listbox"
3811
+ aria-label=${this.label}
3812
+ aria-busy=${this.loading ? "true" : h}
3813
+ ?hidden=${!t}
3814
+ >
3815
+ ${this.loading ? n`<div class="baht-listbox-note" role="option" aria-disabled="true" aria-selected="false">Searching…</div>` : e ? n`<div class="baht-listbox-note" role="option" aria-disabled="true" aria-selected="false">No matches</div>` : this.results.map(
3816
+ // eslint-disable-next-line lit-a11y/click-events-have-key-events -- keyboard lives on the combobox input (aria-activedescendant pattern)
3817
+ (i, a) => n`<div
3818
+ class="baht-listbox-option${a === this.activeIndex ? " baht-listbox-option--active" : ""}"
3819
+ id=${this.optionId(a)}
3820
+ role="option"
3821
+ aria-selected=${a === this.activeIndex ? "true" : "false"}
3822
+ data-key=${i.key}
3823
+ @mousedown=${(s) => s.preventDefault()}
3824
+ @mousemove=${() => this.highlight(a)}
3825
+ @click=${() => {
3826
+ var s;
3827
+ this.pick(i), (s = this.inputEl) == null || s.focus();
3828
+ }}
3829
+ >
3830
+ <span class="baht-listbox-option-label">${i.label}</span>
3831
+ ${i.sub ? n`<span class="baht-listbox-option-sub">${i.sub}</span>` : h}
3832
+ </div>`
3833
+ )}
3834
+ </div>
3835
+ </div>`;
3836
+ }
3837
+ };
3838
+ j([
3839
+ l()
3840
+ ], E.prototype, "label", 2);
3841
+ j([
3842
+ l()
3843
+ ], E.prototype, "value", 2);
3844
+ j([
3845
+ l()
3846
+ ], E.prototype, "placeholder", 2);
3847
+ j([
3848
+ l({ type: Boolean })
3849
+ ], E.prototype, "disabled", 2);
3850
+ j([
3851
+ l({ type: Boolean })
3852
+ ], E.prototype, "invalid", 2);
3853
+ j([
3854
+ l({ attribute: !1 })
3855
+ ], E.prototype, "options", 2);
3856
+ j([
3857
+ l({ attribute: !1 })
3858
+ ], E.prototype, "fetcher", 2);
3859
+ j([
3860
+ l({ type: Number })
3861
+ ], E.prototype, "debounce", 2);
3862
+ j([
3863
+ l({ type: Number, attribute: "min-chars" })
3864
+ ], E.prototype, "minChars", 2);
3865
+ j([
3866
+ l({ type: Number, attribute: "max-items" })
3867
+ ], E.prototype, "maxItems", 2);
3868
+ j([
3869
+ l({ attribute: "free-text", converter: (t) => t !== "false" })
3870
+ ], E.prototype, "freeText", 2);
3871
+ j([
3872
+ l()
3873
+ ], E.prototype, "autocomplete", 2);
3874
+ j([
3875
+ y()
3876
+ ], E.prototype, "term", 2);
3877
+ j([
3878
+ y()
3879
+ ], E.prototype, "open", 2);
3880
+ j([
3881
+ y()
3882
+ ], E.prototype, "results", 2);
3883
+ j([
3884
+ y()
3885
+ ], E.prototype, "loading", 2);
3886
+ j([
3887
+ y()
3888
+ ], E.prototype, "activeIndex", 2);
3889
+ j([
3890
+ Et("input")
3891
+ ], E.prototype, "inputEl", 2);
3892
+ E = j([
3893
+ u("baht-typeahead")
3894
+ ], E);
3895
+ const ns = {
3896
+ text: "baht-input",
3897
+ email: "baht-input",
3898
+ password: "baht-input",
3899
+ textarea: "baht-textarea",
3900
+ number: "baht-number",
3901
+ dropdown: "baht-select",
3902
+ multiselect: "baht-multiselect",
3903
+ checkbox: "baht-checkbox",
3904
+ radio: "baht-radio",
3905
+ toggle: "baht-toggle",
3906
+ date: "baht-datepicker",
3907
+ file: "baht-file",
3908
+ label: "baht-text",
3909
+ section: "baht-section",
3910
+ repeater: "baht-repeater"
3911
+ };
3912
+ var pi = Object.defineProperty, di = Object.getOwnPropertyDescriptor, hs = (t, e, i, a) => {
3913
+ for (var s = a > 1 ? void 0 : a ? di(e, i) : e, r = t.length - 1, o; r >= 0; r--)
3914
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
3915
+ return a && s && pi(e, i, s), s;
3916
+ };
3917
+ const ui = {
3918
+ "1/4": "baht-field--w-1-4",
3919
+ "1/2": "baht-field--w-1-2",
3920
+ "3/4": "baht-field--w-3-4",
3921
+ full: "baht-field--w-full"
3922
+ }, es = /* @__PURE__ */ new Map();
3923
+ function bi(t) {
3924
+ let e = es.get(t);
3925
+ return e || (e = is(t), es.set(t, e)), e;
3926
+ }
3927
+ let Be = class extends W {
3928
+ constructor() {
3929
+ super(...arguments), this.rowErrors = [];
3930
+ }
3931
+ willUpdate(t) {
3932
+ super.willUpdate(t);
3933
+ }
3934
+ get rows() {
3935
+ return Array.isArray(this.value) ? this.value : [];
3936
+ }
3937
+ get subFields() {
3938
+ return [...this.field.fields ?? []].sort((t, e) => t.order - e.order).filter((t) => t.type !== "repeater");
3939
+ }
3940
+ patchRow(t, e, i) {
3941
+ const a = [...this.rows];
3942
+ a[t] = { ...a[t], [e]: i }, this.emitInput(a);
3943
+ }
3944
+ addRow() {
3945
+ const t = {};
3946
+ for (const e of this.subFields)
3947
+ e.type === "label" || e.type === "section" || (t[e.key] = se(e));
3948
+ this.emitInput([...this.rows, t]);
3949
+ }
3950
+ removeRow(t) {
3951
+ this.emitInput(this.rows.filter((e, i) => i !== t));
3952
+ }
3953
+ /** Pending keystrokes in any row land in the array before the host reads it. */
3954
+ flushTyped() {
3955
+ var t;
3956
+ if (!q()) return super.flushTyped();
3957
+ for (const e of this.querySelectorAll(".baht-repeater-row > .baht-field > *"))
3958
+ (t = e.flushTyped) == null || t.call(e);
3959
+ super.flushTyped();
3960
+ }
3961
+ errorFor(t, e) {
3962
+ var a;
3963
+ const i = `${this.field.key}[${t}].${e}`;
3964
+ return ((a = this.rowErrors.find((s) => s.key === i)) == null ? void 0 : a.message) ?? null;
3965
+ }
3966
+ /**
3967
+ * Sub-controls render declaratively (one static-tag template per primitive, rows
3968
+ * keyed by index) so Lit reuses the same node across re-renders — typing keeps
3969
+ * focus, same as <baht-form> — and the whole thing renders on the server.
3970
+ */
3971
+ renderSub(t, e, i) {
3972
+ const a = ns[i.type];
3973
+ if (!a) return h;
3974
+ const s = bi(a), r = ui[i.width ?? "full"] ?? "baht-field--w-full", o = (c) => {
3975
+ c.stopPropagation();
3976
+ const { value: m } = c.detail;
3977
+ this.patchRow(e, i.key, m);
3978
+ };
3979
+ return n`<div class="baht-field ${r}" data-key=${i.key} data-type=${i.type}>
3980
+ ${ee`<${s}
3981
+ .field=${i}
3982
+ .value=${Object.hasOwn(t, i.key) ? t[i.key] : se(i)}
3983
+ .disabled=${this.disabled}
3984
+ .readonly=${this.readonly}
3985
+ .required=${!!i.required}
3986
+ .error=${this.errorFor(e, i.key)}
3987
+ .debounce=${this.debounce}
3988
+ @baht-input=${o}
3989
+ ></${s}>`}
3990
+ </div>`;
3991
+ }
3992
+ renderControl() {
3993
+ const t = this.rows, e = !this.disabled && !this.readonly, i = this.field.max_rows !== void 0 && t.length >= this.field.max_rows;
3994
+ return n`<div
3995
+ class="baht-repeater"
3996
+ id=${this.controlId}
3997
+ role="group"
3998
+ aria-labelledby=${this.field.label ? this.labelId : h}
3999
+ aria-describedby=${this.describedBy}
4000
+ >
4001
+ ${Oe(
4002
+ t,
4003
+ (a, s) => s,
4004
+ (a, s) => n`<div
4005
+ class="baht-repeater-row"
4006
+ data-row=${s}
4007
+ role="group"
4008
+ aria-label=${v("row", { n: s + 1 })}
4009
+ >
4010
+ ${Oe(
4011
+ this.subFields,
4012
+ (r) => r.key,
4013
+ (r) => this.renderSub(a, s, r)
4014
+ )}
4015
+ ${e ? n`<button
4016
+ type="button"
4017
+ class="baht-repeater-remove"
4018
+ aria-label=${v("removeRowN", { n: s + 1 })}
4019
+ title=${v("removeRowN", { n: s + 1 })}
4020
+ @click=${() => this.removeRow(s)}
4021
+ >
4022
+ ✕
4023
+ </button>` : h}
4024
+ </div>`
4025
+ )}
4026
+ ${this.readonly ? h : n`<button
4027
+ type="button"
4028
+ class="baht-repeater-add"
4029
+ ?disabled=${this.disabled || i}
4030
+ @click=${() => this.addRow()}
4031
+ >
4032
+ + ${this.field.add_label ?? v("addRow")}
4033
+ </button>`}
4034
+ </div>`;
4035
+ }
4036
+ };
4037
+ hs([
4038
+ l({ attribute: !1 })
4039
+ ], Be.prototype, "rowErrors", 2);
4040
+ Be = hs([
4041
+ u("baht-repeater")
4042
+ ], Be);
4043
+ var fi = Object.defineProperty, mi = Object.getOwnPropertyDescriptor, me = (t, e, i, a) => {
4044
+ for (var s = a > 1 ? void 0 : a ? mi(e, i) : e, r = t.length - 1, o; r >= 0; r--)
4045
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
4046
+ return a && s && fi(e, i, s), s;
4047
+ };
4048
+ let Gt = class extends $ {
4049
+ constructor() {
4050
+ super(...arguments), this.steps = [], this.current = 0, this.variant = "default";
4051
+ }
4052
+ render() {
4053
+ const t = this.variant === "sidebar";
4054
+ return n`<ol
4055
+ class="baht-steps ${t ? "baht-steps--sidebar" : ""}"
4056
+ aria-label=${v("step", { current: this.current + 1, total: this.steps.length })}
4057
+ >
4058
+ ${this.steps.map((e, i) => {
4059
+ const a = i < this.current ? "done" : i === this.current ? "current" : "todo";
4060
+ return n`<li
4061
+ class="baht-step baht-step--${a} ${t ? "baht-step--sidebar" : ""}"
4062
+ aria-current=${a === "current" ? "step" : "false"}
4063
+ >
4064
+ ${t ? h : n`<span class="baht-step-marker" aria-hidden="true">${a === "done" ? "✓" : i + 1}</span>`}
4065
+ <span class="baht-step-label">${e}</span>
4066
+ ${a === "done" ? n`<span class="baht-visually-hidden"> (${v("stepDone")})</span>` : a === "current" ? n`<span class="baht-visually-hidden"> (${v("stepCurrent")})</span>` : h}
4067
+ </li>`;
4068
+ })}
4069
+ </ol>`;
4070
+ }
4071
+ };
4072
+ me([
4073
+ l({ attribute: !1 })
4074
+ ], Gt.prototype, "steps", 2);
4075
+ me([
4076
+ l({ type: Number })
4077
+ ], Gt.prototype, "current", 2);
4078
+ me([
4079
+ l()
4080
+ ], Gt.prototype, "variant", 2);
4081
+ Gt = me([
4082
+ u("baht-steps")
4083
+ ], Gt);
4084
+ var vi = Object.defineProperty, $i = Object.getOwnPropertyDescriptor, Y = (t, e, i, a) => {
4085
+ for (var s = a > 1 ? void 0 : a ? $i(e, i) : e, r = t.length - 1, o; r >= 0; r--)
4086
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
4087
+ return a && s && vi(e, i, s), s;
4088
+ };
4089
+ const yi = {
4090
+ "1/4": "baht-field--w-1-4",
4091
+ "1/2": "baht-field--w-1-2",
4092
+ "3/4": "baht-field--w-3-4",
4093
+ full: "baht-field--w-full"
4094
+ }, ss = /* @__PURE__ */ new Map();
4095
+ function gi(t) {
4096
+ let e = ss.get(t);
4097
+ return e || (e = is(t), ss.set(t, e)), e;
4098
+ }
4099
+ let V = class extends $ {
4100
+ constructor() {
4101
+ super(...arguments), this.value = {}, this.registry = {}, this.options = {}, this.fieldStates = {}, this.flags = {}, this.readonly = !1, this.edits = {}, this.errors = [], this.dynamicOptions = /* @__PURE__ */ new Map(), this.optionsSnapshots = /* @__PURE__ */ new Map(), this.optionsEpoch = /* @__PURE__ */ new Map(), this.warnedViews = /* @__PURE__ */ new Set(), this.flagCache = {};
4102
+ }
4103
+ get effectiveForm() {
4104
+ return this.form ? ((this.flagCache.form !== this.form || this.flagCache.flags !== this.flags) && (this.flagCache = {
4105
+ form: this.form,
4106
+ flags: this.flags,
4107
+ out: as(this.form, this.flags)
4108
+ }), this.flagCache.out) : this.form;
4109
+ }
4110
+ willUpdate(t) {
4111
+ t.has("value") && (this.edits = {}), (t.has("form") || t.has("flags")) && (this.dynamicOptions.clear(), this.optionsSnapshots.clear(), this.optionsEpoch.clear()), (t.has("form") || t.has("flags") || t.has("value") || t.has("registry")) && this.syncDynamicOptions();
4112
+ }
4113
+ /**
4114
+ * Refetch `options_from` options whose dep snapshot changed. Sync fetchers
4115
+ * land immediately; async ones re-render on resolve (stale responses are
4116
+ * dropped by epoch).
4117
+ */
4118
+ syncDynamicOptions() {
4119
+ var e, i;
4120
+ const t = this.getData();
4121
+ for (const a of ((e = this.effectiveForm) == null ? void 0 : e.fields) ?? []) {
4122
+ if (!a.options_from) continue;
4123
+ const s = JSON.stringify((a.options_deps ?? []).map((m) => t[m] ?? null));
4124
+ if (this.optionsSnapshots.get(a.key) === s) continue;
4125
+ this.optionsSnapshots.set(a.key, s);
4126
+ const r = (this.optionsEpoch.get(a.key) ?? 0) + 1;
4127
+ this.optionsEpoch.set(a.key, r);
4128
+ const o = (i = this.registry.options) == null ? void 0 : i[a.options_from];
4129
+ if (!o) {
4130
+ console.warn(`[bahtui] unknown options fetcher "${a.options_from}" — skipped`), this.dynamicOptions.set(a.key, []);
4131
+ continue;
4132
+ }
4133
+ const c = o(t);
4134
+ c instanceof Promise ? c.then((m) => {
4135
+ this.optionsEpoch.get(a.key) === r && (this.dynamicOptions.set(a.key, m), this.requestUpdate());
4136
+ }).catch((m) => {
4137
+ console.warn(`[bahtui] options fetcher "${a.options_from}" failed`, m), this.optionsEpoch.get(a.key) === r && this.optionsSnapshots.delete(a.key);
4138
+ }) : this.dynamicOptions.set(a.key, c);
4139
+ }
4140
+ }
4141
+ /**
4142
+ * A user edit invalidates every field whose options_deps include the edited
4143
+ * key — their values reset to defaults, cascading down chains
4144
+ * (province -> district -> subdistrict).
4145
+ */
4146
+ clearDependents(t) {
4147
+ var a, s;
4148
+ const e = [t], i = /* @__PURE__ */ new Set();
4149
+ for (; e.length > 0; ) {
4150
+ const r = e.shift();
4151
+ for (const o of ((a = this.effectiveForm) == null ? void 0 : a.fields) ?? [])
4152
+ !((s = o.options_deps) != null && s.includes(r)) || i.has(o.key) || (i.add(o.key), this.edits = { ...this.edits, [o.key]: se(o) }, e.push(o.key));
4153
+ }
4154
+ }
4155
+ get sortedFields() {
4156
+ if (!this.form) return [];
4157
+ const t = Me(this.effectiveForm, this.view);
4158
+ return t || (this.view !== void 0 && !this.warnedViews.has(this.view) && (this.warnedViews.add(this.view), console.warn(`[bahtui] unknown view "${this.view}" — showing the full form`)), Me(this.effectiveForm) ?? []);
4159
+ }
4160
+ stateFor(t) {
4161
+ return this.fieldStates[t.key] ?? {
4162
+ visible: !0,
4163
+ enabled: !t.disabled,
4164
+ readonly: !!t.readonly,
4165
+ required: !!t.required,
4166
+ computed: !1
4167
+ };
4168
+ }
4169
+ valueFor(t) {
4170
+ return Object.hasOwn(this.edits, t.key) ? this.edits[t.key] : Object.hasOwn(this.value, t.key) ? this.value[t.key] : se(t);
4171
+ }
4172
+ // ---- public API (spec 01 §6) ----
4173
+ /** Debounced keystrokes still in a control land in `edits` before anyone reads them. */
4174
+ flushTyped() {
4175
+ var t;
4176
+ if (q())
4177
+ for (const e of this.querySelectorAll(":scope > .baht-form > .baht-field > *"))
4178
+ (t = e.flushTyped) == null || t.call(e);
4179
+ }
4180
+ getData() {
4181
+ var e;
4182
+ this.flushTyped();
4183
+ const t = {};
4184
+ for (const i of ((e = this.effectiveForm) == null ? void 0 : e.fields) ?? [])
4185
+ i.type === "label" || i.type === "section" || (t[i.key] = this.valueFor(i));
4186
+ return t;
4187
+ }
4188
+ setValue(t) {
4189
+ this.edits = { ...this.edits, ...t }, this.requestUpdate();
4190
+ }
4191
+ validate() {
4192
+ const t = [], e = this.getData();
4193
+ for (const a of this.sortedFields) {
4194
+ if (a.type === "label" || a.type === "section") continue;
4195
+ const s = this.stateFor(a);
4196
+ if (!s.visible) continue;
4197
+ const r = s.required === !!a.required ? a : { ...a, required: s.required };
4198
+ t.push(...Ae(r, this.valueFor(a), this.registry, e));
4199
+ }
4200
+ this.errors = t;
4201
+ const i = { valid: t.length === 0, errors: t };
4202
+ return this.dispatchEvent(
4203
+ new CustomEvent("baht-validity", { detail: i, bubbles: !0, composed: !0 })
4204
+ ), i;
4205
+ }
4206
+ reset() {
4207
+ this.edits = {}, this.value = {}, this.errors = [], this.requestUpdate();
4208
+ }
4209
+ // ---- internal ----
4210
+ onFieldInput(t, e) {
4211
+ var s;
4212
+ e.stopPropagation();
4213
+ let { value: i } = e.detail;
4214
+ const a = t.formatter ? (s = this.registry.formatters) == null ? void 0 : s[t.formatter] : void 0;
4215
+ t.formatter && !a && console.warn(`[bahtui] unknown formatter "${t.formatter}" — skipped`), a && (i = a(i)), this.edits = { ...this.edits, [t.key]: i }, this.clearDependents(t.key), this.syncDynamicOptions(), (this.options.validateOn ?? "change") === "change" && this.errors.length > 0 && this.validate(), this.dispatchEvent(
4216
+ new CustomEvent("baht-change", {
4217
+ detail: { form_name: this.form.form_name, key: t.key, value: i, data: this.getData() },
4218
+ bubbles: !0,
4219
+ composed: !0
4220
+ })
4221
+ );
4222
+ }
4223
+ /** Validate a single field against current form data (siblings included). */
4224
+ validateOneField(t) {
4225
+ const e = this.stateFor(t);
4226
+ if (!e.visible) return [];
4227
+ const i = this.getData(), a = e.required === !!t.required ? t : { ...t, required: e.required };
4228
+ return Ae(a, this.valueFor(t), this.registry, i);
4229
+ }
4230
+ /** `validateOn: 'blur'` — validate just the field the user left, same as
4231
+ * how errors are shown elsewhere (merged into `this.errors`, painted by
4232
+ * `renderField`/`.baht-error`). No-op for 'change'/'submit' modes. */
4233
+ onFieldBlur(t) {
4234
+ if ((this.options.validateOn ?? "change") !== "blur") return;
4235
+ const e = this.validateOneField(t), i = this.errors.filter((a) => a.key !== t.key);
4236
+ this.errors = [...i, ...e];
4237
+ }
4238
+ renderField(t) {
4239
+ var k, b;
4240
+ const e = ns[t.type];
4241
+ if (!e)
4242
+ return console.warn(`[bahtui] unknown field type "${t.type}" — skipped`), h;
4243
+ const i = this.stateFor(t), a = yi[t.width ?? "full"] ?? "baht-field--w-full", s = ((k = this.errors.find((w) => w.key === t.key)) == null ? void 0 : k.message) ?? null;
4244
+ if (this.readonly && t.type !== "label" && t.type !== "section")
4245
+ return this.renderReadonlyField(t, a, i.visible);
4246
+ const r = t.options_from ? { ...t, options: this.dynamicOptions.get(t.key) ?? t.options ?? [] } : t, o = this.valueFor(t), c = !i.enabled, m = this.readonly || i.readonly, g = this.options.inputDebounce, _ = (w) => this.onControlInput(t.key, w), p = gi(e);
4247
+ let f;
4248
+ if (t.type === "repeater") {
4249
+ const w = this.errors.filter((D) => D.key.startsWith(`${t.key}[`));
4250
+ f = ee`<${p}
4251
+ .field=${r}
4252
+ .value=${o}
4253
+ .disabled=${c}
4254
+ .readonly=${m}
4255
+ .required=${i.required}
4256
+ .error=${s}
4257
+ .debounce=${g}
4258
+ .rowErrors=${w}
4259
+ @baht-input=${_}
4260
+ ></${p}>`;
4261
+ } else if (t.type === "file") {
4262
+ let w;
4263
+ t.uploader && (w = (b = this.registry.uploaders) == null ? void 0 : b[t.uploader], w || console.warn(`[bahtui] unknown uploader "${t.uploader}" — capture only`)), f = ee`<${p}
4264
+ .field=${r}
4265
+ .value=${o}
4266
+ .disabled=${c}
4267
+ .readonly=${m}
4268
+ .required=${i.required}
4269
+ .error=${s}
4270
+ .debounce=${g}
4271
+ .uploader=${w}
4272
+ @baht-input=${_}
4273
+ ></${p}>`;
4274
+ } else
4275
+ f = ee`<${p}
4276
+ .field=${r}
4277
+ .value=${o}
4278
+ .disabled=${c}
4279
+ .readonly=${m}
4280
+ .required=${i.required}
4281
+ .error=${s}
4282
+ .debounce=${g}
4283
+ @baht-input=${_}
4284
+ ></${p}>`;
4285
+ return n`<div
4286
+ class="baht-field ${a} ${i.visible ? "" : "baht-field--hidden"}"
4287
+ data-key=${t.key}
4288
+ data-type=${t.type}
4289
+ data-testid="${this.form.form_id}.${t.key}"
4290
+ @focusout=${() => this.onFieldBlur(t)}
4291
+ >
4292
+ ${f}
4293
+ </div>`;
4294
+ }
4295
+ /**
4296
+ * Resolve the descriptor at event time — it may have changed since the control
4297
+ * was first rendered (the same node is reused across renders, see render()).
4298
+ */
4299
+ onControlInput(t, e) {
4300
+ var a;
4301
+ const i = (a = this.effectiveForm) == null ? void 0 : a.fields.find((s) => s.key === t);
4302
+ i && this.onFieldInput(i, e);
4303
+ }
4304
+ renderReadonlyField(t, e, i) {
4305
+ const a = t.options_from ? this.dynamicOptions.get(t.key) ?? t.options ?? [] : t.options, s = us(t, this.valueFor(t), a), r = s.kind === "empty" ? n`<span class="baht-readonly-value baht-readonly-value--empty">${v("emptyValue")}</span>` : s.kind === "text" ? n`<span class="baht-readonly-value">${s.text}</span>` : s.kind === "chips" ? n`<span class="baht-readonly-value baht-readonly-chips"
4306
+ >${s.items.map((o) => n`<span class="baht-readonly-chip">${o}</span>`)}</span
4307
+ >` : n`<div class="baht-readonly-rows">
4308
+ ${s.rows.map(
4309
+ (o) => n`<div class="baht-readonly-row">
4310
+ ${o.map(
4311
+ (c) => n`<span class="baht-readonly-cell"
4312
+ ><span class="baht-readonly-cell-label">${c.label}</span
4313
+ ><span class="baht-readonly-cell-value">${c.text}</span></span
4314
+ >`
4315
+ )}
4316
+ </div>`
4317
+ )}
4318
+ </div>`;
4319
+ return n`<div
4320
+ class="baht-field ${e} baht-field--readonly ${i ? "" : "baht-field--hidden"}"
4321
+ data-key=${t.key}
4322
+ data-type=${t.type}
4323
+ data-testid="${this.form.form_id}.${t.key}"
4324
+ >
4325
+ ${t.label ? n`<span class="baht-label">${t.label}</span>` : h}
4326
+ ${r}
4327
+ </div>`;
4328
+ }
4329
+ render() {
4330
+ return n`<div class="baht-form ${this.readonly ? "baht-form--readonly" : ""}">
4331
+ ${Oe(
4332
+ this.sortedFields,
4333
+ (t) => t.key,
4334
+ (t) => this.renderField(t)
4335
+ )}
4336
+ </div>`;
4337
+ }
4338
+ };
4339
+ Y([
4340
+ l({ attribute: !1 })
4341
+ ], V.prototype, "form", 2);
4342
+ Y([
4343
+ l({ attribute: !1 })
4344
+ ], V.prototype, "value", 2);
4345
+ Y([
4346
+ l({ attribute: !1 })
4347
+ ], V.prototype, "registry", 2);
4348
+ Y([
4349
+ l({ attribute: !1 })
4350
+ ], V.prototype, "options", 2);
4351
+ Y([
4352
+ l({ attribute: !1 })
4353
+ ], V.prototype, "fieldStates", 2);
4354
+ Y([
4355
+ l({ type: String })
4356
+ ], V.prototype, "view", 2);
4357
+ Y([
4358
+ l({ attribute: !1 })
4359
+ ], V.prototype, "flags", 2);
4360
+ Y([
4361
+ l({ type: Boolean })
4362
+ ], V.prototype, "readonly", 2);
4363
+ Y([
4364
+ y()
4365
+ ], V.prototype, "edits", 2);
4366
+ Y([
4367
+ y()
4368
+ ], V.prototype, "errors", 2);
4369
+ V = Y([
4370
+ u("baht-form")
4371
+ ], V);
4372
+ var wi = Object.defineProperty, xi = Object.getOwnPropertyDescriptor, N = (t, e, i, a) => {
4373
+ for (var s = a > 1 ? void 0 : a ? xi(e, i) : e, r = t.length - 1, o; r >= 0; r--)
4374
+ (o = t[r]) && (s = (a ? o(e, i, s) : o(s)) || s);
4375
+ return a && s && wi(e, i, s), s;
4376
+ };
4377
+ let T = class extends $ {
4378
+ constructor() {
4379
+ super(...arguments), this.value = {}, this.registry = {}, this.validateGate = !0, this.showBack = !0, this.flags = {}, this.showSteps = !1, this.stepsVariant = "default", this.data = {}, this.derived = null, this.current = null, this.approvalError = null, this.history = [], this.flagCache = {};
4380
+ }
4381
+ get currentFormName() {
4382
+ return this.current;
4383
+ }
4384
+ get effectiveWorkflow() {
4385
+ return this.workflow ? ((this.flagCache.workflow !== this.workflow || this.flagCache.flags !== this.flags) && (this.flagCache = {
4386
+ workflow: this.workflow,
4387
+ flags: this.flags,
4388
+ out: as(this.workflow, this.flags)
4389
+ }), this.flagCache.out) : this.workflow;
4390
+ }
4391
+ willUpdate(t) {
4392
+ var e, i;
4393
+ t.has("workflow") || t.has("value") ? (this.data = structuredClone(this.value ?? {}), this.reevaluate(), this.history = [], this.current = ((e = this.visibleForms[0]) == null ? void 0 : e.form_name) ?? null, this.approvalError = null) : t.has("flags") && (this.reevaluate(), this.current && !this.visibleForms.some((a) => a.form_name === this.current) && (this.current = ((i = this.visibleForms[0]) == null ? void 0 : i.form_name) ?? null));
4394
+ }
4395
+ reevaluate() {
4396
+ this.derived = bs(this.effectiveWorkflow, this.data), this.data = this.derived.data;
4397
+ }
4398
+ /** Forms in ascending order whose derived visibility is true. */
4399
+ get visibleForms() {
4400
+ var e;
4401
+ const t = [...((e = this.effectiveWorkflow) == null ? void 0 : e.forms) ?? []].sort((i, a) => i.order - a.order);
4402
+ return this.derived ? t.filter((i) => {
4403
+ var a;
4404
+ return ((a = this.derived.forms[i.form_name]) == null ? void 0 : a.visible) !== !1;
4405
+ }) : t;
4406
+ }
4407
+ get currentForm() {
4408
+ return this.visibleForms.find((t) => t.form_name === this.current) ?? null;
4409
+ }
4410
+ /** Where next() would go from here: a form_name or 'end' (spec 03 §6). */
4411
+ get navTarget() {
4412
+ var a;
4413
+ if (!this.current) return "end";
4414
+ const t = this.effectiveWorkflow;
4415
+ if (t.transitions && t.transitions.length > 0)
4416
+ return fs(t, this.current, this.data);
4417
+ const e = this.visibleForms, i = e.findIndex((s) => s.form_name === this.current);
4418
+ return ((a = e[i + 1]) == null ? void 0 : a.form_name) ?? "end";
4419
+ }
4420
+ get isLast() {
4421
+ return this.current !== null && this.navTarget === "end";
4422
+ }
4423
+ fieldStatesFor(t) {
4424
+ const e = {};
4425
+ if (!this.derived) return e;
4426
+ const i = `${t}.`;
4427
+ for (const [a, s] of Object.entries(this.derived.fields))
4428
+ a.startsWith(i) && (e[a.slice(i.length)] = s);
4429
+ return e;
4430
+ }
4431
+ get formEl() {
4432
+ return this.querySelector("baht-form");
4433
+ }
4434
+ // ---- public API (spec 03 §2) ----
4435
+ getData() {
4436
+ var t;
4437
+ return ((t = this.derived) == null ? void 0 : t.data) ?? this.data;
4438
+ }
4439
+ /**
4440
+ * Host/store write into one form's data — same path a user edit takes
4441
+ * (rules reevaluate, `baht-data-change` fires) but WITHOUT the step reset
4442
+ * that re-feeding the `value` prop causes.
4443
+ */
4444
+ setValue(t, e) {
4445
+ var i;
4446
+ this.data = { ...this.data, [t]: { ...this.data[t], ...e } }, this.reevaluate(), this.current && !this.visibleForms.some((a) => a.form_name === this.current) && (this.current = ((i = this.visibleForms[0]) == null ? void 0 : i.form_name) ?? null), this.emit("baht-data-change", { data: this.getData() });
4447
+ }
4448
+ next() {
4449
+ const t = this.currentForm;
4450
+ if (!t) return;
4451
+ if (t.kind === "approval") {
4452
+ this.decide("approved");
4453
+ return;
4454
+ }
4455
+ let e = { valid: !0, errors: [] };
4456
+ this.formEl && (e = this.formEl.validate()), !(this.validateGate && !e.valid) && (this.reevaluate(), this.advance(e));
4457
+ }
4458
+ /** Advance past the current form: submit+complete at 'end', else step to navTarget. */
4459
+ advance(t = {}) {
4460
+ const e = { ...t, data: this.getData() }, i = this.navTarget;
4461
+ if (i === "end") {
4462
+ this.emit("baht-submit", e), this.emit("baht-complete", { data: this.getData(), status: "completed" });
4463
+ return;
4464
+ }
4465
+ const a = this.visibleForms.find((s) => s.form_name === i);
4466
+ if (!a || a.form_name === this.current) {
4467
+ const s = a ? "self-transition" : "target-hidden";
4468
+ console.warn(
4469
+ `[bahtui] cannot advance from "${this.current}": target "${i}" is ` + (a ? "the current form (self-transition)" : "not visible")
4470
+ ), this.emit("baht-nav-blocked", {
4471
+ form_name: this.current,
4472
+ target: i,
4473
+ reason: s,
4474
+ data: this.getData()
4475
+ });
4476
+ return;
4477
+ }
4478
+ this.history.push(this.current), this.current = a.form_name, this.emit("baht-next", { form_name: a.form_name, order: a.order, ...e }), this.emit("baht-step-change", {
4479
+ form_name: a.form_name,
4480
+ order: a.order,
4481
+ direction: "forward"
4482
+ });
4483
+ }
4484
+ /** Approve the current approval step (same as pressing its Approve button). */
4485
+ approve() {
4486
+ this.decide("approved");
4487
+ }
4488
+ /** Reject the current approval step (same as pressing its Reject button). */
4489
+ reject() {
4490
+ this.decide("rejected");
4491
+ }
4492
+ decide(t) {
4493
+ var m;
4494
+ const e = this.currentForm;
4495
+ if (!e || e.kind !== "approval") return;
4496
+ const i = e.approval ?? {}, a = String(((m = this.data[e.form_name]) == null ? void 0 : m.comment) ?? ""), s = i.comment ?? "optional";
4497
+ if ((s === "required" || s === "requireOnReject" && t === "rejected") && a.trim() === "") {
4498
+ this.approvalError = v("commentRequired");
4499
+ return;
4500
+ }
4501
+ this.approvalError = null, this.data = {
4502
+ ...this.data,
4503
+ [e.form_name]: { ...this.data[e.form_name], decision: t, comment: a }
4504
+ }, this.reevaluate();
4505
+ const o = { form_name: e.form_name, decision: t, comment: a, data: this.getData() };
4506
+ if (t === "approved") {
4507
+ this.emit("baht-approve", o), this.advance({ decision: t, comment: a });
4508
+ return;
4509
+ }
4510
+ this.emit("baht-reject", o);
4511
+ const c = i.on_reject ?? { action: "end" };
4512
+ c.action === "goto" && this.visibleForms.some((g) => g.form_name === c.form) ? this.gotoForm(c.form) : this.emit("baht-complete", { data: this.getData(), status: "rejected" });
4513
+ }
4514
+ /** Jump back to a visible form, truncating the history to that point. */
4515
+ gotoForm(t) {
4516
+ const e = this.history.indexOf(t);
4517
+ this.history = e >= 0 ? this.history.slice(0, e) : [], this.current = t;
4518
+ const i = this.effectiveWorkflow.forms.find((a) => a.form_name === t);
4519
+ this.emit("baht-step-change", { form_name: t, order: (i == null ? void 0 : i.order) ?? 0, direction: "back" });
4520
+ }
4521
+ back() {
4522
+ let t = this.history.pop();
4523
+ for (; t !== void 0 && !this.visibleForms.some((i) => i.form_name === t); )
4524
+ t = this.history.pop();
4525
+ if (!t) return;
4526
+ this.current = t, this.approvalError = null;
4527
+ const e = this.effectiveWorkflow.forms.find((i) => i.form_name === t);
4528
+ this.emit("baht-step-change", { form_name: t, order: (e == null ? void 0 : e.order) ?? 0, direction: "back" });
4529
+ }
4530
+ gotoStart() {
4531
+ var t;
4532
+ this.history = [], this.current = ((t = this.visibleForms[0]) == null ? void 0 : t.form_name) ?? null, this.approvalError = null;
4533
+ }
4534
+ // ---- internal ----
4535
+ onFormChange(t) {
4536
+ var s;
4537
+ t.stopPropagation();
4538
+ const { form_name: e, key: i, value: a } = t.detail;
4539
+ this.data = { ...this.data, [e]: { ...this.data[e], [i]: a } }, this.reevaluate(), this.current && !this.visibleForms.some((r) => r.form_name === this.current) && (this.current = ((s = this.visibleForms[0]) == null ? void 0 : s.form_name) ?? null), this.emit("baht-data-change", { data: this.getData() });
4540
+ }
4541
+ onCommentInput(t, e) {
4542
+ this.data = { ...this.data, [t]: { ...this.data[t], comment: e } }, this.reevaluate(), e.trim() !== "" && (this.approvalError = null), this.emit("baht-data-change", { data: this.getData() });
4543
+ }
4544
+ emit(t, e) {
4545
+ this.dispatchEvent(new CustomEvent(t, { detail: e, bubbles: !0, composed: !0 }));
4546
+ }
4547
+ // ---- approval summary (spec 03 §4) ----
4548
+ /** Forms the approval step summarizes: configured list, else every earlier plain form. */
4549
+ summary_forms(t) {
4550
+ var a;
4551
+ const e = (a = t.approval) == null ? void 0 : a.summary_forms, i = this.visibleForms.filter(
4552
+ (s) => s.form_name !== t.form_name && s.kind !== "approval"
4553
+ );
4554
+ return e ? i.filter((s) => e.includes(s.form_name)) : i.filter((s) => s.order < t.order);
4555
+ }
4556
+ renderApproval(t) {
4557
+ var a, s;
4558
+ const e = ((a = t.approval) == null ? void 0 : a.comment) ?? "optional", i = this.summary_forms(t);
4559
+ return n`<div class="baht-approval">
4560
+ <div class="baht-approval-summary">
4561
+ ${i.length === 0 ? n`<p class="baht-approval-empty">${v("nothingToReview")}</p>` : i.map(
4562
+ (r) => n`<section class="baht-approval-group">
4563
+ <h4 class="baht-approval-group-title">${r.form_name}</h4>
4564
+ <baht-form
4565
+ readonly
4566
+ .form=${r}
4567
+ .value=${this.data[r.form_name] ?? {}}
4568
+ .fieldStates=${this.fieldStatesFor(r.form_name)}
4569
+ ></baht-form>
4570
+ </section>`
4571
+ )}
4572
+ </div>
4573
+ ${e !== "hidden" ? n`<label class="baht-approval-comment">
4574
+ <span class="baht-approval-comment-label">
4575
+ ${v("comment")}${e === "required" ? v("commentRequiredSuffix") : ""}
4576
+ </span>
4577
+ <textarea
4578
+ rows="3"
4579
+ aria-required=${e === "required" ? "true" : h}
4580
+ aria-invalid=${this.approvalError ? "true" : h}
4581
+ .value=${String(((s = this.data[t.form_name]) == null ? void 0 : s.comment) ?? "")}
4582
+ @input=${(r) => this.onCommentInput(t.form_name, r.target.value)}
4583
+ ></textarea>
4584
+ </label>` : h}
4585
+ ${this.approvalError ? n`<p class="baht-error" role="alert">${this.approvalError}</p>` : h}
4586
+ </div>`;
4587
+ }
4588
+ render() {
4589
+ var s, r;
4590
+ const t = this.currentForm;
4591
+ if (!t) return n`<div class="baht-workflow"></div>`;
4592
+ const e = t.kind === "approval", i = this.visibleForms, a = i.findIndex((o) => o.form_name === t.form_name);
4593
+ return n`<div
4594
+ class="baht-workflow"
4595
+ data-step=${t.form_name}
4596
+ data-testid="${this.workflow.workflow_id}.${t.form_name}"
4597
+ >
4598
+ <div class="baht-visually-hidden" role="status">
4599
+ ${v("step", { current: a + 1, total: i.length })}
4600
+ </div>
4601
+ ${this.showSteps ? n`<baht-steps
4602
+ .steps=${i.map((o) => o.form_name)}
4603
+ .current=${a}
4604
+ .variant=${this.stepsVariant}
4605
+ ></baht-steps>` : h}
4606
+ ${e ? this.renderApproval(t) : n`<baht-form
4607
+ .form=${t}
4608
+ .value=${this.data[t.form_name] ?? {}}
4609
+ .registry=${this.registry}
4610
+ .fieldStates=${this.fieldStatesFor(t.form_name)}
4611
+ .view=${t.view}
4612
+ @baht-change=${(o) => this.onFormChange(o)}
4613
+ ></baht-form>`}
4614
+ <div class="baht-workflow-nav">
4615
+ ${this.showBack && this.history.length > 0 ? n`<button type="button" class="baht-button baht-button--back"
4616
+ data-testid="${this.workflow.workflow_id}.back"
4617
+ @click=${() => this.back()}
4618
+ >
4619
+ ${this.backLabel ?? v("back")}
4620
+ </button>` : h}
4621
+ ${e ? n`<button
4622
+ type="button"
4623
+ class="baht-button baht-button--reject"
4624
+ data-testid="${this.workflow.workflow_id}.reject"
4625
+ @click=${() => this.decide("rejected")}
4626
+ >
4627
+ ${((s = t.approval) == null ? void 0 : s.reject_label) ?? v("reject")}
4628
+ </button>
4629
+ <button
4630
+ type="button"
4631
+ class="baht-button baht-button--next baht-button--approve"
4632
+ data-testid="${this.workflow.workflow_id}.approve"
4633
+ @click=${() => this.decide("approved")}
4634
+ >
4635
+ ${((r = t.approval) == null ? void 0 : r.approve_label) ?? v("approve")}
4636
+ </button>` : n`<button type="button" class="baht-button baht-button--next"
4637
+ data-testid="${this.workflow.workflow_id}.next"
4638
+ @click=${() => this.next()}
4639
+ >
4640
+ ${this.isLast ? this.submitLabel ?? v("submit") : this.nextLabel ?? v("next")}
4641
+ </button>`}
4642
+ </div>
4643
+ </div>`;
4644
+ }
4645
+ };
4646
+ N([
4647
+ l({ attribute: !1 })
4648
+ ], T.prototype, "workflow", 2);
4649
+ N([
4650
+ l({ attribute: !1 })
4651
+ ], T.prototype, "value", 2);
4652
+ N([
4653
+ l({ attribute: !1 })
4654
+ ], T.prototype, "registry", 2);
4655
+ N([
4656
+ l({ type: Boolean, attribute: "validate-gate" })
4657
+ ], T.prototype, "validateGate", 2);
4658
+ N([
4659
+ l({ attribute: "next-label" })
4660
+ ], T.prototype, "nextLabel", 2);
4661
+ N([
4662
+ l({ attribute: "submit-label" })
4663
+ ], T.prototype, "submitLabel", 2);
4664
+ N([
4665
+ l({ attribute: "back-label" })
4666
+ ], T.prototype, "backLabel", 2);
4667
+ N([
4668
+ l({ type: Boolean, attribute: "show-back" })
4669
+ ], T.prototype, "showBack", 2);
4670
+ N([
4671
+ l({ attribute: !1 })
4672
+ ], T.prototype, "flags", 2);
4673
+ N([
4674
+ l({ type: Boolean, attribute: "show-steps" })
4675
+ ], T.prototype, "showSteps", 2);
4676
+ N([
4677
+ l({ attribute: "steps-variant" })
4678
+ ], T.prototype, "stepsVariant", 2);
4679
+ N([
4680
+ y()
4681
+ ], T.prototype, "data", 2);
4682
+ N([
4683
+ y()
4684
+ ], T.prototype, "derived", 2);
4685
+ N([
4686
+ y()
4687
+ ], T.prototype, "current", 2);
4688
+ N([
4689
+ y()
4690
+ ], T.prototype, "approvalError", 2);
4691
+ T = N([
4692
+ u("baht-workflow")
4693
+ ], T);
4694
+ export {
4695
+ Ye as $,
4696
+ nt as A,
4697
+ Ot as B,
4698
+ kt as C,
4699
+ Ve as D,
4700
+ it as E,
4701
+ ft as F,
4702
+ S as G,
4703
+ Be as H,
4704
+ Fe as I,
4705
+ oe as J,
4706
+ Vt as K,
4707
+ ht as L,
4708
+ ie as M,
4709
+ z as N,
4710
+ Ut as O,
4711
+ Gt as P,
4712
+ P as Q,
4713
+ De as R,
4714
+ Ne as S,
4715
+ Ce as T,
4716
+ Ke as U,
4717
+ _t as V,
4718
+ E as W,
4719
+ F as X,
4720
+ T as Y,
4721
+ ns as Z,
4722
+ lt as _,
4723
+ bt as a,
4724
+ Na as a0,
4725
+ qt as a1,
4726
+ le as a2,
4727
+ Ee as a3,
4728
+ be as a4,
4729
+ zt as b,
4730
+ R as c,
4731
+ re as d,
4732
+ Pt as e,
4733
+ Q as f,
4734
+ ze as g,
4735
+ ae as h,
4736
+ Ue as i,
4737
+ H as j,
4738
+ Ht as k,
4739
+ Ft as l,
4740
+ Kt as m,
4741
+ Dt as n,
4742
+ vt as o,
4743
+ V as p,
4744
+ ct as q,
4745
+ Le as r,
4746
+ pt as s,
4747
+ Z as t,
4748
+ Ct as u,
4749
+ at as v,
4750
+ G as w,
4751
+ Re as x,
4752
+ qe as y,
4753
+ mt as z
4754
+ };