bank20baht-ui 0.0.1

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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +190 -0
  3. package/dist/chunks/baht-toast-BlZBbneT.js +324 -0
  4. package/dist/components/baht-form.d.ts +41 -0
  5. package/dist/components/baht-workflow.d.ts +64 -0
  6. package/dist/components/base.d.ts +38 -0
  7. package/dist/components/primitives/baht-accordion.d.ts +26 -0
  8. package/dist/components/primitives/baht-alert.d.ts +17 -0
  9. package/dist/components/primitives/baht-badge.d.ts +19 -0
  10. package/dist/components/primitives/baht-breadcrumbs.d.ts +22 -0
  11. package/dist/components/primitives/baht-button.d.ts +31 -0
  12. package/dist/components/primitives/baht-card.d.ts +18 -0
  13. package/dist/components/primitives/baht-checkbox.d.ts +7 -0
  14. package/dist/components/primitives/baht-code.d.ts +18 -0
  15. package/dist/components/primitives/baht-datepicker.d.ts +6 -0
  16. package/dist/components/primitives/baht-fieldset.d.ts +17 -0
  17. package/dist/components/primitives/baht-file.d.ts +9 -0
  18. package/dist/components/primitives/baht-filter.d.ts +24 -0
  19. package/dist/components/primitives/baht-input.d.ts +6 -0
  20. package/dist/components/primitives/baht-link.d.ts +17 -0
  21. package/dist/components/primitives/baht-list.d.ts +28 -0
  22. package/dist/components/primitives/baht-modal.d.ts +32 -0
  23. package/dist/components/primitives/baht-multiselect.d.ts +8 -0
  24. package/dist/components/primitives/baht-number.d.ts +5 -0
  25. package/dist/components/primitives/baht-otp.d.ts +26 -0
  26. package/dist/components/primitives/baht-pagination.d.ts +21 -0
  27. package/dist/components/primitives/baht-progress.d.ts +16 -0
  28. package/dist/components/primitives/baht-radio.d.ts +5 -0
  29. package/dist/components/primitives/baht-range.d.ts +21 -0
  30. package/dist/components/primitives/baht-rating.d.ts +22 -0
  31. package/dist/components/primitives/baht-select.d.ts +5 -0
  32. package/dist/components/primitives/baht-skeleton.d.ts +16 -0
  33. package/dist/components/primitives/baht-spinner.d.ts +13 -0
  34. package/dist/components/primitives/baht-table.d.ts +44 -0
  35. package/dist/components/primitives/baht-text.d.ts +8 -0
  36. package/dist/components/primitives/baht-textarea.d.ts +5 -0
  37. package/dist/components/primitives/baht-timeline.d.ts +21 -0
  38. package/dist/components/primitives/baht-toast.d.ts +27 -0
  39. package/dist/components/primitives/baht-toggle.d.ts +6 -0
  40. package/dist/components/primitives/baht-tooltip.d.ts +29 -0
  41. package/dist/components/primitives/icons.d.ts +13 -0
  42. package/dist/components/primitives/index.d.ts +38 -0
  43. package/dist/core/approval.d.ts +9 -0
  44. package/dist/core/defaults.d.ts +6 -0
  45. package/dist/core/engine/conditions.d.ts +4 -0
  46. package/dist/core/engine/evaluate.d.ts +8 -0
  47. package/dist/core/engine/expressions.d.ts +3 -0
  48. package/dist/core/index.d.ts +7 -0
  49. package/dist/core/types.d.ts +166 -0
  50. package/dist/core/validators.d.ts +6 -0
  51. package/dist/custom-elements.json +7761 -0
  52. package/dist/engine.js +329 -0
  53. package/dist/index.d.ts +5 -0
  54. package/dist/index.js +1796 -0
  55. package/dist/overlay.d.ts +45 -0
  56. package/dist/overlay.js +121 -0
  57. package/dist/react.d.ts +191 -0
  58. package/dist/react.js +1 -0
  59. package/dist/tokens.css +936 -0
  60. package/dist/vscode.css-custom-data.json +6 -0
  61. package/dist/vscode.html-custom-data.json +479 -0
  62. package/dist/web-types.json +1226 -0
  63. package/package.json +94 -0
package/dist/index.js ADDED
@@ -0,0 +1,1796 @@
1
+ import { defaultValue as _t, validateField as xt, evaluate as Ot } from "./engine.js";
2
+ import { approvalFields as He, evalCondition as Ge, evalValueExpr as We, readRef as Ye } from "./engine.js";
3
+ import { B as d, a as Z, b as g } from "./chunks/baht-toast-BlZBbneT.js";
4
+ import { c as Qe, d as Xe, e as Ze, i as ts, r as es } from "./chunks/baht-toast-BlZBbneT.js";
5
+ import { nothing as h, html as l } from "lit";
6
+ import { property as n, customElement as p, query as ot, state as O } from "lit/decorators.js";
7
+ import { ifDefined as f } from "lit/directives/if-defined.js";
8
+ var Pt = Object.defineProperty, Dt = Object.getOwnPropertyDescriptor, tt = (t, e, r, a) => {
9
+ for (var s = a > 1 ? void 0 : a ? Dt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
10
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
11
+ return a && s && Pt(e, r, s), s;
12
+ };
13
+ let K = class extends d {
14
+ constructor() {
15
+ super(...arguments), this.tone = "neutral", this.label = "", this.dot = null;
16
+ }
17
+ get showDot() {
18
+ return this.dot !== null ? this.dot : ["neutral", "success", "danger", "warning", "info"].includes(this.tone);
19
+ }
20
+ render() {
21
+ const t = this.tone === "neutral" ? "" : ` baht-badge--${this.tone}`;
22
+ return l`<span class="baht-badge${t}">
23
+ ${this.showDot ? l`<span class="baht-badge-dot" aria-hidden="true"></span>` : h}${this.label}
24
+ </span>`;
25
+ }
26
+ };
27
+ tt([
28
+ n()
29
+ ], K.prototype, "tone", 2);
30
+ tt([
31
+ n()
32
+ ], K.prototype, "label", 2);
33
+ tt([
34
+ n({ attribute: !1 })
35
+ ], K.prototype, "dot", 2);
36
+ K = tt([
37
+ p("baht-badge")
38
+ ], K);
39
+ var Bt = Object.defineProperty, Ct = Object.getOwnPropertyDescriptor, lt = (t, e, r, a) => {
40
+ for (var s = a > 1 ? void 0 : a ? Ct(e, r) : e, i = t.length - 1, o; i >= 0; i--)
41
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
42
+ return a && s && Bt(e, r, s), s;
43
+ };
44
+ let J = class extends d {
45
+ constructor() {
46
+ super(...arguments), this.variant = "inline", this.code = "";
47
+ }
48
+ firstUpdated() {
49
+ const t = this.renderRoot.querySelector(this.variant === "block" ? "pre" : "code");
50
+ t && Z(this, t);
51
+ }
52
+ render() {
53
+ return this.variant === "block" ? l`<pre class="baht-code baht-code--block" tabindex="0">${this.code}</pre>` : l`<code class="baht-code">${this.code}</code>`;
54
+ }
55
+ };
56
+ lt([
57
+ n()
58
+ ], J.prototype, "variant", 2);
59
+ lt([
60
+ n()
61
+ ], J.prototype, "code", 2);
62
+ J = lt([
63
+ p("baht-code")
64
+ ], J);
65
+ var jt = Object.defineProperty, Nt = Object.getOwnPropertyDescriptor, z = (t, e, r, a) => {
66
+ for (var s = a > 1 ? void 0 : a ? Nt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
67
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
68
+ return a && s && jt(e, r, s), s;
69
+ };
70
+ let q = class extends d {
71
+ constructor() {
72
+ super(...arguments), this.page = 1, this.totalPages = 1, this.variant = "numbered", this.siblings = 1;
73
+ }
74
+ go(t) {
75
+ const e = Math.min(Math.max(1, t), this.totalPages);
76
+ e !== this.page && this.dispatchEvent(
77
+ new CustomEvent("baht-page-change", {
78
+ detail: { page: e },
79
+ bubbles: !0,
80
+ composed: !0
81
+ })
82
+ );
83
+ }
84
+ /** Visible page numbers with `null` marking an ellipsis gap. */
85
+ get pageItems() {
86
+ const { page: t, totalPages: e, siblings: r } = this, a = /* @__PURE__ */ new Set([1, e]);
87
+ for (let c = t - r; c <= t + r; c++)
88
+ c >= 1 && c <= e && a.add(c);
89
+ const s = [...a].sort((c, v) => c - v), i = [];
90
+ let o = 0;
91
+ for (const c of s)
92
+ o && c - o === 2 ? i.push(o + 1) : o && c - o > 2 && i.push(null), i.push(c), o = c;
93
+ return i;
94
+ }
95
+ render() {
96
+ const t = this.page <= 1, e = this.page >= this.totalPages;
97
+ return l`<nav class="baht-pagination" aria-label="Pagination">
98
+ <button type="button" aria-label="Previous page" ?disabled=${t} @click=${() => this.go(this.page - 1)}>«</button>
99
+ ${this.variant === "compact" ? l`<span class="baht-pagination-label">Page ${this.page} of ${this.totalPages}</span>` : this.pageItems.map(
100
+ (r) => r === null ? l`<span class="baht-pagination-ellipsis">…</span>` : l`<button
101
+ type="button"
102
+ aria-current=${r === this.page ? "page" : h}
103
+ @click=${() => this.go(r)}
104
+ >${r}</button>`
105
+ )}
106
+ <button type="button" aria-label="Next page" ?disabled=${e} @click=${() => this.go(this.page + 1)}>»</button>
107
+ </nav>`;
108
+ }
109
+ };
110
+ z([
111
+ n({ type: Number })
112
+ ], q.prototype, "page", 2);
113
+ z([
114
+ n({ type: Number, attribute: "total-pages" })
115
+ ], q.prototype, "totalPages", 2);
116
+ z([
117
+ n()
118
+ ], q.prototype, "variant", 2);
119
+ z([
120
+ n({ type: Number })
121
+ ], q.prototype, "siblings", 2);
122
+ q = z([
123
+ p("baht-pagination")
124
+ ], q);
125
+ var Et = Object.defineProperty, It = Object.getOwnPropertyDescriptor, b = (t, e, r, a) => {
126
+ for (var s = a > 1 ? void 0 : a ? It(e, r) : e, i = t.length - 1, o; i >= 0; i--)
127
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
128
+ return a && s && Et(e, r, s), s;
129
+ };
130
+ let u = class extends d {
131
+ constructor() {
132
+ 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.page = 1, this.totalPages = 1;
133
+ }
134
+ get columnKeys() {
135
+ const t = Object.keys(this.columns);
136
+ return t.length > 0 ? t : this.items.length > 0 ? Object.keys(this.items[0]) : [];
137
+ }
138
+ labelFor(t) {
139
+ return this.columns[t] ?? t.replace(/_/g, " ").replace(/\b\w/g, (e) => e.toUpperCase());
140
+ }
141
+ emitRow(t, e) {
142
+ this.clickable && this.dispatchEvent(
143
+ new CustomEvent("baht-row-click", {
144
+ detail: { row: t, index: e, id: this.rowKey ? t[this.rowKey] : void 0 },
145
+ bubbles: !0,
146
+ composed: !0
147
+ })
148
+ );
149
+ }
150
+ cell(t, e) {
151
+ const r = this.renderers[e], a = t[e];
152
+ return r ? r(a, t) : a == null ? "" : String(a);
153
+ }
154
+ renderBody(t) {
155
+ const e = t.length + (this.showIndex ? 1 : 0);
156
+ return this.loading ? l`${Array.from(
157
+ { length: this.skeletonRows },
158
+ (r, a) => l`<tr>
159
+ ${this.showIndex ? l`<td class="baht-table-index">${this.indexOffset + a + 1}</td>` : h}
160
+ ${t.map(() => l`<td><span class="baht-skeleton" style="height:16px;"></span></td>`)}
161
+ </tr>`
162
+ )}` : this.error ? l`<tr><td colspan=${e}><div class="baht-table-state baht-table-state--error">${this.errorMessage}</div></td></tr>` : this.items.length === 0 ? l`<tr><td colspan=${e}><div class="baht-table-state">${this.emptyMessage}</div></td></tr>` : l`${this.items.map(
163
+ (r, a) => l`<tr
164
+ tabindex=${this.clickable ? "0" : h}
165
+ @click=${() => this.emitRow(r, a)}
166
+ @keydown=${(s) => {
167
+ s.key !== "Enter" && s.key !== " " || (s.preventDefault(), this.emitRow(r, a));
168
+ }}
169
+ >
170
+ ${this.showIndex ? l`<td class="baht-table-index">${this.indexOffset + a + 1}</td>` : h}
171
+ ${t.map((s) => l`<td data-col=${s}>${this.cell(r, s)}</td>`)}
172
+ </tr>`
173
+ )}`;
174
+ }
175
+ render() {
176
+ const t = this.columnKeys;
177
+ return l`<div
178
+ class="baht-table-wrap"
179
+ tabindex=${this.clickable ? h : "0"}
180
+ aria-busy=${this.loading ? "true" : h}
181
+ >
182
+ <table class="baht-table">
183
+ <thead>
184
+ <tr>
185
+ ${this.showIndex ? l`<th scope="col" class="baht-table-index">No.</th>` : h}
186
+ ${t.map((e) => l`<th scope="col" data-col=${e}>${this.labelFor(e)}</th>`)}
187
+ </tr>
188
+ </thead>
189
+ <tbody>${this.renderBody(t)}</tbody>
190
+ </table>
191
+ ${this.totalPages > 1 ? l`<div class="baht-table-footer">
192
+ <baht-pagination
193
+ variant="compact"
194
+ page=${this.page}
195
+ total-pages=${this.totalPages}
196
+ ></baht-pagination>
197
+ </div>` : h}
198
+ </div>`;
199
+ }
200
+ };
201
+ b([
202
+ n({ attribute: !1 })
203
+ ], u.prototype, "items", 2);
204
+ b([
205
+ n({ attribute: !1 })
206
+ ], u.prototype, "columns", 2);
207
+ b([
208
+ n({ type: Boolean })
209
+ ], u.prototype, "loading", 2);
210
+ b([
211
+ n({ type: Boolean })
212
+ ], u.prototype, "error", 2);
213
+ b([
214
+ n({ attribute: "error-message" })
215
+ ], u.prototype, "errorMessage", 2);
216
+ b([
217
+ n({ attribute: "empty-message" })
218
+ ], u.prototype, "emptyMessage", 2);
219
+ b([
220
+ n({ type: Boolean, attribute: "show-index" })
221
+ ], u.prototype, "showIndex", 2);
222
+ b([
223
+ n({ type: Number, attribute: "index-offset" })
224
+ ], u.prototype, "indexOffset", 2);
225
+ b([
226
+ n({ type: Number, attribute: "skeleton-rows" })
227
+ ], u.prototype, "skeletonRows", 2);
228
+ b([
229
+ n({ attribute: "row-key" })
230
+ ], u.prototype, "rowKey", 2);
231
+ b([
232
+ n({ type: Boolean })
233
+ ], u.prototype, "clickable", 2);
234
+ b([
235
+ n({ attribute: !1 })
236
+ ], u.prototype, "renderers", 2);
237
+ b([
238
+ n({ type: Number })
239
+ ], u.prototype, "page", 2);
240
+ b([
241
+ n({ type: Number, attribute: "total-pages" })
242
+ ], u.prototype, "totalPages", 2);
243
+ u = b([
244
+ p("baht-table")
245
+ ], u);
246
+ var Ft = Object.defineProperty, qt = Object.getOwnPropertyDescriptor, D = (t, e, r, a) => {
247
+ for (var s = a > 1 ? void 0 : a ? qt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
248
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
249
+ return a && s && Ft(e, r, s), s;
250
+ };
251
+ let _ = class extends d {
252
+ constructor() {
253
+ 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;
254
+ }
255
+ emitItem(t, e) {
256
+ this.clickable && this.dispatchEvent(
257
+ new CustomEvent("baht-item-click", {
258
+ detail: { item: t, index: e, id: t.id },
259
+ bubbles: !0,
260
+ composed: !0
261
+ })
262
+ );
263
+ }
264
+ renderRows() {
265
+ return this.loading ? l`${Array.from(
266
+ { length: this.skeletonRows },
267
+ () => l`<div class="baht-list-item">
268
+ <div class="baht-list-main">
269
+ <span class="baht-skeleton baht-skeleton--text" style="width:40%; margin-bottom:6px;"></span>
270
+ <span class="baht-skeleton baht-skeleton--text" style="width:65%;"></span>
271
+ </div>
272
+ </div>`
273
+ )}` : this.error ? l`<div class="baht-list-state baht-list-state--error">${this.errorMessage}</div>` : this.items.length === 0 ? l`<div class="baht-list-state">${this.emptyMessage}</div>` : l`${this.items.map(
274
+ (t, e) => l`<div
275
+ class="baht-list-item"
276
+ role="listitem"
277
+ tabindex=${this.clickable ? "0" : h}
278
+ @click=${() => this.emitItem(t, e)}
279
+ @keydown=${(r) => {
280
+ r.key !== "Enter" && r.key !== " " || (r.preventDefault(), this.emitItem(t, e));
281
+ }}
282
+ >
283
+ <div class="baht-list-main">
284
+ <div class="baht-list-title">${t.title}</div>
285
+ ${t.subtitle ? l`<div class="baht-list-subtitle">${t.subtitle}</div>` : h}
286
+ </div>
287
+ ${t.badge ? l`<baht-badge tone=${t.badgeTone ?? "neutral"} label=${t.badge}></baht-badge>` : h}
288
+ ${t.meta ? l`<span class="baht-list-meta">${t.meta}</span>` : h}
289
+ </div>`
290
+ )}`;
291
+ }
292
+ render() {
293
+ return l`<div class="baht-list" role="list">${this.renderRows()}</div>`;
294
+ }
295
+ };
296
+ D([
297
+ n({ attribute: !1 })
298
+ ], _.prototype, "items", 2);
299
+ D([
300
+ n({ type: Boolean })
301
+ ], _.prototype, "loading", 2);
302
+ D([
303
+ n({ type: Boolean })
304
+ ], _.prototype, "error", 2);
305
+ D([
306
+ n({ attribute: "error-message" })
307
+ ], _.prototype, "errorMessage", 2);
308
+ D([
309
+ n({ attribute: "empty-message" })
310
+ ], _.prototype, "emptyMessage", 2);
311
+ D([
312
+ n({ type: Number, attribute: "skeleton-rows" })
313
+ ], _.prototype, "skeletonRows", 2);
314
+ D([
315
+ n({ type: Boolean })
316
+ ], _.prototype, "clickable", 2);
317
+ _ = D([
318
+ p("baht-list")
319
+ ], _);
320
+ var St = Object.defineProperty, kt = Object.getOwnPropertyDescriptor, H = (t, e, r, a) => {
321
+ for (var s = a > 1 ? void 0 : a ? kt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
322
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
323
+ return a && s && St(e, r, s), s;
324
+ };
325
+ let P = class extends d {
326
+ constructor() {
327
+ super(...arguments), this.text = "", this.position = "top", this.dismissed = !1, this.uid = ++P.instances;
328
+ }
329
+ get tooltipId() {
330
+ return `baht-tooltip-${this.uid}`;
331
+ }
332
+ /**
333
+ * Point aria-describedby at the tooltip from the focusable child (light DOM,
334
+ * so the id reference works). No focusable child -> the anchor itself becomes
335
+ * one, so keyboard users can still surface the tooltip.
336
+ */
337
+ wireDescribedBy() {
338
+ const t = this.anchorEl.querySelector(
339
+ "button, a[href], input, select, textarea, [tabindex]"
340
+ );
341
+ 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));
342
+ }
343
+ firstUpdated() {
344
+ Z(this, this.anchorEl), this.wireDescribedBy(), setTimeout(() => this.isConnected && this.wireDescribedBy(), 0);
345
+ }
346
+ onKeydown(t) {
347
+ t.key === "Escape" && (this.dismissed = !0);
348
+ }
349
+ rearm() {
350
+ this.dismissed = !1;
351
+ }
352
+ render() {
353
+ return l`<span
354
+ class="baht-tooltip-host${this.dismissed ? " baht-tooltip-host--dismissed" : ""}"
355
+ @keydown=${this.onKeydown}
356
+ @mouseleave=${this.rearm}
357
+ @focusout=${this.rearm}
358
+ >
359
+ <span class="baht-tooltip-anchor"></span>
360
+ <span class="baht-tooltip baht-tooltip--${this.position}" id=${this.tooltipId} role="tooltip">${this.text}</span>
361
+ </span>`;
362
+ }
363
+ };
364
+ P.instances = 0;
365
+ H([
366
+ n()
367
+ ], P.prototype, "text", 2);
368
+ H([
369
+ n()
370
+ ], P.prototype, "position", 2);
371
+ H([
372
+ ot(".baht-tooltip-anchor")
373
+ ], P.prototype, "anchorEl", 2);
374
+ H([
375
+ O()
376
+ ], P.prototype, "dismissed", 2);
377
+ P = H([
378
+ p("baht-tooltip")
379
+ ], P);
380
+ var At = Object.defineProperty, Lt = Object.getOwnPropertyDescriptor, L = (t, e, r, a) => {
381
+ for (var s = a > 1 ? void 0 : a ? Lt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
382
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
383
+ return a && s && At(e, r, s), s;
384
+ };
385
+ let j = class extends d {
386
+ constructor() {
387
+ super(...arguments), this.tone = "info", this.heading = "", this.message = "", this.dismissible = !1, this.hidden = !1;
388
+ }
389
+ dismiss() {
390
+ this.hidden = !0, this.dispatchEvent(new CustomEvent("baht-dismiss", { bubbles: !0, composed: !0 }));
391
+ }
392
+ render() {
393
+ return this.hidden ? h : l`<div class="baht-alert baht-alert--${this.tone}" role="alert">
394
+ <div class="baht-alert-main">
395
+ ${this.heading ? l`<div class="baht-alert-title">${this.heading}</div>` : h}
396
+ ${this.message ? l`<div class="baht-alert-message">${this.message}</div>` : h}
397
+ </div>
398
+ ${this.dismissible ? l`<button type="button" class="baht-alert-dismiss" aria-label="Dismiss" @click=${() => this.dismiss()}>×</button>` : h}
399
+ </div>`;
400
+ }
401
+ };
402
+ L([
403
+ n()
404
+ ], j.prototype, "tone", 2);
405
+ L([
406
+ n()
407
+ ], j.prototype, "heading", 2);
408
+ L([
409
+ n()
410
+ ], j.prototype, "message", 2);
411
+ L([
412
+ n({ type: Boolean })
413
+ ], j.prototype, "dismissible", 2);
414
+ L([
415
+ n({ type: Boolean, reflect: !0 })
416
+ ], j.prototype, "hidden", 2);
417
+ j = L([
418
+ p("baht-alert")
419
+ ], j);
420
+ var Rt = Object.defineProperty, Mt = Object.getOwnPropertyDescriptor, R = (t, e, r, a) => {
421
+ for (var s = a > 1 ? void 0 : a ? Mt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
422
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
423
+ return a && s && Rt(e, r, s), s;
424
+ };
425
+ let N = class extends d {
426
+ constructor() {
427
+ super(...arguments), this.value = 0, this.max = 5, this.readonly = !1, this.label = "Rating", this.hover = 0;
428
+ }
429
+ emitValue(t) {
430
+ this.dispatchEvent(
431
+ new CustomEvent("baht-change", { detail: { value: t }, bubbles: !0, composed: !0 })
432
+ );
433
+ }
434
+ pick(t) {
435
+ this.readonly || this.emitValue(t === this.value ? 0 : t);
436
+ }
437
+ /** APG radio-group keys: arrows move the value, Home/End jump the ends. */
438
+ onKeydown(t, e) {
439
+ var a;
440
+ if (this.readonly) return;
441
+ let r;
442
+ if (t.key === "ArrowRight" || t.key === "ArrowUp") r = Math.min(e + 1, this.max);
443
+ else if (t.key === "ArrowLeft" || t.key === "ArrowDown") r = Math.max(e - 1, 1);
444
+ else if (t.key === "Home") r = 1;
445
+ else if (t.key === "End") r = this.max;
446
+ else return;
447
+ t.preventDefault(), this.emitValue(r), (a = this.querySelectorAll("button")[r - 1]) == null || a.focus();
448
+ }
449
+ setHover(t) {
450
+ this.readonly || (this.hover = t);
451
+ }
452
+ render() {
453
+ const t = this.hover || this.value;
454
+ return l`<div
455
+ class="baht-rating"
456
+ role="radiogroup"
457
+ aria-label=${this.label}
458
+ @mouseleave=${() => this.setHover(0)}
459
+ >
460
+ ${Array.from({ length: this.max }, (e, r) => {
461
+ const a = r + 1, s = this.value || 1;
462
+ return l`<button
463
+ type="button"
464
+ class=${a <= t ? "baht-rating--on" : ""}
465
+ role="radio"
466
+ aria-checked=${a === this.value}
467
+ aria-label="${a} of ${this.max}"
468
+ tabindex=${a === s ? "0" : "-1"}
469
+ ?disabled=${this.readonly}
470
+ @mouseenter=${() => this.setHover(a)}
471
+ @click=${() => this.pick(a)}
472
+ @keydown=${(i) => this.onKeydown(i, a)}
473
+ >★</button>`;
474
+ })}
475
+ </div>`;
476
+ }
477
+ };
478
+ R([
479
+ n({ type: Number })
480
+ ], N.prototype, "value", 2);
481
+ R([
482
+ n({ type: Number })
483
+ ], N.prototype, "max", 2);
484
+ R([
485
+ n({ type: Boolean })
486
+ ], N.prototype, "readonly", 2);
487
+ R([
488
+ n()
489
+ ], N.prototype, "label", 2);
490
+ R([
491
+ O()
492
+ ], N.prototype, "hover", 2);
493
+ N = R([
494
+ p("baht-rating")
495
+ ], N);
496
+ var Tt = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, B = (t, e, r, a) => {
497
+ for (var s = a > 1 ? void 0 : a ? Kt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
498
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
499
+ return a && s && Tt(e, r, s), s;
500
+ };
501
+ let y = class extends d {
502
+ constructor() {
503
+ super(...arguments), this.value = 0, this.min = 0, this.max = 100, this.step = 1, this.label = "", this.disabled = !1, this.showValue = !0, this.uid = ++y.instances;
504
+ }
505
+ get inputId() {
506
+ return `baht-range-${this.uid}`;
507
+ }
508
+ onInput(t) {
509
+ const e = Number(t.target.value);
510
+ this.dispatchEvent(
511
+ new CustomEvent("baht-change", { detail: { value: e }, bubbles: !0, composed: !0 })
512
+ );
513
+ }
514
+ render() {
515
+ return l`<div class="baht-range">
516
+ ${this.label ? l`<label class="baht-label" for=${this.inputId}>${this.label}</label>` : h}
517
+ <div class="baht-range-row">
518
+ <input
519
+ type="range"
520
+ id=${this.inputId}
521
+ aria-label=${this.label ? h : "Value"}
522
+ .value=${String(this.value)}
523
+ min=${this.min}
524
+ max=${this.max}
525
+ step=${this.step}
526
+ ?disabled=${this.disabled}
527
+ @input=${(t) => this.onInput(t)}
528
+ />
529
+ ${this.showValue ? l`<span class="baht-range-value">${this.value}</span>` : h}
530
+ </div>
531
+ </div>`;
532
+ }
533
+ };
534
+ y.instances = 0;
535
+ B([
536
+ n({ type: Number })
537
+ ], y.prototype, "value", 2);
538
+ B([
539
+ n({ type: Number })
540
+ ], y.prototype, "min", 2);
541
+ B([
542
+ n({ type: Number })
543
+ ], y.prototype, "max", 2);
544
+ B([
545
+ n({ type: Number })
546
+ ], y.prototype, "step", 2);
547
+ B([
548
+ n()
549
+ ], y.prototype, "label", 2);
550
+ B([
551
+ n({ type: Boolean })
552
+ ], y.prototype, "disabled", 2);
553
+ B([
554
+ n({ type: Boolean, attribute: "show-value" })
555
+ ], y.prototype, "showValue", 2);
556
+ y = B([
557
+ p("baht-range")
558
+ ], y);
559
+ var Vt = Object.defineProperty, Ut = Object.getOwnPropertyDescriptor, M = (t, e, r, a) => {
560
+ for (var s = a > 1 ? void 0 : a ? Ut(e, r) : e, i = t.length - 1, o; i >= 0; i--)
561
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
562
+ return a && s && Vt(e, r, s), s;
563
+ };
564
+ let E = class extends d {
565
+ constructor() {
566
+ super(...arguments), this.length = 6, this.value = "", this.disabled = !1, this.mode = "numeric", this.label = "One-time code";
567
+ }
568
+ get chars() {
569
+ return Array.from({ length: this.length }, (t, e) => this.value[e] ?? "");
570
+ }
571
+ inputs() {
572
+ return Array.from(this.querySelectorAll("input"));
573
+ }
574
+ clean(t) {
575
+ return this.mode === "numeric" ? t.replace(/\D/g, "") : t;
576
+ }
577
+ commit(t) {
578
+ this.value = t.slice(0, this.length), this.dispatchEvent(
579
+ new CustomEvent("baht-change", {
580
+ detail: { value: this.value },
581
+ bubbles: !0,
582
+ composed: !0
583
+ })
584
+ ), this.value.length === this.length && this.dispatchEvent(
585
+ new CustomEvent("baht-complete", {
586
+ detail: { value: this.value },
587
+ bubbles: !0,
588
+ composed: !0
589
+ })
590
+ );
591
+ }
592
+ onInput(t, e) {
593
+ var i;
594
+ const r = e.target, a = this.clean(r.value).slice(-1);
595
+ r.value = a;
596
+ const s = this.chars;
597
+ s[t] = a, this.commit(s.join("")), a && t < this.length - 1 && ((i = this.inputs()[t + 1]) == null || i.focus());
598
+ }
599
+ onKeydown(t, e) {
600
+ var r;
601
+ if (e.key === "Backspace" && !this.chars[t] && t > 0) {
602
+ const a = this.chars;
603
+ a[t - 1] = "", this.commit(a.join("")), (r = this.inputs()[t - 1]) == null || r.focus(), e.preventDefault();
604
+ }
605
+ }
606
+ onPaste(t) {
607
+ var r, a;
608
+ t.preventDefault();
609
+ const e = this.clean(((r = t.clipboardData) == null ? void 0 : r.getData("text")) ?? "").slice(0, this.length);
610
+ e && (this.commit(e), (a = this.inputs()[Math.min(e.length, this.length - 1)]) == null || a.focus());
611
+ }
612
+ render() {
613
+ return l`<div class="baht-otp" role="group" aria-label=${this.label} @paste=${(t) => this.onPaste(t)}>
614
+ ${this.chars.map(
615
+ (t, e) => l`<input
616
+ type="text"
617
+ inputmode=${this.mode === "numeric" ? "numeric" : "text"}
618
+ maxlength="1"
619
+ autocomplete=${e === 0 ? "one-time-code" : "off"}
620
+ aria-label="Character ${e + 1} of ${this.length}"
621
+ .value=${t}
622
+ ?disabled=${this.disabled}
623
+ @input=${(r) => this.onInput(e, r)}
624
+ @keydown=${(r) => this.onKeydown(e, r)}
625
+ />`
626
+ )}
627
+ </div>`;
628
+ }
629
+ };
630
+ M([
631
+ n({ type: Number })
632
+ ], E.prototype, "length", 2);
633
+ M([
634
+ n()
635
+ ], E.prototype, "value", 2);
636
+ M([
637
+ n({ type: Boolean })
638
+ ], E.prototype, "disabled", 2);
639
+ M([
640
+ n()
641
+ ], E.prototype, "mode", 2);
642
+ M([
643
+ n()
644
+ ], E.prototype, "label", 2);
645
+ E = M([
646
+ p("baht-otp")
647
+ ], E);
648
+ var zt = Object.defineProperty, Ht = Object.getOwnPropertyDescriptor, T = (t, e, r, a) => {
649
+ for (var s = a > 1 ? void 0 : a ? Ht(e, r) : e, i = t.length - 1, o; i >= 0; i--)
650
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
651
+ return a && s && zt(e, r, s), s;
652
+ };
653
+ let I = class extends d {
654
+ constructor() {
655
+ super(...arguments), this.options = [], this.selected = [], this.multiple = !0, this.disabled = !1, this.label = "Filters";
656
+ }
657
+ toggle(t) {
658
+ const e = this.selected.includes(t);
659
+ let r;
660
+ this.multiple ? (r = e ? this.selected.filter((s) => s !== t) : [...this.selected, t], r = this.options.map((s) => s.key).filter((s) => r.includes(s))) : r = e ? [] : [t], this.dispatchEvent(
661
+ new CustomEvent("baht-change", { detail: { selected: r }, bubbles: !0, composed: !0 })
662
+ );
663
+ }
664
+ render() {
665
+ return l`<div class="baht-filter" role="group" aria-label=${this.label}>
666
+ ${this.options.map(
667
+ (t) => l`<button
668
+ type="button"
669
+ aria-pressed=${this.selected.includes(t.key)}
670
+ ?disabled=${this.disabled}
671
+ @click=${() => this.toggle(t.key)}
672
+ >${t.label}</button>`
673
+ )}
674
+ </div>`;
675
+ }
676
+ };
677
+ T([
678
+ n({ attribute: !1 })
679
+ ], I.prototype, "options", 2);
680
+ T([
681
+ n({ attribute: !1 })
682
+ ], I.prototype, "selected", 2);
683
+ T([
684
+ n({ type: Boolean })
685
+ ], I.prototype, "multiple", 2);
686
+ T([
687
+ n({ type: Boolean })
688
+ ], I.prototype, "disabled", 2);
689
+ T([
690
+ n()
691
+ ], I.prototype, "label", 2);
692
+ I = T([
693
+ p("baht-filter")
694
+ ], I);
695
+ var Gt = Object.defineProperty, Wt = Object.getOwnPropertyDescriptor, et = (t, e, r, a) => {
696
+ for (var s = a > 1 ? void 0 : a ? Wt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
697
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
698
+ return a && s && Gt(e, r, s), s;
699
+ };
700
+ let V = class extends d {
701
+ constructor() {
702
+ super(...arguments), this.variant = "rect", this.width = "100%", this.height = "";
703
+ }
704
+ render() {
705
+ const t = this.height || (this.variant === "text" ? "1em" : "20px"), e = this.variant === "rect" ? "" : ` baht-skeleton--${this.variant}`;
706
+ return l`<span
707
+ class="baht-skeleton${e}"
708
+ style="width:${this.width}; height:${t};"
709
+ aria-hidden="true"
710
+ ></span>`;
711
+ }
712
+ };
713
+ et([
714
+ n()
715
+ ], V.prototype, "variant", 2);
716
+ et([
717
+ n()
718
+ ], V.prototype, "width", 2);
719
+ et([
720
+ n()
721
+ ], V.prototype, "height", 2);
722
+ V = et([
723
+ p("baht-skeleton")
724
+ ], V);
725
+ var Yt = Object.defineProperty, Jt = Object.getOwnPropertyDescriptor, G = (t, e, r, a) => {
726
+ for (var s = a > 1 ? void 0 : a ? Jt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
727
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
728
+ return a && s && Yt(e, r, s), s;
729
+ };
730
+ let S = class extends d {
731
+ constructor() {
732
+ super(...arguments), this.value = null, this.tone = "primary", this.showLabel = !1, this.label = "Progress";
733
+ }
734
+ render() {
735
+ const t = this.value == null || Number.isNaN(this.value), e = t ? 0 : Math.min(100, Math.max(0, this.value)), r = this.tone === "primary" ? "" : ` baht-progress--${this.tone}`;
736
+ return l`<div>
737
+ <div
738
+ class="baht-progress${r}${t ? " baht-progress--indeterminate" : ""}"
739
+ role="progressbar"
740
+ aria-label=${this.label}
741
+ aria-valuemin="0"
742
+ aria-valuemax="100"
743
+ aria-valuenow=${t ? h : e}
744
+ >
745
+ <div class="baht-progress-bar" style=${t ? h : `width:${e}%`}></div>
746
+ </div>
747
+ ${this.showLabel && !t ? l`<div class="baht-progress-label">${e}%</div>` : h}
748
+ </div>`;
749
+ }
750
+ };
751
+ G([
752
+ n({ type: Number })
753
+ ], S.prototype, "value", 2);
754
+ G([
755
+ n()
756
+ ], S.prototype, "tone", 2);
757
+ G([
758
+ n({ type: Boolean, attribute: "show-label" })
759
+ ], S.prototype, "showLabel", 2);
760
+ G([
761
+ n()
762
+ ], S.prototype, "label", 2);
763
+ S = G([
764
+ p("baht-progress")
765
+ ], S);
766
+ var Qt = Object.defineProperty, Xt = Object.getOwnPropertyDescriptor, nt = (t, e, r, a) => {
767
+ for (var s = a > 1 ? void 0 : a ? Xt(e, r) : e, i = t.length - 1, o; i >= 0; i--)
768
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
769
+ return a && s && Qt(e, r, s), s;
770
+ };
771
+ let Q = class extends d {
772
+ constructor() {
773
+ super(...arguments), this.size = "md", this.label = "Loading";
774
+ }
775
+ render() {
776
+ const t = this.size === "md" ? "" : ` baht-spinner--${this.size}`;
777
+ return l`<span class="baht-spinner${t}" role="status" aria-label=${this.label}></span>`;
778
+ }
779
+ };
780
+ nt([
781
+ n()
782
+ ], Q.prototype, "size", 2);
783
+ nt([
784
+ n()
785
+ ], Q.prototype, "label", 2);
786
+ Q = nt([
787
+ p("baht-spinner")
788
+ ], Q);
789
+ var Zt = Object.defineProperty, te = Object.getOwnPropertyDescriptor, W = (t, e, r, a) => {
790
+ for (var s = a > 1 ? void 0 : a ? te(e, r) : e, i = t.length - 1, o; i >= 0; i--)
791
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
792
+ return a && s && Zt(e, r, s), s;
793
+ };
794
+ let k = class extends d {
795
+ constructor() {
796
+ super(...arguments), this.heading = "", this.subtitle = "", this.hero = !1;
797
+ }
798
+ firstUpdated() {
799
+ Z(this, this.bodyEl);
800
+ }
801
+ render() {
802
+ return l`<div class="baht-card${this.hero ? " baht-card--hero" : ""}">
803
+ ${this.heading ? l`<div class="baht-card-title">${this.heading}</div>` : h}
804
+ ${this.subtitle ? l`<div class="baht-card-subtitle">${this.subtitle}</div>` : h}
805
+ <div class="baht-card-body"></div>
806
+ </div>`;
807
+ }
808
+ };
809
+ W([
810
+ n()
811
+ ], k.prototype, "heading", 2);
812
+ W([
813
+ n()
814
+ ], k.prototype, "subtitle", 2);
815
+ W([
816
+ n({ type: Boolean })
817
+ ], k.prototype, "hero", 2);
818
+ W([
819
+ ot(".baht-card-body")
820
+ ], k.prototype, "bodyEl", 2);
821
+ k = W([
822
+ p("baht-card")
823
+ ], k);
824
+ var ee = Object.defineProperty, se = Object.getOwnPropertyDescriptor, st = (t, e, r, a) => {
825
+ for (var s = a > 1 ? void 0 : a ? se(e, r) : e, i = t.length - 1, o; i >= 0; i--)
826
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
827
+ return a && s && ee(e, r, s), s;
828
+ };
829
+ let U = class extends d {
830
+ constructor() {
831
+ super(...arguments), this.legend = "", this.disabled = !1;
832
+ }
833
+ firstUpdated() {
834
+ Z(this, this.bodyEl);
835
+ }
836
+ render() {
837
+ return l`<fieldset class="baht-fieldset" ?disabled=${this.disabled}>
838
+ ${this.legend ? l`<legend>${this.legend}</legend>` : h}
839
+ <div class="baht-fieldset-body"></div>
840
+ </fieldset>`;
841
+ }
842
+ };
843
+ st([
844
+ n()
845
+ ], U.prototype, "legend", 2);
846
+ st([
847
+ n({ type: Boolean })
848
+ ], U.prototype, "disabled", 2);
849
+ st([
850
+ ot(".baht-fieldset-body")
851
+ ], U.prototype, "bodyEl", 2);
852
+ U = st([
853
+ p("baht-fieldset")
854
+ ], U);
855
+ var re = Object.defineProperty, ae = Object.getOwnPropertyDescriptor, gt = (t, e, r, a) => {
856
+ for (var s = a > 1 ? void 0 : a ? ae(e, r) : e, i = t.length - 1, o; i >= 0; i--)
857
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
858
+ return a && s && re(e, r, s), s;
859
+ };
860
+ let at = class extends d {
861
+ constructor() {
862
+ super(...arguments), this.items = [];
863
+ }
864
+ render() {
865
+ return l`<div class="baht-timeline" role="list">
866
+ ${this.items.map(
867
+ (t, e) => l`<div class="baht-timeline-item" role="listitem">
868
+ <div class="baht-timeline-rail">
869
+ <span class="baht-timeline-dot${t.tone && t.tone !== "primary" ? ` baht-timeline-dot--${t.tone}` : ""}"></span>
870
+ ${e < this.items.length - 1 ? l`<span class="baht-timeline-line"></span>` : h}
871
+ </div>
872
+ <div class="baht-timeline-main">
873
+ <div class="baht-timeline-title">
874
+ ${t.title}
875
+ ${t.time ? l`<span class="baht-timeline-time"> · ${t.time}</span>` : h}
876
+ </div>
877
+ ${t.description ? l`<div class="baht-timeline-desc">${t.description}</div>` : h}
878
+ </div>
879
+ </div>`
880
+ )}
881
+ </div>`;
882
+ }
883
+ };
884
+ gt([
885
+ n({ attribute: !1 })
886
+ ], at.prototype, "items", 2);
887
+ at = gt([
888
+ p("baht-timeline")
889
+ ], at);
890
+ var ie = Object.defineProperty, oe = Object.getOwnPropertyDescriptor, rt = (t, e, r, a) => {
891
+ for (var s = a > 1 ? void 0 : a ? oe(e, r) : e, i = t.length - 1, o; i >= 0; i--)
892
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
893
+ return a && s && ie(e, r, s), s;
894
+ };
895
+ let F = class extends d {
896
+ constructor() {
897
+ super(...arguments), this.items = [], this.multiple = !1, this.openSet = /* @__PURE__ */ new Set(), this.uid = ++F.instances;
898
+ }
899
+ willUpdate(t) {
900
+ t.has("items") && (this.openSet = new Set(this.items.flatMap((e, r) => e.open ? [r] : [])));
901
+ }
902
+ toggle(t) {
903
+ const e = !this.openSet.has(t), r = this.multiple ? new Set(this.openSet) : /* @__PURE__ */ new Set();
904
+ e ? r.add(t) : r.delete(t), this.openSet = r, this.dispatchEvent(
905
+ new CustomEvent("baht-toggle", { detail: { index: t, open: e }, bubbles: !0, composed: !0 })
906
+ );
907
+ }
908
+ render() {
909
+ return l`<div class="baht-accordion">
910
+ ${this.items.map((t, e) => {
911
+ const r = this.openSet.has(e), a = `baht-acc-${this.uid}-t-${e}`, s = `baht-acc-${this.uid}-p-${e}`;
912
+ return l`<div class="baht-accordion-item${r ? " baht-accordion-item--open" : ""}">
913
+ <button
914
+ type="button"
915
+ class="baht-accordion-trigger"
916
+ id=${a}
917
+ aria-expanded=${r}
918
+ aria-controls=${r ? s : h}
919
+ @click=${() => this.toggle(e)}
920
+ >
921
+ <span>${t.title}</span>
922
+ <span class="baht-accordion-chevron" aria-hidden="true">▾</span>
923
+ </button>
924
+ ${r ? l`<div class="baht-accordion-content" id=${s} role="region" aria-labelledby=${a}>${t.content}</div>` : h}
925
+ </div>`;
926
+ })}
927
+ </div>`;
928
+ }
929
+ };
930
+ F.instances = 0;
931
+ rt([
932
+ n({ attribute: !1 })
933
+ ], F.prototype, "items", 2);
934
+ rt([
935
+ n({ type: Boolean })
936
+ ], F.prototype, "multiple", 2);
937
+ rt([
938
+ O()
939
+ ], F.prototype, "openSet", 2);
940
+ F = rt([
941
+ p("baht-accordion")
942
+ ], F);
943
+ var le = Object.defineProperty, ne = Object.getOwnPropertyDescriptor, Y = (t, e, r, a) => {
944
+ for (var s = a > 1 ? void 0 : a ? ne(e, r) : e, i = t.length - 1, o; i >= 0; i--)
945
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
946
+ return a && s && le(e, r, s), s;
947
+ };
948
+ let A = class extends d {
949
+ constructor() {
950
+ super(...arguments), this.href = "", this.label = "", this.external = !1, this.externalHint = "opens in new tab";
951
+ }
952
+ render() {
953
+ return l`<a
954
+ class="baht-link"
955
+ href=${this.href || h}
956
+ target=${this.external ? "_blank" : h}
957
+ rel=${this.external ? "noopener noreferrer" : h}
958
+ >${this.label}${this.external ? l` <span class="baht-link-external" aria-hidden="true">↗</span><span class="baht-visually-hidden"> (${this.externalHint})</span>` : h}</a>`;
959
+ }
960
+ };
961
+ Y([
962
+ n()
963
+ ], A.prototype, "href", 2);
964
+ Y([
965
+ n()
966
+ ], A.prototype, "label", 2);
967
+ Y([
968
+ n({ type: Boolean })
969
+ ], A.prototype, "external", 2);
970
+ Y([
971
+ n({ attribute: "external-hint" })
972
+ ], A.prototype, "externalHint", 2);
973
+ A = Y([
974
+ p("baht-link")
975
+ ], A);
976
+ var he = Object.defineProperty, pe = Object.getOwnPropertyDescriptor, ht = (t, e, r, a) => {
977
+ for (var s = a > 1 ? void 0 : a ? pe(e, r) : e, i = t.length - 1, o; i >= 0; i--)
978
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
979
+ return a && s && he(e, r, s), s;
980
+ };
981
+ let X = class extends d {
982
+ constructor() {
983
+ super(...arguments), this.items = [], this.separator = "›";
984
+ }
985
+ navigate(t, e) {
986
+ this.dispatchEvent(
987
+ new CustomEvent("baht-navigate", { detail: { item: t, index: e }, bubbles: !0, composed: !0 })
988
+ );
989
+ }
990
+ render() {
991
+ const t = this.items.length - 1;
992
+ return l`<nav class="baht-breadcrumbs" aria-label="Breadcrumb">
993
+ ${this.items.map((e, r) => {
994
+ const a = r < t ? l`<span class="baht-breadcrumbs-sep" aria-hidden="true">${this.separator}</span>` : h;
995
+ return r === t ? l`<span class="baht-breadcrumbs-current" aria-current="page">${e.label}</span>${a}` : e.href ? l`<a class="baht-link" href=${e.href}>${e.label}</a>${a}` : l`<a
996
+ class="baht-link"
997
+ href="#"
998
+ @click=${(s) => {
999
+ s.preventDefault(), this.navigate(e, r);
1000
+ }}
1001
+ >${e.label}</a>${a}`;
1002
+ })}
1003
+ </nav>`;
1004
+ }
1005
+ };
1006
+ ht([
1007
+ n({ attribute: !1 })
1008
+ ], X.prototype, "items", 2);
1009
+ ht([
1010
+ n()
1011
+ ], X.prototype, "separator", 2);
1012
+ X = ht([
1013
+ p("baht-breadcrumbs")
1014
+ ], X);
1015
+ var de = Object.getOwnPropertyDescriptor, ce = (t, e, r, a) => {
1016
+ for (var s = a > 1 ? void 0 : a ? de(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1017
+ (o = t[i]) && (s = o(s) || s);
1018
+ return s;
1019
+ };
1020
+ let pt = class extends g {
1021
+ renderControl() {
1022
+ return l`<input
1023
+ class="baht-control baht-control--text"
1024
+ id=${this.controlId}
1025
+ type=${this.field.type === "email" ? "email" : "text"}
1026
+ .value=${this.value == null ? "" : String(this.value)}
1027
+ placeholder=${f(this.field.placeholder)}
1028
+ maxlength=${f(this.field.maxLength)}
1029
+ autocomplete=${f(this.field.autocomplete)}
1030
+ ?disabled=${this.disabled}
1031
+ ?readonly=${this.readonly}
1032
+ ?required=${this.required}
1033
+ aria-invalid=${this.invalid}
1034
+ aria-describedby=${this.describedBy}
1035
+ @input=${(t) => this.emitInput(t.target.value)}
1036
+ />`;
1037
+ }
1038
+ };
1039
+ pt = ce([
1040
+ p("baht-input")
1041
+ ], pt);
1042
+ var ue = Object.getOwnPropertyDescriptor, be = (t, e, r, a) => {
1043
+ for (var s = a > 1 ? void 0 : a ? ue(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1044
+ (o = t[i]) && (s = o(s) || s);
1045
+ return s;
1046
+ };
1047
+ let dt = class extends g {
1048
+ renderControl() {
1049
+ return l`<textarea
1050
+ class="baht-control baht-control--textarea"
1051
+ id=${this.controlId}
1052
+ .value=${this.value == null ? "" : String(this.value)}
1053
+ placeholder=${f(this.field.placeholder)}
1054
+ maxlength=${f(this.field.maxLength)}
1055
+ rows=${this.field.rows ?? 3}
1056
+ autocomplete=${f(this.field.autocomplete)}
1057
+ ?disabled=${this.disabled}
1058
+ ?readonly=${this.readonly}
1059
+ ?required=${this.required}
1060
+ aria-invalid=${this.invalid}
1061
+ aria-describedby=${this.describedBy}
1062
+ @input=${(t) => this.emitInput(t.target.value)}
1063
+ ></textarea>`;
1064
+ }
1065
+ };
1066
+ dt = be([
1067
+ p("baht-textarea")
1068
+ ], dt);
1069
+ var ve = Object.getOwnPropertyDescriptor, me = (t, e, r, a) => {
1070
+ for (var s = a > 1 ? void 0 : a ? ve(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1071
+ (o = t[i]) && (s = o(s) || s);
1072
+ return s;
1073
+ };
1074
+ let ct = class extends g {
1075
+ renderControl() {
1076
+ return l`<input
1077
+ class="baht-control baht-control--number"
1078
+ id=${this.controlId}
1079
+ type="number"
1080
+ .value=${this.value == null ? "" : String(this.value)}
1081
+ placeholder=${f(this.field.placeholder)}
1082
+ min=${f(this.field.min)}
1083
+ max=${f(this.field.max)}
1084
+ step=${f(this.field.step)}
1085
+ ?disabled=${this.disabled}
1086
+ ?readonly=${this.readonly}
1087
+ ?required=${this.required}
1088
+ aria-invalid=${this.invalid}
1089
+ aria-describedby=${this.describedBy}
1090
+ @input=${(t) => {
1091
+ const e = t.target.value;
1092
+ this.emitInput(e === "" ? null : Number(e));
1093
+ }}
1094
+ />`;
1095
+ }
1096
+ };
1097
+ ct = me([
1098
+ p("baht-number")
1099
+ ], ct);
1100
+ var fe = Object.getOwnPropertyDescriptor, $e = (t, e, r, a) => {
1101
+ for (var s = a > 1 ? void 0 : a ? fe(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1102
+ (o = t[i]) && (s = o(s) || s);
1103
+ return s;
1104
+ };
1105
+ let ut = class extends g {
1106
+ renderControl() {
1107
+ const t = this.value == null ? "" : String(this.value);
1108
+ return l`<select
1109
+ class="baht-control baht-control--select"
1110
+ id=${this.controlId}
1111
+ .value=${t}
1112
+ ?disabled=${this.disabled || this.readonly}
1113
+ ?required=${this.required}
1114
+ aria-invalid=${this.invalid}
1115
+ aria-describedby=${this.describedBy}
1116
+ @change=${(e) => {
1117
+ const r = e.target.value;
1118
+ this.emitInput(r === "" ? null : r);
1119
+ }}
1120
+ >
1121
+ <option value="" ?selected=${t === ""}>${this.field.placeholder ?? "—"}</option>
1122
+ ${(this.field.options ?? []).map(
1123
+ (e) => l`<option value=${e.key} ?selected=${t === e.key}>${e.label}</option>`
1124
+ )}
1125
+ </select>`;
1126
+ }
1127
+ };
1128
+ ut = $e([
1129
+ p("baht-select")
1130
+ ], ut);
1131
+ var ye = Object.getOwnPropertyDescriptor, ge = (t, e, r, a) => {
1132
+ for (var s = a > 1 ? void 0 : a ? ye(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1133
+ (o = t[i]) && (s = o(s) || s);
1134
+ return s;
1135
+ };
1136
+ let bt = class extends g {
1137
+ get selected() {
1138
+ return Array.isArray(this.value) ? this.value : [];
1139
+ }
1140
+ toggle(t, e) {
1141
+ const r = e ? [...this.selected, t] : this.selected.filter((s) => s !== t), a = (this.field.options ?? []).map((s) => s.key);
1142
+ this.emitInput(a.filter((s) => r.includes(s)));
1143
+ }
1144
+ renderControl() {
1145
+ return l`<div
1146
+ class="baht-control baht-control--multiselect"
1147
+ role="group"
1148
+ aria-labelledby=${this.field.label ? this.labelId : h}
1149
+ aria-describedby=${this.describedBy}
1150
+ >
1151
+ ${(this.field.options ?? []).map(
1152
+ (t) => l`<label class="baht-option">
1153
+ <input
1154
+ type="checkbox"
1155
+ value=${t.key}
1156
+ .checked=${this.selected.includes(t.key)}
1157
+ ?disabled=${this.disabled || this.readonly}
1158
+ @change=${(e) => this.toggle(t.key, e.target.checked)}
1159
+ />
1160
+ <span>${t.label}</span>
1161
+ </label>`
1162
+ )}
1163
+ </div>`;
1164
+ }
1165
+ };
1166
+ bt = ge([
1167
+ p("baht-multiselect")
1168
+ ], bt);
1169
+ var we = Object.getOwnPropertyDescriptor, _e = (t, e, r, a) => {
1170
+ for (var s = a > 1 ? void 0 : a ? we(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1171
+ (o = t[i]) && (s = o(s) || s);
1172
+ return s;
1173
+ };
1174
+ let vt = class extends g {
1175
+ /** Label sits beside the box, so suppress the block label. */
1176
+ renderLabel() {
1177
+ return h;
1178
+ }
1179
+ renderControl() {
1180
+ return l`<label class="baht-control baht-control--checkbox baht-option">
1181
+ <input
1182
+ type="checkbox"
1183
+ id=${this.controlId}
1184
+ .checked=${this.value === !0}
1185
+ ?disabled=${this.disabled || this.readonly}
1186
+ ?required=${this.required}
1187
+ aria-invalid=${this.invalid}
1188
+ aria-describedby=${this.describedBy}
1189
+ @change=${(t) => this.emitInput(t.target.checked)}
1190
+ />
1191
+ <span class="baht-label"
1192
+ >${this.field.label}${this.required ? l`<span class="baht-required-mark">*</span>` : h}</span
1193
+ >
1194
+ </label>`;
1195
+ }
1196
+ };
1197
+ vt = _e([
1198
+ p("baht-checkbox")
1199
+ ], vt);
1200
+ var xe = Object.getOwnPropertyDescriptor, Oe = (t, e, r, a) => {
1201
+ for (var s = a > 1 ? void 0 : a ? xe(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1202
+ (o = t[i]) && (s = o(s) || s);
1203
+ return s;
1204
+ };
1205
+ let mt = class extends g {
1206
+ renderControl() {
1207
+ return l`<div
1208
+ class="baht-control baht-control--radio"
1209
+ role="radiogroup"
1210
+ aria-labelledby=${this.field.label ? this.labelId : h}
1211
+ aria-required=${this.required ? "true" : h}
1212
+ aria-invalid=${this.invalid}
1213
+ aria-describedby=${this.describedBy}
1214
+ >
1215
+ ${(this.field.options ?? []).map(
1216
+ (t) => l`<label class="baht-option">
1217
+ <input
1218
+ type="radio"
1219
+ name=${this.controlId}
1220
+ value=${t.key}
1221
+ .checked=${this.value === t.key}
1222
+ ?disabled=${this.disabled || this.readonly}
1223
+ @change=${() => this.emitInput(t.key)}
1224
+ />
1225
+ <span>${t.label}</span>
1226
+ </label>`
1227
+ )}
1228
+ </div>`;
1229
+ }
1230
+ };
1231
+ mt = Oe([
1232
+ p("baht-radio")
1233
+ ], mt);
1234
+ var Pe = Object.getOwnPropertyDescriptor, De = (t, e, r, a) => {
1235
+ for (var s = a > 1 ? void 0 : a ? Pe(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1236
+ (o = t[i]) && (s = o(s) || s);
1237
+ return s;
1238
+ };
1239
+ let ft = class extends g {
1240
+ renderLabel() {
1241
+ return h;
1242
+ }
1243
+ renderControl() {
1244
+ return l`<label class="baht-control baht-control--toggle baht-option">
1245
+ <input
1246
+ type="checkbox"
1247
+ role="switch"
1248
+ id=${this.controlId}
1249
+ aria-checked=${this.value === !0 ? "true" : "false"}
1250
+ .checked=${this.value === !0}
1251
+ ?disabled=${this.disabled || this.readonly}
1252
+ ?required=${this.required}
1253
+ aria-invalid=${this.invalid}
1254
+ aria-describedby=${this.describedBy}
1255
+ @change=${(t) => this.emitInput(t.target.checked)}
1256
+ />
1257
+ <span class="baht-toggle-track"><span class="baht-toggle-thumb"></span></span>
1258
+ <span class="baht-label"
1259
+ >${this.field.label}${this.required ? l`<span class="baht-required-mark">*</span>` : h}</span
1260
+ >
1261
+ </label>`;
1262
+ }
1263
+ };
1264
+ ft = De([
1265
+ p("baht-toggle")
1266
+ ], ft);
1267
+ var Be = Object.getOwnPropertyDescriptor, Ce = (t, e, r, a) => {
1268
+ for (var s = a > 1 ? void 0 : a ? Be(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1269
+ (o = t[i]) && (s = o(s) || s);
1270
+ return s;
1271
+ };
1272
+ let $t = class extends g {
1273
+ renderControl() {
1274
+ return l`<input
1275
+ class="baht-control baht-control--date"
1276
+ id=${this.controlId}
1277
+ type="date"
1278
+ .value=${this.value == null ? "" : String(this.value)}
1279
+ min=${f(this.field.min)}
1280
+ max=${f(this.field.max)}
1281
+ ?disabled=${this.disabled}
1282
+ ?readonly=${this.readonly}
1283
+ ?required=${this.required}
1284
+ aria-invalid=${this.invalid}
1285
+ aria-describedby=${this.describedBy}
1286
+ @change=${(t) => {
1287
+ const e = t.target.value;
1288
+ this.emitInput(e === "" ? null : e);
1289
+ }}
1290
+ />`;
1291
+ }
1292
+ };
1293
+ $t = Ce([
1294
+ p("baht-datepicker")
1295
+ ], $t);
1296
+ var je = Object.getOwnPropertyDescriptor, Ne = (t, e, r, a) => {
1297
+ for (var s = a > 1 ? void 0 : a ? je(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1298
+ (o = t[i]) && (s = o(s) || s);
1299
+ return s;
1300
+ };
1301
+ let yt = class extends g {
1302
+ renderControl() {
1303
+ return l`<input
1304
+ class="baht-control baht-control--file"
1305
+ id=${this.controlId}
1306
+ type="file"
1307
+ accept=${f(this.field.accept)}
1308
+ ?multiple=${this.field.multiple}
1309
+ ?disabled=${this.disabled || this.readonly}
1310
+ ?required=${this.required}
1311
+ aria-invalid=${this.invalid}
1312
+ aria-describedby=${this.describedBy}
1313
+ @change=${(t) => {
1314
+ const e = Array.from(t.target.files ?? []), r = this.field.maxSize ? e.filter((a) => a.size <= this.field.maxSize) : e;
1315
+ this.emitInput(this.field.multiple ? r : r[0] ?? null);
1316
+ }}
1317
+ />`;
1318
+ }
1319
+ };
1320
+ yt = Ne([
1321
+ p("baht-file")
1322
+ ], yt);
1323
+ var Ee = Object.defineProperty, Ie = Object.getOwnPropertyDescriptor, wt = (t, e, r, a) => {
1324
+ for (var s = a > 1 ? void 0 : a ? Ie(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1325
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
1326
+ return a && s && Ee(e, r, s), s;
1327
+ };
1328
+ let it = class extends d {
1329
+ render() {
1330
+ const t = this.field.variant ?? "body";
1331
+ return l`<div class="baht-text baht-text--${t}">${this.field.text ?? this.field.label ?? ""}</div>`;
1332
+ }
1333
+ };
1334
+ wt([
1335
+ n({ attribute: !1 })
1336
+ ], it.prototype, "field", 2);
1337
+ it = wt([
1338
+ p("baht-text")
1339
+ ], it);
1340
+ const Fe = {
1341
+ text: "baht-input",
1342
+ email: "baht-input",
1343
+ textarea: "baht-textarea",
1344
+ number: "baht-number",
1345
+ dropdown: "baht-select",
1346
+ multiselect: "baht-multiselect",
1347
+ checkbox: "baht-checkbox",
1348
+ radio: "baht-radio",
1349
+ toggle: "baht-toggle",
1350
+ date: "baht-datepicker",
1351
+ file: "baht-file",
1352
+ label: "baht-text"
1353
+ };
1354
+ var qe = Object.defineProperty, Se = Object.getOwnPropertyDescriptor, C = (t, e, r, a) => {
1355
+ for (var s = a > 1 ? void 0 : a ? Se(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1356
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
1357
+ return a && s && qe(e, r, s), s;
1358
+ };
1359
+ const ke = {
1360
+ "1/4": "baht-field--w-1-4",
1361
+ "1/2": "baht-field--w-1-2",
1362
+ "3/4": "baht-field--w-3-4",
1363
+ full: "baht-field--w-full"
1364
+ };
1365
+ let x = class extends d {
1366
+ constructor() {
1367
+ super(...arguments), this.value = {}, this.registry = {}, this.options = {}, this.fieldStates = {}, this.edits = {}, this.errors = [];
1368
+ }
1369
+ willUpdate(t) {
1370
+ t.has("value") && (this.edits = {});
1371
+ }
1372
+ get sortedFields() {
1373
+ var t;
1374
+ return [...((t = this.form) == null ? void 0 : t.field_data) ?? []].sort((e, r) => e.order - r.order);
1375
+ }
1376
+ stateFor(t) {
1377
+ return this.fieldStates[t.key] ?? {
1378
+ visible: !0,
1379
+ enabled: !t.disabled,
1380
+ readonly: !1,
1381
+ required: !!t.required,
1382
+ computed: !1
1383
+ };
1384
+ }
1385
+ valueFor(t) {
1386
+ return t.key in this.edits ? this.edits[t.key] : t.key in this.value ? this.value[t.key] : _t(t);
1387
+ }
1388
+ // ---- public API (spec 01 §6) ----
1389
+ getData() {
1390
+ const t = {};
1391
+ for (const e of this.sortedFields)
1392
+ e.type !== "label" && (t[e.key] = this.valueFor(e));
1393
+ return t;
1394
+ }
1395
+ setValue(t) {
1396
+ this.edits = { ...this.edits, ...t }, this.requestUpdate();
1397
+ }
1398
+ validate() {
1399
+ const t = [];
1400
+ for (const r of this.sortedFields) {
1401
+ if (r.type === "label") continue;
1402
+ const a = this.stateFor(r);
1403
+ if (!a.visible) continue;
1404
+ const s = a.required === !!r.required ? r : { ...r, required: a.required };
1405
+ t.push(...xt(s, this.valueFor(r), this.registry));
1406
+ }
1407
+ this.errors = t;
1408
+ const e = { valid: t.length === 0, errors: t };
1409
+ return this.dispatchEvent(
1410
+ new CustomEvent("baht-validity", { detail: e, bubbles: !0, composed: !0 })
1411
+ ), e;
1412
+ }
1413
+ reset() {
1414
+ this.edits = {}, this.value = {}, this.errors = [], this.requestUpdate();
1415
+ }
1416
+ // ---- internal ----
1417
+ onFieldInput(t, e) {
1418
+ var s;
1419
+ e.stopPropagation();
1420
+ let { value: r } = e.detail;
1421
+ const a = t.formatter ? (s = this.registry.formatters) == null ? void 0 : s[t.formatter] : void 0;
1422
+ t.formatter && !a && console.warn(`[bahtui] unknown formatter "${t.formatter}" — skipped`), a && (r = a(r)), this.edits = { ...this.edits, [t.key]: r }, (this.options.validateOn ?? "change") === "change" && this.errors.length > 0 && this.validate(), this.dispatchEvent(
1423
+ new CustomEvent("baht-change", {
1424
+ detail: { formName: this.form.formName, key: t.key, value: r, data: this.getData() },
1425
+ bubbles: !0,
1426
+ composed: !0
1427
+ })
1428
+ );
1429
+ }
1430
+ renderField(t) {
1431
+ var o;
1432
+ const e = Fe[t.type];
1433
+ if (!e)
1434
+ return console.warn(`[bahtui] unknown field type "${t.type}" — skipped`), h;
1435
+ const r = this.stateFor(t), a = ke[t.width ?? "full"] ?? "baht-field--w-full", s = ((o = this.errors.find((c) => c.key === t.key)) == null ? void 0 : o.message) ?? null, i = document.createElement(e);
1436
+ return i.field = t, i.value = this.valueFor(t), i.disabled = !r.enabled, i.readonly = r.readonly, i.required = r.required, i.error = s, i.addEventListener("baht-input", (c) => this.onFieldInput(t, c)), l`<div
1437
+ class="baht-field ${a} ${r.visible ? "" : "baht-field--hidden"}"
1438
+ data-key=${t.key}
1439
+ data-type=${t.type}
1440
+ >
1441
+ ${i}
1442
+ </div>`;
1443
+ }
1444
+ render() {
1445
+ return l`<div class="baht-form">${this.sortedFields.map((t) => this.renderField(t))}</div>`;
1446
+ }
1447
+ };
1448
+ C([
1449
+ n({ attribute: !1 })
1450
+ ], x.prototype, "form", 2);
1451
+ C([
1452
+ n({ attribute: !1 })
1453
+ ], x.prototype, "value", 2);
1454
+ C([
1455
+ n({ attribute: !1 })
1456
+ ], x.prototype, "registry", 2);
1457
+ C([
1458
+ n({ attribute: !1 })
1459
+ ], x.prototype, "options", 2);
1460
+ C([
1461
+ n({ attribute: !1 })
1462
+ ], x.prototype, "fieldStates", 2);
1463
+ C([
1464
+ O()
1465
+ ], x.prototype, "edits", 2);
1466
+ C([
1467
+ O()
1468
+ ], x.prototype, "errors", 2);
1469
+ x = C([
1470
+ p("baht-form")
1471
+ ], x);
1472
+ var Ae = Object.defineProperty, Le = Object.getOwnPropertyDescriptor, $ = (t, e, r, a) => {
1473
+ for (var s = a > 1 ? void 0 : a ? Le(e, r) : e, i = t.length - 1, o; i >= 0; i--)
1474
+ (o = t[i]) && (s = (a ? o(e, r, s) : o(s)) || s);
1475
+ return a && s && Ae(e, r, s), s;
1476
+ };
1477
+ let m = class extends d {
1478
+ constructor() {
1479
+ super(...arguments), this.value = {}, this.registry = {}, this.validateGate = !0, this.nextLabel = "Next", this.submitLabel = "Submit", this.backLabel = "Back", this.showBack = !0, this.data = {}, this.derived = null, this.current = null, this.approvalError = null, this.history = [];
1480
+ }
1481
+ get currentFormName() {
1482
+ return this.current;
1483
+ }
1484
+ willUpdate(t) {
1485
+ var e;
1486
+ (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.formName) ?? null, this.approvalError = null);
1487
+ }
1488
+ reevaluate() {
1489
+ this.derived = Ot(this.workflow, this.data), this.data = this.derived.data;
1490
+ }
1491
+ /** Forms in ascending order whose derived visibility is true. */
1492
+ get visibleForms() {
1493
+ var e;
1494
+ const t = [...((e = this.workflow) == null ? void 0 : e.forms) ?? []].sort((r, a) => r.order - a.order);
1495
+ return this.derived ? t.filter((r) => {
1496
+ var a;
1497
+ return ((a = this.derived.forms[r.formName]) == null ? void 0 : a.visible) !== !1;
1498
+ }) : t;
1499
+ }
1500
+ get currentForm() {
1501
+ return this.visibleForms.find((t) => t.formName === this.current) ?? null;
1502
+ }
1503
+ get isLast() {
1504
+ var e;
1505
+ const t = this.visibleForms;
1506
+ return t.length > 0 && ((e = t[t.length - 1]) == null ? void 0 : e.formName) === this.current;
1507
+ }
1508
+ fieldStatesFor(t) {
1509
+ const e = {};
1510
+ if (!this.derived) return e;
1511
+ const r = `${t}.`;
1512
+ for (const [a, s] of Object.entries(this.derived.fields))
1513
+ a.startsWith(r) && (e[a.slice(r.length)] = s);
1514
+ return e;
1515
+ }
1516
+ get formEl() {
1517
+ return this.querySelector("baht-form");
1518
+ }
1519
+ // ---- public API (spec 03 §2) ----
1520
+ getData() {
1521
+ var t;
1522
+ return ((t = this.derived) == null ? void 0 : t.data) ?? this.data;
1523
+ }
1524
+ next() {
1525
+ const t = this.currentForm;
1526
+ if (!t) return;
1527
+ if (t.kind === "approval") {
1528
+ this.decide("approved");
1529
+ return;
1530
+ }
1531
+ let e = { valid: !0, errors: [] };
1532
+ this.formEl && (e = this.formEl.validate()), !(this.validateGate && !e.valid) && (this.reevaluate(), this.advance(e));
1533
+ }
1534
+ /** Advance past the current form: submit+complete on the last one, else step forward. */
1535
+ advance(t = {}) {
1536
+ const e = { ...t, data: this.getData() };
1537
+ if (this.isLast) {
1538
+ this.emit("baht-submit", e), this.emit("baht-complete", { data: this.getData(), status: "completed" });
1539
+ return;
1540
+ }
1541
+ const r = this.visibleForms, a = r.findIndex((i) => i.formName === this.current), s = r[a + 1];
1542
+ s && (this.history.push(this.current), this.current = s.formName, this.emit("baht-next", { formName: s.formName, order: s.order, ...e }), this.emit("baht-step-change", {
1543
+ formName: s.formName,
1544
+ order: s.order,
1545
+ direction: "forward"
1546
+ }));
1547
+ }
1548
+ /** Approve the current approval step (same as pressing its Approve button). */
1549
+ approve() {
1550
+ this.decide("approved");
1551
+ }
1552
+ /** Reject the current approval step (same as pressing its Reject button). */
1553
+ reject() {
1554
+ this.decide("rejected");
1555
+ }
1556
+ decide(t) {
1557
+ var v;
1558
+ const e = this.currentForm;
1559
+ if (!e || e.kind !== "approval") return;
1560
+ const r = e.approval ?? {}, a = String(((v = this.data[e.formName]) == null ? void 0 : v.comment) ?? ""), s = r.comment ?? "optional";
1561
+ if ((s === "required" || s === "requireOnReject" && t === "rejected") && a.trim() === "") {
1562
+ this.approvalError = "A comment is required.";
1563
+ return;
1564
+ }
1565
+ this.approvalError = null, this.data = {
1566
+ ...this.data,
1567
+ [e.formName]: { ...this.data[e.formName], decision: t, comment: a }
1568
+ }, this.reevaluate();
1569
+ const o = { formName: e.formName, decision: t, comment: a, data: this.getData() };
1570
+ if (t === "approved") {
1571
+ this.emit("baht-approve", o), this.advance({ decision: t, comment: a });
1572
+ return;
1573
+ }
1574
+ this.emit("baht-reject", o);
1575
+ const c = r.onReject ?? { action: "end" };
1576
+ c.action === "goto" && this.visibleForms.some((w) => w.formName === c.form) ? this.gotoForm(c.form) : this.emit("baht-complete", { data: this.getData(), status: "rejected" });
1577
+ }
1578
+ /** Jump back to a visible form, truncating the history to that point. */
1579
+ gotoForm(t) {
1580
+ const e = this.history.indexOf(t);
1581
+ this.history = e >= 0 ? this.history.slice(0, e) : [], this.current = t;
1582
+ const r = this.workflow.forms.find((a) => a.formName === t);
1583
+ this.emit("baht-step-change", { formName: t, order: (r == null ? void 0 : r.order) ?? 0, direction: "back" });
1584
+ }
1585
+ back() {
1586
+ const t = this.history.pop();
1587
+ if (!t) return;
1588
+ this.current = t, this.approvalError = null;
1589
+ const e = this.workflow.forms.find((r) => r.formName === t);
1590
+ this.emit("baht-step-change", { formName: t, order: (e == null ? void 0 : e.order) ?? 0, direction: "back" });
1591
+ }
1592
+ gotoStart() {
1593
+ var t;
1594
+ this.history = [], this.current = ((t = this.visibleForms[0]) == null ? void 0 : t.formName) ?? null, this.approvalError = null;
1595
+ }
1596
+ // ---- internal ----
1597
+ onFormChange(t) {
1598
+ var s;
1599
+ t.stopPropagation();
1600
+ const { formName: e, key: r, value: a } = t.detail;
1601
+ this.data = { ...this.data, [e]: { ...this.data[e], [r]: a } }, this.reevaluate(), this.current && !this.visibleForms.some((i) => i.formName === this.current) && (this.current = ((s = this.visibleForms[0]) == null ? void 0 : s.formName) ?? null), this.emit("baht-data-change", { data: this.getData() });
1602
+ }
1603
+ onCommentInput(t, e) {
1604
+ 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() });
1605
+ }
1606
+ emit(t, e) {
1607
+ this.dispatchEvent(new CustomEvent(t, { detail: e, bubbles: !0, composed: !0 }));
1608
+ }
1609
+ // ---- approval summary (spec 03 §4) ----
1610
+ /** Human-readable value for the summary: option labels, Yes/No, em-dash for empty. */
1611
+ displayValue(t, e) {
1612
+ const r = (a) => {
1613
+ var s, i;
1614
+ return ((i = (s = t.options) == null ? void 0 : s.find((o) => o.key === a)) == null ? void 0 : i.label) ?? String(a);
1615
+ };
1616
+ return e == null || e === "" ? "—" : typeof e == "boolean" ? e ? "Yes" : "No" : Array.isArray(e) ? e.length ? e.map(r).join(", ") : "—" : t.options ? r(e) : String(e);
1617
+ }
1618
+ /** Forms the approval step summarizes: configured list, else every earlier plain form. */
1619
+ summaryForms(t) {
1620
+ var a;
1621
+ const e = (a = t.approval) == null ? void 0 : a.summaryForms, r = this.visibleForms.filter(
1622
+ (s) => s.formName !== t.formName && s.kind !== "approval"
1623
+ );
1624
+ return e ? r.filter((s) => e.includes(s.formName)) : r.filter((s) => s.order < t.order);
1625
+ }
1626
+ renderApproval(t) {
1627
+ var a, s;
1628
+ const e = ((a = t.approval) == null ? void 0 : a.comment) ?? "optional", r = this.summaryForms(t);
1629
+ return l`<div class="baht-approval">
1630
+ <div class="baht-approval-summary">
1631
+ ${r.length === 0 ? l`<p class="baht-approval-empty">Nothing to review.</p>` : r.map((i) => {
1632
+ const o = this.fieldStatesFor(i.formName), c = [...i.field_data].sort((v, w) => v.order - w.order).filter((v) => {
1633
+ var w;
1634
+ return v.type !== "label" && ((w = o[v.key]) == null ? void 0 : w.visible) !== !1;
1635
+ });
1636
+ return l`<section class="baht-approval-group">
1637
+ <h4 class="baht-approval-group-title">${i.formName}</h4>
1638
+ <dl class="baht-approval-rows">
1639
+ ${c.map(
1640
+ (v) => {
1641
+ var w;
1642
+ return l`<div class="baht-approval-row">
1643
+ <dt>${v.label ?? v.key}</dt>
1644
+ <dd>${this.displayValue(v, (w = this.data[i.formName]) == null ? void 0 : w[v.key])}</dd>
1645
+ </div>`;
1646
+ }
1647
+ )}
1648
+ </dl>
1649
+ </section>`;
1650
+ })}
1651
+ </div>
1652
+ ${e !== "hidden" ? l`<label class="baht-approval-comment">
1653
+ <span class="baht-approval-comment-label">
1654
+ Comment${e === "required" ? " (required)" : ""}
1655
+ </span>
1656
+ <textarea
1657
+ rows="3"
1658
+ aria-required=${e === "required" ? "true" : h}
1659
+ aria-invalid=${this.approvalError ? "true" : h}
1660
+ .value=${String(((s = this.data[t.formName]) == null ? void 0 : s.comment) ?? "")}
1661
+ @input=${(i) => this.onCommentInput(t.formName, i.target.value)}
1662
+ ></textarea>
1663
+ </label>` : h}
1664
+ ${this.approvalError ? l`<p class="baht-error" role="alert">${this.approvalError}</p>` : h}
1665
+ </div>`;
1666
+ }
1667
+ render() {
1668
+ var s, i;
1669
+ const t = this.currentForm;
1670
+ if (!t) return l`<div class="baht-workflow"></div>`;
1671
+ const e = t.kind === "approval", r = this.visibleForms, a = r.findIndex((o) => o.formName === t.formName);
1672
+ return l`<div class="baht-workflow" data-step=${t.formName}>
1673
+ <div class="baht-visually-hidden" role="status">
1674
+ Step ${a + 1} of ${r.length}
1675
+ </div>
1676
+ ${e ? this.renderApproval(t) : l`<baht-form
1677
+ .form=${t}
1678
+ .value=${this.data[t.formName] ?? {}}
1679
+ .registry=${this.registry}
1680
+ .fieldStates=${this.fieldStatesFor(t.formName)}
1681
+ @baht-change=${(o) => this.onFormChange(o)}
1682
+ ></baht-form>`}
1683
+ <div class="baht-workflow-nav">
1684
+ ${this.showBack && this.history.length > 0 ? l`<button type="button" class="baht-button baht-button--back" @click=${() => this.back()}>
1685
+ ${this.backLabel}
1686
+ </button>` : h}
1687
+ ${e ? l`<button
1688
+ type="button"
1689
+ class="baht-button baht-button--reject"
1690
+ @click=${() => this.decide("rejected")}
1691
+ >
1692
+ ${((s = t.approval) == null ? void 0 : s.rejectLabel) ?? "Reject"}
1693
+ </button>
1694
+ <button
1695
+ type="button"
1696
+ class="baht-button baht-button--next baht-button--approve"
1697
+ @click=${() => this.decide("approved")}
1698
+ >
1699
+ ${((i = t.approval) == null ? void 0 : i.approveLabel) ?? "Approve"}
1700
+ </button>` : l`<button type="button" class="baht-button baht-button--next" @click=${() => this.next()}>
1701
+ ${this.isLast ? this.submitLabel : this.nextLabel}
1702
+ </button>`}
1703
+ </div>
1704
+ </div>`;
1705
+ }
1706
+ };
1707
+ $([
1708
+ n({ attribute: !1 })
1709
+ ], m.prototype, "workflow", 2);
1710
+ $([
1711
+ n({ attribute: !1 })
1712
+ ], m.prototype, "value", 2);
1713
+ $([
1714
+ n({ attribute: !1 })
1715
+ ], m.prototype, "registry", 2);
1716
+ $([
1717
+ n({ type: Boolean, attribute: "validate-gate" })
1718
+ ], m.prototype, "validateGate", 2);
1719
+ $([
1720
+ n({ attribute: "next-label" })
1721
+ ], m.prototype, "nextLabel", 2);
1722
+ $([
1723
+ n({ attribute: "submit-label" })
1724
+ ], m.prototype, "submitLabel", 2);
1725
+ $([
1726
+ n({ attribute: "back-label" })
1727
+ ], m.prototype, "backLabel", 2);
1728
+ $([
1729
+ n({ type: Boolean, attribute: "show-back" })
1730
+ ], m.prototype, "showBack", 2);
1731
+ $([
1732
+ O()
1733
+ ], m.prototype, "data", 2);
1734
+ $([
1735
+ O()
1736
+ ], m.prototype, "derived", 2);
1737
+ $([
1738
+ O()
1739
+ ], m.prototype, "current", 2);
1740
+ $([
1741
+ O()
1742
+ ], m.prototype, "approvalError", 2);
1743
+ m = $([
1744
+ p("baht-workflow")
1745
+ ], m);
1746
+ export {
1747
+ F as BahtAccordion,
1748
+ j as BahtAlert,
1749
+ K as BahtBadge,
1750
+ X as BahtBreadcrumbs,
1751
+ Qe as BahtButton,
1752
+ k as BahtCard,
1753
+ vt as BahtCheckbox,
1754
+ J as BahtCode,
1755
+ $t as BahtDatepicker,
1756
+ d as BahtElement,
1757
+ g as BahtFieldBase,
1758
+ U as BahtFieldset,
1759
+ yt as BahtFile,
1760
+ I as BahtFilter,
1761
+ x as BahtForm,
1762
+ pt as BahtInput,
1763
+ A as BahtLink,
1764
+ _ as BahtList,
1765
+ Xe as BahtModal,
1766
+ bt as BahtMultiselect,
1767
+ ct as BahtNumber,
1768
+ E as BahtOtp,
1769
+ q as BahtPagination,
1770
+ S as BahtProgress,
1771
+ mt as BahtRadio,
1772
+ y as BahtRange,
1773
+ N as BahtRating,
1774
+ ut as BahtSelect,
1775
+ V as BahtSkeleton,
1776
+ Q as BahtSpinner,
1777
+ u as BahtTable,
1778
+ it as BahtText,
1779
+ dt as BahtTextarea,
1780
+ at as BahtTimeline,
1781
+ Ze as BahtToast,
1782
+ ft as BahtToggle,
1783
+ P as BahtTooltip,
1784
+ m as BahtWorkflow,
1785
+ Fe as TAG_FOR_TYPE,
1786
+ Z as adoptLightChildren,
1787
+ He as approvalFields,
1788
+ _t as defaultValue,
1789
+ Ge as evalCondition,
1790
+ We as evalValueExpr,
1791
+ Ot as evaluate,
1792
+ ts as isIconName,
1793
+ Ye as readRef,
1794
+ es as renderIcon,
1795
+ xt as validateField
1796
+ };