@formatica/react 0.1.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,1379 @@
1
+ import { extractFields as ne, evaluateCondition as se, getRule as ae, isFieldNode as O } from "@formatica/core";
2
+ export * from "@formatica/core";
3
+ import { useRef as L, useState as S, useCallback as D, createContext as oe, useContext as le, useEffect as B } from "react";
4
+ import { jsxs as g, jsx as t } from "react/jsx-runtime";
5
+ function ie(e) {
6
+ switch (e.type) {
7
+ case "tags":
8
+ case "checkbox-group":
9
+ return [];
10
+ case "checkbox":
11
+ case "switch":
12
+ return !1;
13
+ case "number":
14
+ case "slider":
15
+ case "file":
16
+ return null;
17
+ default:
18
+ return "";
19
+ }
20
+ }
21
+ function ce(e) {
22
+ const n = {};
23
+ for (const s of e)
24
+ n[s.name] = s.defaultValue ?? ie(s);
25
+ return n;
26
+ }
27
+ function ue(e) {
28
+ return e ? typeof e == "string" ? e.split("|").map(Z) : Array.isArray(e) ? e.map(Z) : Object.entries(e).filter(([, n]) => n !== !1 && n !== void 0).map(([n, s]) => ({
29
+ name: n,
30
+ params: typeof s == "object" && s !== null ? s : { [n]: s }
31
+ })) : [];
32
+ }
33
+ function Z(e) {
34
+ const [n = "", ...s] = e.split(":"), r = s.join(":"), a = {};
35
+ if (r) {
36
+ const o = r.split(",");
37
+ if (n === "between" && o.length === 2)
38
+ a.min = Number(o[0]), a.max = Number(o[1]);
39
+ else if (n === "pattern")
40
+ a.pattern = r;
41
+ else if (a[n] = o.length === 1 ? o[0] : o, o.length === 1) {
42
+ const i = Number(o[0]);
43
+ Number.isNaN(i) || (a[n] = i, n === "minLength" && (a.min = i), n === "maxLength" && (a.max = i));
44
+ }
45
+ }
46
+ return { name: n, params: a };
47
+ }
48
+ function de(e, n) {
49
+ const s = ne(e.fields), r = L(ce(s)), a = L(s), [o, i] = S(() => ({
50
+ ...r.current
51
+ })), [u, l] = S({}), [m, d] = S({}), [h, f] = S({}), [C, v] = S(!1), [p, b] = S(0), k = L(o);
52
+ k.current = o;
53
+ const x = L(u);
54
+ x.current = u;
55
+ const F = Object.values(u).every((y) => y.length === 0), R = Object.values(h).some(Boolean), j = D((y, $) => {
56
+ i((N) => ({ ...N, [y]: $ })), f((N) => ({ ...N, [y]: !0 }));
57
+ }, []), H = D((y) => k.current[y], []), T = D(
58
+ async (y, $) => {
59
+ const N = a.current.find((E) => E.name === y);
60
+ if (!N) return [];
61
+ if (N.condition && !se(N.condition, $))
62
+ return [];
63
+ const I = ue(N.rules);
64
+ N.required && !I.some((E) => E.name === "required") && I.unshift({ name: "required", params: {} });
65
+ const z = [], te = {
66
+ values: $,
67
+ getFieldValue: (E) => $[E]
68
+ };
69
+ for (const E of I) {
70
+ const G = ae(E.name);
71
+ if (!G) continue;
72
+ const W = await G($[y], E.params, te);
73
+ typeof W == "string" && z.push(W);
74
+ }
75
+ return z;
76
+ },
77
+ []
78
+ ), A = D(
79
+ async (y) => {
80
+ const $ = await T(y, k.current);
81
+ return l((N) => ({ ...N, [y]: $ })), d((N) => ({ ...N, [y]: !0 })), $.length === 0;
82
+ },
83
+ [T]
84
+ ), V = D(async () => {
85
+ const y = k.current, $ = {};
86
+ let N = !0;
87
+ for (const I of a.current) {
88
+ const z = await T(I.name, y);
89
+ $[I.name] = z, z.length > 0 && (N = !1);
90
+ }
91
+ return l($), N;
92
+ }, [T]), P = D(
93
+ async (y) => {
94
+ v(!0), b((N) => N + 1);
95
+ const $ = {};
96
+ for (const N of a.current)
97
+ $[N.name] = !0;
98
+ d($);
99
+ try {
100
+ if (!await V()) return;
101
+ await y({ ...k.current });
102
+ } finally {
103
+ v(!1);
104
+ }
105
+ },
106
+ [V]
107
+ ), _ = D(() => {
108
+ i({ ...r.current }), l({}), d({}), f({});
109
+ }, []), U = D(() => {
110
+ const y = {};
111
+ for (const $ of a.current)
112
+ y[$.name] = null;
113
+ i(y), l({});
114
+ }, []), q = D((y, $) => {
115
+ const N = Array.isArray($) ? $ : [$];
116
+ l((I) => ({ ...I, [y]: N }));
117
+ }, []), c = D((y) => {
118
+ l(($) => {
119
+ const N = { ...$ };
120
+ return delete N[y], N;
121
+ });
122
+ }, []), w = D(() => {
123
+ l({});
124
+ }, []);
125
+ return {
126
+ values: o,
127
+ errors: u,
128
+ touched: m,
129
+ dirty: h,
130
+ isValid: F,
131
+ isDirty: R,
132
+ isSubmitting: C,
133
+ submitCount: p,
134
+ setFieldValue: j,
135
+ validate: V,
136
+ validateField: A,
137
+ submit: P,
138
+ reset: _,
139
+ clear: U,
140
+ setError: q,
141
+ clearError: c,
142
+ clearErrors: w,
143
+ getFieldValue: H
144
+ };
145
+ }
146
+ const ee = oe(null);
147
+ function Te() {
148
+ const e = le(ee);
149
+ if (!e) throw new Error("useFormContext must be used within a FormProvider");
150
+ return e;
151
+ }
152
+ function fe({
153
+ label: e,
154
+ required: n,
155
+ errors: s,
156
+ touched: r = !0,
157
+ helpText: a,
158
+ tooltip: o,
159
+ disabled: i,
160
+ readOnly: u,
161
+ fieldName: l,
162
+ children: m,
163
+ className: d,
164
+ style: h
165
+ }) {
166
+ const [f, C] = S(!1), v = r && s !== void 0 && s.length > 0, p = l ? `fc-field-${l}` : void 0, b = l ? `fc-error-${l}` : void 0;
167
+ return /* @__PURE__ */ g(
168
+ "div",
169
+ {
170
+ className: `relative mb-4 ${i ? "opacity-50 cursor-not-allowed" : ""} ${u ? "fc-readonly" : ""} ${d ?? ""}`,
171
+ style: h,
172
+ children: [
173
+ e && /* @__PURE__ */ g("div", { className: "mb-1.5 flex items-center gap-1", children: [
174
+ /* @__PURE__ */ g("label", { htmlFor: p, className: "block text-sm font-medium text-gray-700", children: [
175
+ e,
176
+ n && /* @__PURE__ */ t("span", { className: "text-red-500 ml-0.5", "aria-hidden": "true", children: "*" })
177
+ ] }),
178
+ o && /* @__PURE__ */ g(
179
+ "span",
180
+ {
181
+ className: "relative inline-flex",
182
+ onMouseEnter: () => C(!0),
183
+ onMouseLeave: () => C(!1),
184
+ onFocus: () => C(!0),
185
+ onBlur: () => C(!1),
186
+ children: [
187
+ /* @__PURE__ */ t(
188
+ "button",
189
+ {
190
+ type: "button",
191
+ className: "inline-flex h-4 w-4 items-center justify-center rounded-full bg-gray-200 text-gray-500 text-xs hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500/40",
192
+ "aria-label": `Info: ${o}`,
193
+ tabIndex: 0,
194
+ children: "i"
195
+ }
196
+ ),
197
+ f && /* @__PURE__ */ g(
198
+ "div",
199
+ {
200
+ role: "tooltip",
201
+ className: "absolute bottom-full left-1/2 z-10 mb-2 -translate-x-1/2 rounded-md bg-gray-900 px-3 py-1.5 text-xs text-white shadow-lg whitespace-nowrap",
202
+ children: [
203
+ o,
204
+ /* @__PURE__ */ t("div", { className: "absolute left-1/2 top-full -translate-x-1/2 border-4 border-transparent border-t-gray-900" })
205
+ ]
206
+ }
207
+ )
208
+ ]
209
+ }
210
+ )
211
+ ] }),
212
+ /* @__PURE__ */ t("div", { id: p, children: m }),
213
+ v && /* @__PURE__ */ t("div", { children: s.map((k, x) => /* @__PURE__ */ t(
214
+ "p",
215
+ {
216
+ id: x === 0 ? b : void 0,
217
+ className: "mt-1 text-xs text-red-500",
218
+ role: "alert",
219
+ children: k
220
+ },
221
+ `${k}-${x}`
222
+ )) }),
223
+ a && !v && /* @__PURE__ */ t("p", { className: "mt-1 text-xs text-gray-400", children: a })
224
+ ]
225
+ }
226
+ );
227
+ }
228
+ const me = "w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-colors duration-200 fc-text-input";
229
+ function J({
230
+ value: e,
231
+ onChange: n,
232
+ onBlur: s,
233
+ disabled: r,
234
+ placeholder: a,
235
+ inputType: o = "text",
236
+ readOnly: i,
237
+ prefix: u,
238
+ suffix: l,
239
+ maxLength: m,
240
+ className: d
241
+ }) {
242
+ const v = `${me} ${r ? "opacity-50 cursor-not-allowed bg-gray-100" : ""} ${u ? "rounded-l-none" : ""} ${l ? "rounded-r-none" : ""} ${d ?? ""}`.trim(), p = /* @__PURE__ */ t(
243
+ "input",
244
+ {
245
+ type: o,
246
+ className: v,
247
+ style: { borderColor: void 0 },
248
+ value: e ?? "",
249
+ onChange: (b) => n(b.target.value),
250
+ onFocus: (b) => {
251
+ b.target.style.borderColor = "var(--fc-color-primary, #3b82f6)";
252
+ },
253
+ onBlur: (b) => {
254
+ b.target.style.borderColor = "", s == null || s();
255
+ },
256
+ disabled: r,
257
+ placeholder: a,
258
+ readOnly: i,
259
+ maxLength: m,
260
+ "aria-disabled": r || void 0,
261
+ "aria-readonly": i || void 0
262
+ }
263
+ );
264
+ return u || l ? /* @__PURE__ */ g("div", { className: "flex items-stretch", children: [
265
+ u && /* @__PURE__ */ t("span", { className: "inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500", children: u }),
266
+ p,
267
+ l && /* @__PURE__ */ t("span", { className: "inline-flex items-center rounded-r-md border border-l-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500", children: l })
268
+ ] }) : p;
269
+ }
270
+ const pe = "w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm placeholder:text-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-colors duration-200 fc-number-input";
271
+ function be({
272
+ value: e,
273
+ onChange: n,
274
+ onBlur: s,
275
+ disabled: r,
276
+ placeholder: a,
277
+ min: o,
278
+ max: i,
279
+ step: u = 1,
280
+ precision: l,
281
+ readOnly: m,
282
+ prefix: d,
283
+ suffix: h,
284
+ className: f
285
+ }) {
286
+ const b = `${pe} ${r ? "opacity-50 cursor-not-allowed bg-gray-100" : ""} ${d ? "rounded-l-none" : ""} ${h ? "rounded-r-none" : ""} ${f ?? ""}`.trim();
287
+ function k(F) {
288
+ const R = F.target.value;
289
+ if (R === "") {
290
+ n(null);
291
+ return;
292
+ }
293
+ let j = Number.parseFloat(R);
294
+ Number.isNaN(j) || (l !== void 0 && (j = Number.parseFloat(j.toFixed(l))), n(j));
295
+ }
296
+ const x = /* @__PURE__ */ t(
297
+ "input",
298
+ {
299
+ type: "number",
300
+ className: b,
301
+ value: e ?? "",
302
+ onChange: k,
303
+ onFocus: (F) => {
304
+ F.target.style.borderColor = "var(--fc-color-primary, #3b82f6)";
305
+ },
306
+ onBlur: (F) => {
307
+ F.target.style.borderColor = "", s == null || s();
308
+ },
309
+ disabled: r,
310
+ placeholder: a,
311
+ min: o,
312
+ max: i,
313
+ step: u,
314
+ readOnly: m,
315
+ "aria-disabled": r || void 0,
316
+ "aria-readonly": m || void 0
317
+ }
318
+ );
319
+ return d || h ? /* @__PURE__ */ g("div", { className: "flex items-stretch", children: [
320
+ d && /* @__PURE__ */ t("span", { className: "inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500", children: d }),
321
+ x,
322
+ h && /* @__PURE__ */ t("span", { className: "inline-flex items-center rounded-r-md border border-l-0 border-gray-300 bg-gray-50 px-3 text-sm text-gray-500", children: h })
323
+ ] }) : x;
324
+ }
325
+ const ge = "w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm placeholder:text-gray-400 resize-y focus:outline-none focus:ring-2 focus:ring-blue-500/20 transition-colors duration-200 fc-textarea-input";
326
+ function ye({
327
+ value: e,
328
+ onChange: n,
329
+ onBlur: s,
330
+ disabled: r,
331
+ placeholder: a,
332
+ rows: o = 3,
333
+ readOnly: i,
334
+ autoResize: u,
335
+ maxLength: l,
336
+ className: m
337
+ }) {
338
+ const d = L(null), h = D(() => {
339
+ if (!u || !d.current) return;
340
+ const p = d.current;
341
+ p.style.height = "auto", p.style.height = `${p.scrollHeight}px`;
342
+ }, [u]);
343
+ B(() => {
344
+ h();
345
+ }, [e, h]);
346
+ const v = `${ge} ${r ? "opacity-50 cursor-not-allowed bg-gray-100" : ""} ${u ? "resize-none overflow-hidden" : ""} ${m ?? ""}`.trim();
347
+ return /* @__PURE__ */ t(
348
+ "textarea",
349
+ {
350
+ ref: d,
351
+ className: v,
352
+ value: e ?? "",
353
+ onChange: (p) => {
354
+ n(p.target.value);
355
+ },
356
+ onFocus: (p) => {
357
+ p.target.style.borderColor = "var(--fc-color-primary, #3b82f6)";
358
+ },
359
+ onBlur: (p) => {
360
+ p.target.style.borderColor = "", s == null || s();
361
+ },
362
+ disabled: r,
363
+ placeholder: a,
364
+ rows: o,
365
+ readOnly: i,
366
+ maxLength: l,
367
+ "aria-disabled": r || void 0,
368
+ "aria-readonly": i || void 0
369
+ }
370
+ );
371
+ }
372
+ function he({
373
+ value: e,
374
+ onChange: n,
375
+ onBlur: s,
376
+ disabled: r,
377
+ placeholder: a = "Select...",
378
+ options: o,
379
+ multiple: i = !1,
380
+ searchable: u = !1,
381
+ clearable: l = !1,
382
+ className: m
383
+ }) {
384
+ const [d, h] = S(!1), [f, C] = S(""), [v, p] = S(-1), b = L(null), k = L(null), x = e == null ? [] : Array.isArray(e) ? e : [e], F = (() => {
385
+ if (x.length === 0 || i) return "";
386
+ const c = o.find((w) => w.value === x[0]);
387
+ return (c == null ? void 0 : c.label) ?? String(x[0]);
388
+ })(), R = f ? o.filter((c) => c.label.toLowerCase().includes(f.toLowerCase())) : o;
389
+ function j(c) {
390
+ return x.includes(c);
391
+ }
392
+ function H(c) {
393
+ const w = o.find((y) => y.value === c);
394
+ return (w == null ? void 0 : w.label) ?? String(c);
395
+ }
396
+ const T = D(() => {
397
+ h(!0), p(-1), C(""), setTimeout(() => {
398
+ var c;
399
+ return (c = k.current) == null ? void 0 : c.focus();
400
+ }, 0);
401
+ }, []), A = D(() => {
402
+ h(!1), C(""), s == null || s();
403
+ }, [s]);
404
+ function V() {
405
+ r || (d ? A() : T());
406
+ }
407
+ function P(c) {
408
+ if (!c.disabled)
409
+ if (i) {
410
+ const w = [...x], y = w.indexOf(c.value);
411
+ y >= 0 ? w.splice(y, 1) : w.push(c.value), n(w);
412
+ } else
413
+ n(c.value), A();
414
+ }
415
+ function _(c) {
416
+ if (r) return;
417
+ const w = x.filter((y) => y !== c);
418
+ n(w.length ? w : i ? [] : null);
419
+ }
420
+ function U(c) {
421
+ c.stopPropagation(), n(i ? [] : null);
422
+ }
423
+ function q(c) {
424
+ if (!d) {
425
+ (c.key === "Enter" || c.key === " " || c.key === "ArrowDown") && (c.preventDefault(), T());
426
+ return;
427
+ }
428
+ switch (c.key) {
429
+ case "ArrowDown":
430
+ c.preventDefault(), p((w) => Math.min(w + 1, R.length - 1));
431
+ break;
432
+ case "ArrowUp":
433
+ c.preventDefault(), p((w) => Math.max(w - 1, 0));
434
+ break;
435
+ case "Enter":
436
+ c.preventDefault(), v >= 0 && R[v] && P(R[v]);
437
+ break;
438
+ case "Escape":
439
+ c.preventDefault(), A();
440
+ break;
441
+ }
442
+ }
443
+ return B(() => {
444
+ function c(w) {
445
+ b.current && !b.current.contains(w.target) && A();
446
+ }
447
+ return document.addEventListener("mousedown", c), () => document.removeEventListener("mousedown", c);
448
+ }, [A]), /* @__PURE__ */ g(
449
+ "div",
450
+ {
451
+ ref: b,
452
+ className: `relative w-full ${r ? "opacity-50 cursor-not-allowed" : ""} ${m ?? ""}`,
453
+ children: [
454
+ /* @__PURE__ */ g(
455
+ "div",
456
+ {
457
+ role: "combobox",
458
+ "aria-expanded": d,
459
+ "aria-haspopup": "listbox",
460
+ tabIndex: 0,
461
+ className: `flex min-h-[38px] w-full cursor-pointer items-center rounded-md border border-gray-300 bg-white px-3 py-1.5 text-sm transition-colors duration-200 ${d ? "ring-2 ring-blue-500/20" : ""} ${r ? "pointer-events-none bg-gray-100" : ""}`,
462
+ style: d ? { borderColor: "var(--fc-color-primary, #3b82f6)" } : {},
463
+ onClick: V,
464
+ onKeyDown: q,
465
+ children: [
466
+ /* @__PURE__ */ g("div", { className: "flex flex-1 flex-wrap items-center gap-1", children: [
467
+ i && x.map((c) => /* @__PURE__ */ g(
468
+ "span",
469
+ {
470
+ className: "inline-flex items-center gap-1 rounded px-2 py-0.5 text-xs",
471
+ style: {
472
+ backgroundColor: "color-mix(in srgb, var(--fc-color-primary, #3b82f6) 15%, white)",
473
+ color: "var(--fc-color-primary, #3b82f6)"
474
+ },
475
+ children: [
476
+ H(c),
477
+ /* @__PURE__ */ t(
478
+ "button",
479
+ {
480
+ type: "button",
481
+ className: "ml-0.5",
482
+ style: { color: "var(--fc-color-primary, #3b82f6)" },
483
+ "aria-label": "Remove",
484
+ onClick: (w) => {
485
+ w.stopPropagation(), _(c);
486
+ },
487
+ children: "×"
488
+ }
489
+ )
490
+ ]
491
+ },
492
+ String(c)
493
+ )),
494
+ !i && F && /* @__PURE__ */ t("span", { className: "truncate", children: F }),
495
+ x.length === 0 && !i && /* @__PURE__ */ t("span", { className: "text-gray-400", children: a }),
496
+ i && x.length === 0 && /* @__PURE__ */ t("span", { className: "text-gray-400", children: a })
497
+ ] }),
498
+ l && x.length > 0 && !r && /* @__PURE__ */ t(
499
+ "button",
500
+ {
501
+ type: "button",
502
+ className: "ml-1 shrink-0 text-gray-400 hover:text-gray-600 transition-colors duration-200",
503
+ "aria-label": "Clear selection",
504
+ onClick: U,
505
+ children: "×"
506
+ }
507
+ ),
508
+ /* @__PURE__ */ t(
509
+ "svg",
510
+ {
511
+ className: `ml-1 h-4 w-4 shrink-0 text-gray-400 transition-transform duration-200 ${d ? "rotate-180" : ""}`,
512
+ viewBox: "0 0 20 20",
513
+ fill: "currentColor",
514
+ "aria-hidden": "true",
515
+ children: /* @__PURE__ */ t(
516
+ "path",
517
+ {
518
+ fillRule: "evenodd",
519
+ d: "M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",
520
+ clipRule: "evenodd"
521
+ }
522
+ )
523
+ }
524
+ )
525
+ ]
526
+ }
527
+ ),
528
+ d && /* @__PURE__ */ g("div", { className: "absolute z-50 mt-1 w-full rounded-md border border-gray-200 bg-white shadow-lg", children: [
529
+ u && /* @__PURE__ */ t("div", { className: "border-b border-gray-200 p-2", children: /* @__PURE__ */ t(
530
+ "input",
531
+ {
532
+ ref: k,
533
+ type: "text",
534
+ className: "w-full rounded border border-gray-300 px-2 py-1 text-sm focus:outline-none fc-select-search",
535
+ placeholder: "Search...",
536
+ value: f,
537
+ onChange: (c) => C(c.target.value),
538
+ onKeyDown: q,
539
+ onFocus: (c) => {
540
+ c.target.style.borderColor = "var(--fc-color-primary, #3b82f6)";
541
+ },
542
+ onBlur: (c) => {
543
+ c.target.style.borderColor = "";
544
+ }
545
+ }
546
+ ) }),
547
+ /* @__PURE__ */ g("ul", { role: "listbox", className: "max-h-60 overflow-auto py-1", children: [
548
+ R.map((c, w) => /* @__PURE__ */ t(
549
+ "li",
550
+ {
551
+ role: "option",
552
+ "aria-selected": j(c.value),
553
+ className: `cursor-pointer px-3 py-2 text-sm transition-colors duration-200 ${j(c.value) ? "" : "text-gray-900"} ${v === w ? "bg-gray-100" : ""} ${c.disabled ? "opacity-50 cursor-not-allowed" : "hover:bg-gray-50"}`,
554
+ style: j(c.value) ? {
555
+ backgroundColor: "color-mix(in srgb, var(--fc-color-primary, #3b82f6) 8%, white)",
556
+ color: "var(--fc-color-primary, #3b82f6)"
557
+ } : {},
558
+ onClick: () => P(c),
559
+ onMouseEnter: () => p(w),
560
+ children: c.label
561
+ },
562
+ String(c.value)
563
+ )),
564
+ R.length === 0 && /* @__PURE__ */ t("li", { className: "px-3 py-2 text-sm text-gray-400", children: "No options found" })
565
+ ] })
566
+ ] })
567
+ ]
568
+ }
569
+ );
570
+ }
571
+ function xe({
572
+ value: e,
573
+ onChange: n,
574
+ onBlur: s,
575
+ disabled: r,
576
+ label: a,
577
+ className: o
578
+ }) {
579
+ function i() {
580
+ r || n(!e);
581
+ }
582
+ function u(l) {
583
+ (l.key === " " || l.key === "Enter") && (l.preventDefault(), i());
584
+ }
585
+ return /* @__PURE__ */ g(
586
+ "label",
587
+ {
588
+ className: `inline-flex items-center gap-2 select-none ${r ? "opacity-50 cursor-not-allowed" : "cursor-pointer"} ${o ?? ""}`,
589
+ children: [
590
+ /* @__PURE__ */ t(
591
+ "input",
592
+ {
593
+ type: "checkbox",
594
+ checked: e ?? !1,
595
+ onChange: () => {
596
+ },
597
+ onBlur: s,
598
+ disabled: r,
599
+ className: "sr-only"
600
+ }
601
+ ),
602
+ /* @__PURE__ */ t(
603
+ "div",
604
+ {
605
+ role: "checkbox",
606
+ "aria-checked": e,
607
+ "aria-disabled": r || void 0,
608
+ tabIndex: 0,
609
+ className: `flex h-5 w-5 shrink-0 items-center justify-center rounded border-2 transition-colors duration-200 ${e ? "text-white" : "border-gray-300 bg-white"}`,
610
+ style: e ? {
611
+ borderColor: "var(--fc-color-primary, #3b82f6)",
612
+ backgroundColor: "var(--fc-color-primary, #3b82f6)"
613
+ } : {},
614
+ onClick: (l) => {
615
+ l.preventDefault(), i();
616
+ },
617
+ onKeyDown: u,
618
+ children: e && /* @__PURE__ */ t(
619
+ "svg",
620
+ {
621
+ className: "h-3 w-3",
622
+ viewBox: "0 0 12 12",
623
+ fill: "none",
624
+ stroke: "currentColor",
625
+ strokeWidth: "2",
626
+ "aria-hidden": "true",
627
+ children: /* @__PURE__ */ t("path", { d: "M2 6l3 3 5-5", strokeLinecap: "round", strokeLinejoin: "round" })
628
+ }
629
+ )
630
+ }
631
+ ),
632
+ a && /* @__PURE__ */ t("span", { className: "text-sm text-gray-700", children: a })
633
+ ]
634
+ }
635
+ );
636
+ }
637
+ function ve({
638
+ name: e,
639
+ value: n,
640
+ onChange: s,
641
+ onBlur: r,
642
+ disabled: a,
643
+ options: o,
644
+ inline: i = !1,
645
+ className: u
646
+ }) {
647
+ function l(f) {
648
+ return n === f;
649
+ }
650
+ function m(f) {
651
+ return a === !0 || !!f.disabled;
652
+ }
653
+ function d(f) {
654
+ m(f) || s(f.value);
655
+ }
656
+ function h(f, C) {
657
+ (f.key === " " || f.key === "Enter") && (f.preventDefault(), d(C));
658
+ }
659
+ return /* @__PURE__ */ t(
660
+ "div",
661
+ {
662
+ role: "radiogroup",
663
+ className: `${i ? "flex flex-wrap gap-4" : "flex flex-col gap-2"} ${u ?? ""}`,
664
+ children: o.map((f) => /* @__PURE__ */ g(
665
+ "label",
666
+ {
667
+ className: `inline-flex items-center gap-2 select-none ${m(f) ? "opacity-50 cursor-not-allowed" : "cursor-pointer"}`,
668
+ children: [
669
+ /* @__PURE__ */ t(
670
+ "input",
671
+ {
672
+ type: "radio",
673
+ checked: l(f.value),
674
+ disabled: m(f),
675
+ className: "sr-only",
676
+ name: e,
677
+ onChange: () => d(f),
678
+ onBlur: r
679
+ }
680
+ ),
681
+ /* @__PURE__ */ t(
682
+ "div",
683
+ {
684
+ role: "radio",
685
+ "aria-checked": l(f.value),
686
+ "aria-disabled": m(f) || void 0,
687
+ tabIndex: 0,
688
+ className: `flex h-5 w-5 shrink-0 items-center justify-center rounded-full border-2 transition-colors duration-200 ${l(f.value) ? "" : "border-gray-300"}`,
689
+ style: l(f.value) ? { borderColor: "var(--fc-color-primary, #3b82f6)" } : {},
690
+ onClick: () => d(f),
691
+ onKeyDown: (C) => h(C, f),
692
+ children: l(f.value) && /* @__PURE__ */ t(
693
+ "div",
694
+ {
695
+ className: "h-2.5 w-2.5 rounded-full",
696
+ style: {
697
+ backgroundColor: "var(--fc-color-primary, #3b82f6)"
698
+ }
699
+ }
700
+ )
701
+ }
702
+ ),
703
+ /* @__PURE__ */ t("span", { className: "text-sm text-gray-700", children: f.label })
704
+ ]
705
+ },
706
+ String(f.value)
707
+ ))
708
+ }
709
+ );
710
+ }
711
+ function we({
712
+ value: e,
713
+ onChange: n,
714
+ onBlur: s,
715
+ disabled: r,
716
+ activeLabel: a,
717
+ inactiveLabel: o,
718
+ className: i
719
+ }) {
720
+ function u() {
721
+ r || n(!e);
722
+ }
723
+ function l(m) {
724
+ (m.key === " " || m.key === "Enter") && (m.preventDefault(), u());
725
+ }
726
+ return /* @__PURE__ */ g(
727
+ "label",
728
+ {
729
+ className: `inline-flex items-center gap-2 select-none ${r ? "opacity-50 cursor-not-allowed" : "cursor-pointer"} ${i ?? ""}`,
730
+ children: [
731
+ o && /* @__PURE__ */ t("span", { className: "text-sm text-gray-600", children: o }),
732
+ /* @__PURE__ */ t(
733
+ "input",
734
+ {
735
+ type: "checkbox",
736
+ checked: e ?? !1,
737
+ onChange: u,
738
+ onBlur: s,
739
+ disabled: r,
740
+ className: "sr-only"
741
+ }
742
+ ),
743
+ /* @__PURE__ */ t(
744
+ "button",
745
+ {
746
+ type: "button",
747
+ role: "switch",
748
+ "aria-checked": e,
749
+ "aria-disabled": r || void 0,
750
+ tabIndex: 0,
751
+ className: `relative inline-flex h-6 w-11 shrink-0 rounded-full border-2 border-transparent transition-colors duration-300 ease-[cubic-bezier(0.34,1.56,0.64,1)] ${e ? "" : "bg-gray-300"} ${r ? "pointer-events-none" : "focus:outline-none focus:ring-2 focus:ring-blue-500/20"}`,
752
+ style: e ? { backgroundColor: "var(--fc-color-primary, #3b82f6)" } : {},
753
+ onClick: u,
754
+ onKeyDown: l,
755
+ children: /* @__PURE__ */ t(
756
+ "span",
757
+ {
758
+ className: `pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow-sm transition-transform duration-300 ease-[cubic-bezier(0.34,1.56,0.64,1)] ${e ? "translate-x-5" : "translate-x-0"}`,
759
+ "aria-hidden": "true"
760
+ }
761
+ )
762
+ }
763
+ ),
764
+ a && /* @__PURE__ */ t("span", { className: "text-sm text-gray-600", children: a })
765
+ ]
766
+ }
767
+ );
768
+ }
769
+ function Ne({
770
+ value: e,
771
+ onChange: n,
772
+ onBlur: s,
773
+ disabled: r,
774
+ min: a = 0,
775
+ max: o = 100,
776
+ step: i = 1,
777
+ showTooltip: u = !0,
778
+ className: l
779
+ }) {
780
+ const [m, d] = S(!1), h = e ?? a, f = o - a, C = f === 0 ? 0 : (h - a) / f * 100;
781
+ return /* @__PURE__ */ g(
782
+ "div",
783
+ {
784
+ className: `relative w-full py-2 ${r ? "opacity-50 cursor-not-allowed" : ""} ${l ?? ""}`,
785
+ children: [
786
+ u && m && /* @__PURE__ */ t(
787
+ "div",
788
+ {
789
+ className: "absolute -top-8 rounded bg-gray-800 px-2 py-1 text-xs text-white shadow-sm transition-opacity duration-200",
790
+ style: { left: `calc(${C}% - 16px)` },
791
+ children: h
792
+ }
793
+ ),
794
+ /* @__PURE__ */ t(
795
+ "input",
796
+ {
797
+ type: "range",
798
+ value: h,
799
+ onChange: (v) => n(Number.parseFloat(v.target.value)),
800
+ onMouseDown: () => d(!0),
801
+ onMouseUp: () => d(!1),
802
+ onTouchStart: () => d(!0),
803
+ onTouchEnd: () => d(!1),
804
+ onFocus: () => d(!0),
805
+ onBlur: (v) => {
806
+ d(!1), s == null || s();
807
+ },
808
+ disabled: r,
809
+ min: a,
810
+ max: o,
811
+ step: i,
812
+ "aria-valuenow": h,
813
+ "aria-valuemin": a,
814
+ "aria-valuemax": o,
815
+ "aria-disabled": r || void 0,
816
+ className: "h-2 w-full cursor-pointer appearance-none rounded-full bg-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500/20 disabled:pointer-events-none",
817
+ style: { accentColor: "var(--fc-color-primary, #3b82f6)" }
818
+ }
819
+ ),
820
+ /* @__PURE__ */ g("div", { className: "mt-1 flex justify-between text-xs text-gray-400", children: [
821
+ /* @__PURE__ */ t("span", { children: a }),
822
+ /* @__PURE__ */ t("span", { children: o })
823
+ ] })
824
+ ]
825
+ }
826
+ );
827
+ }
828
+ function M(e) {
829
+ return e.replace(/[A-Z]/g, (n) => `-${n.toLowerCase()}`);
830
+ }
831
+ function Ce(e) {
832
+ if (!e) return {};
833
+ const n = {};
834
+ if (e.colors)
835
+ for (const [s, r] of Object.entries(e.colors))
836
+ r && (n[`--fc-color-${M(s)}`] = r);
837
+ if (e.typography)
838
+ for (const [s, r] of Object.entries(e.typography))
839
+ r && (n[`--fc-${M(s)}`] = r);
840
+ if (e.spacing)
841
+ for (const [s, r] of Object.entries(e.spacing))
842
+ r && (n[`--fc-${M(s)}`] = r);
843
+ if (e.borders)
844
+ for (const [s, r] of Object.entries(e.borders))
845
+ r && (n[`--fc-border-${M(s)}`] = r);
846
+ if (e.shadows)
847
+ for (const [s, r] of Object.entries(e.shadows))
848
+ r && (n[`--fc-shadow-${M(s)}`] = r);
849
+ if (e.transitions)
850
+ for (const [s, r] of Object.entries(e.transitions))
851
+ r && (n[`--fc-transition-${M(s)}`] = r);
852
+ return e.cssVars && Object.assign(n, e.cssVars), n;
853
+ }
854
+ function Q(e, n, s, r, a) {
855
+ var l, m;
856
+ const o = e.translations;
857
+ if (!o) return a;
858
+ const i = o[s];
859
+ if ((l = i == null ? void 0 : i.messages) != null && l[n]) return i.messages[n];
860
+ const u = o[r];
861
+ return ((m = u == null ? void 0 : u.messages) == null ? void 0 : m[n]) ?? a;
862
+ }
863
+ function X(e, n, s, r, a) {
864
+ const o = e.translations;
865
+ if (!o) return a;
866
+ const i = o[s];
867
+ if (i != null && i[n]) return i[n];
868
+ const u = o[r];
869
+ return (u == null ? void 0 : u[n]) ?? a;
870
+ }
871
+ function Y(e) {
872
+ return Array.isArray(e) ? e : [];
873
+ }
874
+ function $e({ field: e, value: n, onChange: s, onBlur: r, disabled: a }) {
875
+ switch (e.type) {
876
+ case "text":
877
+ return /* @__PURE__ */ t(
878
+ J,
879
+ {
880
+ value: String(n ?? ""),
881
+ onChange: s,
882
+ onBlur: r,
883
+ disabled: a,
884
+ placeholder: e.placeholder,
885
+ inputType: e.inputType,
886
+ readOnly: e.readOnly
887
+ }
888
+ );
889
+ case "number":
890
+ return /* @__PURE__ */ t(
891
+ be,
892
+ {
893
+ value: n,
894
+ onChange: s,
895
+ onBlur: r,
896
+ disabled: a,
897
+ placeholder: e.placeholder,
898
+ min: e.min,
899
+ max: e.max,
900
+ step: e.step,
901
+ readOnly: e.readOnly
902
+ }
903
+ );
904
+ case "textarea":
905
+ return /* @__PURE__ */ t(
906
+ ye,
907
+ {
908
+ value: String(n ?? ""),
909
+ onChange: s,
910
+ onBlur: r,
911
+ disabled: a,
912
+ placeholder: e.placeholder,
913
+ rows: e.rows,
914
+ readOnly: e.readOnly
915
+ }
916
+ );
917
+ case "select":
918
+ return /* @__PURE__ */ t(
919
+ he,
920
+ {
921
+ value: n,
922
+ onChange: s,
923
+ onBlur: r,
924
+ disabled: a,
925
+ placeholder: e.placeholder,
926
+ options: Y(e.options)
927
+ }
928
+ );
929
+ case "checkbox":
930
+ return /* @__PURE__ */ t(
931
+ xe,
932
+ {
933
+ value: !!n,
934
+ onChange: s,
935
+ onBlur: r,
936
+ disabled: a
937
+ }
938
+ );
939
+ case "radio":
940
+ return /* @__PURE__ */ t(
941
+ ve,
942
+ {
943
+ name: e.name,
944
+ value: n,
945
+ onChange: s,
946
+ onBlur: r,
947
+ disabled: a,
948
+ options: Y(e.options)
949
+ }
950
+ );
951
+ case "switch":
952
+ return /* @__PURE__ */ t(
953
+ we,
954
+ {
955
+ value: !!n,
956
+ onChange: s,
957
+ onBlur: r,
958
+ disabled: a
959
+ }
960
+ );
961
+ case "slider":
962
+ return /* @__PURE__ */ t(
963
+ Ne,
964
+ {
965
+ value: n,
966
+ onChange: s,
967
+ onBlur: r,
968
+ disabled: a,
969
+ min: e.min,
970
+ max: e.max,
971
+ step: e.step
972
+ }
973
+ );
974
+ default:
975
+ return /* @__PURE__ */ t(
976
+ J,
977
+ {
978
+ value: String(n ?? ""),
979
+ onChange: s,
980
+ onBlur: r,
981
+ disabled: a,
982
+ placeholder: e.placeholder
983
+ }
984
+ );
985
+ }
986
+ }
987
+ function re(e) {
988
+ return e === "full" ? { gridColumn: "1 / -1" } : e === "auto" ? { gridColumn: "auto" } : typeof e == "number" ? { gridColumn: `span ${e} / span ${e}` } : { gridColumn: "span 12 / span 12" };
989
+ }
990
+ function ke(e, n, s) {
991
+ const r = n.errors[e.name] ?? [], a = e.disabled === !0 || !1, o = {
992
+ field: e,
993
+ value: n.values[e.name],
994
+ onChange: (l) => n.setFieldValue(e.name, l),
995
+ onBlur: () => n.validateField(e.name),
996
+ errors: r,
997
+ disabled: a
998
+ }, u = (s == null ? void 0 : s[e.type]) ?? $e;
999
+ return /* @__PURE__ */ t(
1000
+ fe,
1001
+ {
1002
+ label: e.label,
1003
+ required: e.required,
1004
+ errors: r,
1005
+ touched: n.touched[e.name],
1006
+ helpText: e.helpText,
1007
+ tooltip: e.tooltip,
1008
+ disabled: e.disabled,
1009
+ readOnly: e.readOnly,
1010
+ fieldName: e.name,
1011
+ className: e.className,
1012
+ style: e.style,
1013
+ children: /* @__PURE__ */ t(u, { ...o })
1014
+ },
1015
+ e.name
1016
+ );
1017
+ }
1018
+ function Se(e, n, s) {
1019
+ const a = {
1020
+ start: "items-start",
1021
+ center: "items-center",
1022
+ end: "items-end",
1023
+ stretch: "items-stretch"
1024
+ }[e.align ?? "stretch"] ?? "items-stretch", o = e.gap !== void 0 ? typeof e.gap == "number" ? `${e.gap}px` : e.gap : "1rem";
1025
+ return /* @__PURE__ */ t(
1026
+ "div",
1027
+ {
1028
+ className: `grid grid-cols-12 ${a} ${e.className ?? ""}`,
1029
+ style: { gap: o },
1030
+ role: "group",
1031
+ children: e.children.map((i, u) => /* @__PURE__ */ t(
1032
+ "div",
1033
+ {
1034
+ style: re(O(i) ? i.span : void 0),
1035
+ children: K(i, n, s)
1036
+ },
1037
+ O(i) ? i.name : `row-child-${u}`
1038
+ ))
1039
+ }
1040
+ );
1041
+ }
1042
+ function Fe({
1043
+ node: e,
1044
+ form: n,
1045
+ components: s
1046
+ }) {
1047
+ const [r, a] = S(e.collapsed ?? !1), o = e.title ? `fc-group-${e.title.toLowerCase().replace(/\s+/g, "-")}` : void 0;
1048
+ function i() {
1049
+ e.collapsible && a(!r);
1050
+ }
1051
+ const u = e.collapsible ? "button" : "div";
1052
+ return /* @__PURE__ */ g(
1053
+ "fieldset",
1054
+ {
1055
+ className: `rounded-lg border border-gray-200 bg-white ${e.className ?? ""}`,
1056
+ "aria-labelledby": o,
1057
+ children: [
1058
+ (e.title || e.description) && /* @__PURE__ */ t("div", { className: "border-b border-gray-100 px-4 py-3", children: /* @__PURE__ */ g(
1059
+ u,
1060
+ {
1061
+ type: e.collapsible ? "button" : void 0,
1062
+ className: `flex w-full items-center justify-between text-left ${e.collapsible ? "cursor-pointer focus:outline-none focus:ring-2 focus:ring-blue-500/40 rounded" : ""}`,
1063
+ "aria-expanded": e.collapsible ? !r : void 0,
1064
+ "aria-controls": e.collapsible ? `fc-group-body-${o}` : void 0,
1065
+ onClick: i,
1066
+ children: [
1067
+ /* @__PURE__ */ g("div", { children: [
1068
+ e.title && /* @__PURE__ */ t(
1069
+ "legend",
1070
+ {
1071
+ id: o,
1072
+ className: "text-sm font-semibold text-gray-800",
1073
+ children: e.title
1074
+ }
1075
+ ),
1076
+ e.description && /* @__PURE__ */ t("p", { className: "mt-0.5 text-xs text-gray-500", children: e.description })
1077
+ ] }),
1078
+ e.collapsible && /* @__PURE__ */ t(
1079
+ "svg",
1080
+ {
1081
+ className: `h-4 w-4 shrink-0 text-gray-400 transition-transform duration-200 ${r ? "" : "rotate-180"}`,
1082
+ xmlns: "http://www.w3.org/2000/svg",
1083
+ viewBox: "0 0 20 20",
1084
+ fill: "currentColor",
1085
+ "aria-hidden": "true",
1086
+ children: /* @__PURE__ */ t(
1087
+ "path",
1088
+ {
1089
+ fillRule: "evenodd",
1090
+ d: "M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",
1091
+ clipRule: "evenodd"
1092
+ }
1093
+ )
1094
+ }
1095
+ )
1096
+ ]
1097
+ }
1098
+ ) }),
1099
+ !r && /* @__PURE__ */ t(
1100
+ "div",
1101
+ {
1102
+ id: e.collapsible ? `fc-group-body-${o}` : void 0,
1103
+ className: "p-4",
1104
+ children: e.children.map((l, m) => /* @__PURE__ */ t("div", { children: K(l, n, s) }, O(l) ? l.name : `group-child-${m}`))
1105
+ }
1106
+ )
1107
+ ]
1108
+ }
1109
+ );
1110
+ }
1111
+ function De({
1112
+ node: e,
1113
+ form: n,
1114
+ components: s
1115
+ }) {
1116
+ const [r, a] = S(0), [o, i] = S(/* @__PURE__ */ new Set()), u = e.steps, l = u.length, m = r === 0, d = r === l - 1;
1117
+ function h() {
1118
+ d || (i((p) => {
1119
+ const b = new Set(p);
1120
+ return b.add(r), b;
1121
+ }), a((p) => p + 1));
1122
+ }
1123
+ function f() {
1124
+ m || a((p) => p - 1);
1125
+ }
1126
+ function C(p) {
1127
+ e.linear && p > r || a(p);
1128
+ }
1129
+ const v = u[r];
1130
+ return /* @__PURE__ */ g("div", { className: `space-y-6 ${e.className ?? ""}`, children: [
1131
+ /* @__PURE__ */ t("nav", { "aria-label": "Form steps", className: "flex items-center justify-center", children: /* @__PURE__ */ t("ol", { className: "flex items-center gap-0", children: u.map((p, b) => /* @__PURE__ */ g("li", { className: "flex items-center", children: [
1132
+ /* @__PURE__ */ t(
1133
+ "button",
1134
+ {
1135
+ type: "button",
1136
+ disabled: e.linear === !0 && b > r,
1137
+ "aria-current": b === r ? "step" : void 0,
1138
+ "aria-label": `Step ${b + 1}: ${p.title}`,
1139
+ className: `relative flex h-8 w-8 shrink-0 items-center justify-center rounded-full border-2 text-xs font-semibold transition-all duration-300 focus:outline-none focus:ring-2 focus:ring-blue-500/40 ${o.has(b) && b !== r ? "border-green-500 bg-green-500 text-white" : b !== r ? "border-gray-300 bg-white text-gray-500" : "text-white"} ${e.linear === !0 && b > r ? "cursor-not-allowed" : "cursor-pointer hover:shadow-md"}`,
1140
+ style: b === r ? {
1141
+ borderColor: "var(--fc-color-primary, #3b82f6)",
1142
+ backgroundColor: "var(--fc-color-primary, #3b82f6)"
1143
+ } : {},
1144
+ onClick: () => C(b),
1145
+ children: o.has(b) && b !== r ? /* @__PURE__ */ t(
1146
+ "svg",
1147
+ {
1148
+ className: "h-4 w-4 transition-transform duration-200",
1149
+ xmlns: "http://www.w3.org/2000/svg",
1150
+ viewBox: "0 0 20 20",
1151
+ fill: "currentColor",
1152
+ "aria-hidden": "true",
1153
+ children: /* @__PURE__ */ t(
1154
+ "path",
1155
+ {
1156
+ fillRule: "evenodd",
1157
+ d: "M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z",
1158
+ clipRule: "evenodd"
1159
+ }
1160
+ )
1161
+ }
1162
+ ) : /* @__PURE__ */ t("span", { children: b + 1 })
1163
+ }
1164
+ ),
1165
+ b < u.length - 1 && /* @__PURE__ */ t(
1166
+ "div",
1167
+ {
1168
+ className: `mx-1 h-0.5 w-8 transition-colors duration-300 sm:w-12 ${o.has(b) ? "bg-green-500" : "bg-gray-200"}`
1169
+ }
1170
+ )
1171
+ ] }, p.title)) }) }),
1172
+ v && /* @__PURE__ */ g("div", { className: "text-center", children: [
1173
+ /* @__PURE__ */ t("h3", { className: "text-base font-semibold text-gray-800", children: v.title }),
1174
+ v.description && /* @__PURE__ */ t("p", { className: "mt-1 text-sm text-gray-500", children: v.description })
1175
+ ] }),
1176
+ v && /* @__PURE__ */ t("div", { children: v.children.map((p, b) => /* @__PURE__ */ t("div", { children: K(p, n, s) }, O(p) ? p.name : `step-child-${b}`)) }),
1177
+ /* @__PURE__ */ g("div", { className: "flex items-center justify-between border-t border-gray-100 pt-4", children: [
1178
+ /* @__PURE__ */ t(
1179
+ "button",
1180
+ {
1181
+ type: "button",
1182
+ disabled: m,
1183
+ className: "rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 transition-colors duration-150 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50",
1184
+ onClick: f,
1185
+ children: "Previous"
1186
+ }
1187
+ ),
1188
+ /* @__PURE__ */ g("span", { className: "text-xs text-gray-400", children: [
1189
+ r + 1,
1190
+ " / ",
1191
+ l
1192
+ ] }),
1193
+ d ? /* @__PURE__ */ t("div", { className: "w-[72px]" }) : /* @__PURE__ */ t(
1194
+ "button",
1195
+ {
1196
+ type: "button",
1197
+ className: "rounded-md px-4 py-2 text-sm font-medium text-white transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-blue-500/40",
1198
+ style: {
1199
+ backgroundColor: "var(--fc-color-primary, #3b82f6)"
1200
+ },
1201
+ onClick: h,
1202
+ children: "Next"
1203
+ }
1204
+ )
1205
+ ] })
1206
+ ] });
1207
+ }
1208
+ function Re({
1209
+ node: e,
1210
+ form: n,
1211
+ components: s
1212
+ }) {
1213
+ const [r, a] = S(0), o = e.tabs, i = o[r], u = `fc-tabpanel-${r}`;
1214
+ function l(m) {
1215
+ a(m);
1216
+ }
1217
+ return /* @__PURE__ */ g("div", { className: e.className ?? "", children: [
1218
+ /* @__PURE__ */ t(
1219
+ "div",
1220
+ {
1221
+ className: "relative flex border-b border-gray-200",
1222
+ role: "tablist",
1223
+ "aria-orientation": "horizontal",
1224
+ children: o.map((m, d) => /* @__PURE__ */ g(
1225
+ "button",
1226
+ {
1227
+ id: `fc-tab-${d}`,
1228
+ type: "button",
1229
+ role: "tab",
1230
+ "aria-selected": d === r,
1231
+ "aria-controls": u,
1232
+ tabIndex: d === r ? 0 : -1,
1233
+ className: `relative px-4 py-2.5 text-sm font-medium transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-blue-500/40 ${d !== r ? "text-gray-500 hover:text-gray-700" : ""}`,
1234
+ style: d === r ? { color: "var(--fc-color-primary, #3b82f6)" } : {},
1235
+ onClick: () => l(d),
1236
+ children: [
1237
+ m.title,
1238
+ d === r && /* @__PURE__ */ t(
1239
+ "span",
1240
+ {
1241
+ className: "absolute inset-x-0 -bottom-px h-0.5 transition-all duration-200",
1242
+ style: {
1243
+ backgroundColor: "var(--fc-color-primary, #3b82f6)"
1244
+ }
1245
+ }
1246
+ )
1247
+ ]
1248
+ },
1249
+ m.title
1250
+ ))
1251
+ }
1252
+ ),
1253
+ i && /* @__PURE__ */ t(
1254
+ "div",
1255
+ {
1256
+ id: u,
1257
+ role: "tabpanel",
1258
+ "aria-labelledby": `fc-tab-${r}`,
1259
+ tabIndex: 0,
1260
+ className: "pt-4",
1261
+ children: i.children.map((m, d) => /* @__PURE__ */ t("div", { children: K(m, n, s) }, O(m) ? m.name : `tab-child-${d}`))
1262
+ }
1263
+ )
1264
+ ] });
1265
+ }
1266
+ function je(e) {
1267
+ return e.label ? /* @__PURE__ */ g("div", { className: `relative my-4 ${e.className ?? ""}`, children: [
1268
+ /* @__PURE__ */ t("div", { className: "absolute inset-0 flex items-center", "aria-hidden": "true", children: /* @__PURE__ */ t("div", { className: "w-full border-t border-gray-200" }) }),
1269
+ /* @__PURE__ */ t("div", { className: "relative flex justify-center", children: /* @__PURE__ */ t("span", { className: "bg-white px-3 text-sm text-gray-500", children: e.label }) })
1270
+ ] }) : /* @__PURE__ */ t("hr", { className: `my-4 border-gray-200 ${e.className ?? ""}` });
1271
+ }
1272
+ function K(e, n, s) {
1273
+ if (O(e))
1274
+ return ke(e, n, s);
1275
+ switch (e.type) {
1276
+ case "row":
1277
+ return Se(e, n, s);
1278
+ case "group":
1279
+ return /* @__PURE__ */ t(Fe, { node: e, form: n, components: s });
1280
+ case "steps":
1281
+ return /* @__PURE__ */ t(De, { node: e, form: n, components: s });
1282
+ case "tabs":
1283
+ return /* @__PURE__ */ t(Re, { node: e, form: n, components: s });
1284
+ case "divider":
1285
+ return je(e);
1286
+ case "html":
1287
+ return /* @__PURE__ */ t(
1288
+ "div",
1289
+ {
1290
+ className: e.className ?? "",
1291
+ dangerouslySetInnerHTML: { __html: e.content }
1292
+ }
1293
+ );
1294
+ default:
1295
+ return null;
1296
+ }
1297
+ }
1298
+ function Ae({
1299
+ schema: e,
1300
+ onSubmit: n,
1301
+ onError: s,
1302
+ locale: r = "en",
1303
+ fallbackLocale: a = "en",
1304
+ theme: o,
1305
+ components: i,
1306
+ className: u
1307
+ }) {
1308
+ var b, k;
1309
+ const l = de(e), m = Ce(o), d = Q(e, "title", r, a, ""), h = Q(e, "description", r, a, ""), f = X(e, "submit", r, a, "Submit"), C = X(e, "reset", r, a, "Reset"), v = async (x) => {
1310
+ x.preventDefault(), n ? await l.submit(async (F) => {
1311
+ await n(F);
1312
+ }) : await l.validate(), !l.isValid && s && s(l.errors);
1313
+ }, p = (x) => {
1314
+ x.preventDefault(), l.reset();
1315
+ };
1316
+ return /* @__PURE__ */ t(ee.Provider, { value: l, children: /* @__PURE__ */ g(
1317
+ "form",
1318
+ {
1319
+ className: `fc-form-builder ${((b = o == null ? void 0 : o.components) == null ? void 0 : b.form) ?? ""} ${u ?? ""}`.trim(),
1320
+ style: m,
1321
+ onSubmit: v,
1322
+ onReset: p,
1323
+ noValidate: !0,
1324
+ children: [
1325
+ (d || h) && /* @__PURE__ */ g("div", { className: "mb-6", children: [
1326
+ d && /* @__PURE__ */ t("h2", { className: "text-lg font-semibold text-gray-900", children: d }),
1327
+ h && /* @__PURE__ */ t("p", { className: "mt-1 text-sm text-gray-500", children: h })
1328
+ ] }),
1329
+ e.fields.map((x, F) => /* @__PURE__ */ t(
1330
+ "div",
1331
+ {
1332
+ style: O(x) ? re(x.span) : void 0,
1333
+ children: K(x, l, i)
1334
+ },
1335
+ O(x) ? x.name : `node-${F}`
1336
+ )),
1337
+ /* @__PURE__ */ g("div", { className: "mt-6 flex items-center gap-3", children: [
1338
+ /* @__PURE__ */ g(
1339
+ "button",
1340
+ {
1341
+ type: "submit",
1342
+ disabled: l.isSubmitting,
1343
+ className: `fc-submit-btn rounded-md px-4 py-2 text-sm font-medium text-white transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50 ${((k = o == null ? void 0 : o.components) == null ? void 0 : k.button) ?? ""}`,
1344
+ style: {
1345
+ backgroundColor: "var(--fc-color-primary, #3b82f6)"
1346
+ },
1347
+ children: [
1348
+ l.isSubmitting && /* @__PURE__ */ t(
1349
+ "span",
1350
+ {
1351
+ className: "mr-2 inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-white border-t-transparent",
1352
+ "aria-hidden": "true"
1353
+ }
1354
+ ),
1355
+ f
1356
+ ]
1357
+ }
1358
+ ),
1359
+ /* @__PURE__ */ t(
1360
+ "button",
1361
+ {
1362
+ type: "reset",
1363
+ disabled: l.isSubmitting,
1364
+ className: "rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 transition-colors duration-150 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500/40 disabled:cursor-not-allowed disabled:opacity-50",
1365
+ children: C
1366
+ }
1367
+ )
1368
+ ] })
1369
+ ]
1370
+ }
1371
+ ) });
1372
+ }
1373
+ export {
1374
+ Ae as FormBuilder,
1375
+ ee as FormContext,
1376
+ de as useForm,
1377
+ Te as useFormContext
1378
+ };
1379
+ //# sourceMappingURL=formatica-react.es.js.map