@ram_28/kf-ai-sdk 1.0.13 → 1.0.14

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.
package/dist/form.mjs CHANGED
@@ -1,1025 +1,16 @@
1
- var Bt = Object.defineProperty;
2
- var Pt = (e, t, r) => t in e ? Bt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
- var we = (e, t, r) => Pt(e, typeof t != "symbol" ? t + "" : t, r);
4
- import X, { useState as ye, useRef as qe, useEffect as $e, useMemo as Ne, useCallback as te } from "react";
5
- import { u as ct } from "./useQuery-KpZFg80c.js";
6
- import { a as pe } from "./client-CfvLiGfP.js";
7
- import { g as qt } from "./metadata-DBcoDth-.js";
8
- var Le = (e) => e.type === "checkbox", ge = (e) => e instanceof Date, G = (e) => e == null;
9
- const St = (e) => typeof e == "object";
10
- var I = (e) => !G(e) && !Array.isArray(e) && St(e) && !ge(e), $t = (e) => I(e) && e.target ? Le(e.target) ? e.target.checked : e.target.value : e, jt = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, Wt = (e, t) => e.has(jt(t)), Ht = (e) => {
11
- const t = e.constructor && e.constructor.prototype;
12
- return I(t) && t.hasOwnProperty("isPrototypeOf");
13
- }, rt = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
14
- function k(e) {
15
- if (e instanceof Date)
16
- return new Date(e);
17
- const t = typeof FileList < "u" && e instanceof FileList;
18
- if (rt && (e instanceof Blob || t))
19
- return e;
20
- const r = Array.isArray(e);
21
- if (!r && !(I(e) && Ht(e)))
22
- return e;
23
- const s = r ? [] : Object.create(Object.getPrototypeOf(e));
24
- for (const i in e)
25
- Object.prototype.hasOwnProperty.call(e, i) && (s[i] = k(e[i]));
26
- return s;
27
- }
28
- var He = (e) => /^\w*$/.test(e), C = (e) => e === void 0, st = (e) => Array.isArray(e) ? e.filter(Boolean) : [], it = (e) => st(e.replace(/["|']|\]/g, "").split(/\.|\[/)), g = (e, t, r) => {
29
- if (!t || !I(e))
30
- return r;
31
- const s = (He(t) ? [t] : it(t)).reduce((i, n) => G(i) ? i : i[n], e);
32
- return C(s) || s === e ? C(e[t]) ? r : e[t] : s;
33
- }, ie = (e) => typeof e == "boolean", re = (e) => typeof e == "function", R = (e, t, r) => {
34
- let s = -1;
35
- const i = He(t) ? [t] : it(t), n = i.length, l = n - 1;
36
- for (; ++s < n; ) {
37
- const d = i[s];
38
- let w = r;
39
- if (s !== l) {
40
- const p = e[d];
41
- w = I(p) || Array.isArray(p) ? p : isNaN(+i[s + 1]) ? {} : [];
42
- }
43
- if (d === "__proto__" || d === "constructor" || d === "prototype")
44
- return;
45
- e[d] = w, e = e[d];
46
- }
47
- };
48
- const dt = {
49
- BLUR: "blur",
50
- FOCUS_OUT: "focusout"
51
- }, se = {
52
- onBlur: "onBlur",
53
- onChange: "onChange",
54
- onSubmit: "onSubmit",
55
- onTouched: "onTouched",
56
- all: "all"
57
- }, ue = {
58
- max: "max",
59
- min: "min",
60
- maxLength: "maxLength",
61
- minLength: "minLength",
62
- pattern: "pattern",
63
- required: "required",
64
- validate: "validate"
65
- }, Yt = X.createContext(null);
66
- Yt.displayName = "HookFormContext";
67
- var Kt = (e, t, r, s = !0) => {
68
- const i = {
69
- defaultValues: t._defaultValues
70
- };
71
- for (const n in e)
72
- Object.defineProperty(i, n, {
73
- get: () => {
74
- const l = n;
75
- return t._proxyFormState[l] !== se.all && (t._proxyFormState[l] = !s || se.all), e[l];
76
- }
77
- });
78
- return i;
79
- };
80
- const zt = typeof window < "u" ? X.useLayoutEffect : X.useEffect;
81
- var Q = (e) => typeof e == "string", Jt = (e, t, r, s, i) => Q(e) ? (s && t.watch.add(e), g(r, e, i)) : Array.isArray(e) ? e.map((n) => (s && t.watch.add(n), g(r, n))) : (s && (t.watchAll = !0), r), et = (e) => G(e) || !St(e);
82
- function de(e, t, r = /* @__PURE__ */ new WeakSet()) {
83
- if (et(e) || et(t))
84
- return Object.is(e, t);
85
- if (ge(e) && ge(t))
86
- return Object.is(e.getTime(), t.getTime());
87
- const s = Object.keys(e), i = Object.keys(t);
88
- if (s.length !== i.length)
89
- return !1;
90
- if (r.has(e) || r.has(t))
91
- return !0;
92
- r.add(e), r.add(t);
93
- for (const n of s) {
94
- const l = e[n];
95
- if (!i.includes(n))
96
- return !1;
97
- if (n !== "ref") {
98
- const d = t[n];
99
- if (ge(l) && ge(d) || I(l) && I(d) || Array.isArray(l) && Array.isArray(d) ? !de(l, d, r) : !Object.is(l, d))
100
- return !1;
101
- }
102
- }
103
- return !0;
104
- }
105
- var Gt = (e, t, r, s, i) => t ? {
106
- ...r[e],
107
- types: {
108
- ...r[e] && r[e].types ? r[e].types : {},
109
- [s]: i || !0
110
- }
111
- } : {}, Ce = (e) => Array.isArray(e) ? e : [e], ft = () => {
112
- let e = [];
1
+ var Ue = Object.defineProperty;
2
+ var _e = (t, e, r) => e in t ? Ue(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var U = (t, e, r) => _e(t, typeof e != "symbol" ? e + "" : e, r);
4
+ import { useState as M, useRef as Y, useEffect as z, useMemo as $, useCallback as S } from "react";
5
+ import { useForm as $e } from "react-hook-form";
6
+ import { useQuery as ue } from "@tanstack/react-query";
7
+ import { a as I } from "./client-CfvLiGfP.js";
8
+ import { g as qe } from "./metadata-DBcoDth-.js";
9
+ function Be() {
10
+ const t = /* @__PURE__ */ new Date();
113
11
  return {
114
- get observers() {
115
- return e;
116
- },
117
- next: (i) => {
118
- for (const n of e)
119
- n.next && n.next(i);
120
- },
121
- subscribe: (i) => (e.push(i), {
122
- unsubscribe: () => {
123
- e = e.filter((n) => n !== i);
124
- }
125
- }),
126
- unsubscribe: () => {
127
- e = [];
128
- }
129
- };
130
- };
131
- function Rt(e, t) {
132
- const r = {};
133
- for (const s in e)
134
- if (e.hasOwnProperty(s)) {
135
- const i = e[s], n = t[s];
136
- if (i && I(i) && n) {
137
- const l = Rt(i, n);
138
- I(l) && (r[s] = l);
139
- } else e[s] && (r[s] = n);
140
- }
141
- return r;
142
- }
143
- var Y = (e) => I(e) && !Object.keys(e).length, at = (e) => e.type === "file", je = (e) => {
144
- if (!rt)
145
- return !1;
146
- const t = e ? e.ownerDocument : 0;
147
- return e instanceof (t && t.defaultView ? t.defaultView.HTMLElement : HTMLElement);
148
- }, Nt = (e) => e.type === "select-multiple", nt = (e) => e.type === "radio", Xt = (e) => nt(e) || Le(e), Qe = (e) => je(e) && e.isConnected;
149
- function Qt(e, t) {
150
- const r = t.slice(0, -1).length;
151
- let s = 0;
152
- for (; s < r; )
153
- e = C(e) ? s++ : e[t[s++]];
154
- return e;
155
- }
156
- function Zt(e) {
157
- for (const t in e)
158
- if (e.hasOwnProperty(t) && !C(e[t]))
159
- return !1;
160
- return !0;
161
- }
162
- function M(e, t) {
163
- const r = Array.isArray(t) ? t : He(t) ? [t] : it(t), s = r.length === 1 ? e : Qt(e, r), i = r.length - 1, n = r[i];
164
- return s && delete s[n], i !== 0 && (I(s) && Y(s) || Array.isArray(s) && Zt(s)) && M(e, r.slice(0, -1)), e;
165
- }
166
- var er = (e) => {
167
- for (const t in e)
168
- if (re(e[t]))
169
- return !0;
170
- return !1;
171
- };
172
- function Ot(e) {
173
- return Array.isArray(e) || I(e) && !er(e);
174
- }
175
- function tt(e, t = {}) {
176
- for (const r in e) {
177
- const s = e[r];
178
- Ot(s) ? (t[r] = Array.isArray(s) ? [] : {}, tt(s, t[r])) : C(s) || (t[r] = !0);
179
- }
180
- return t;
181
- }
182
- function Fe(e, t, r) {
183
- r || (r = tt(t));
184
- for (const s in e) {
185
- const i = e[s];
186
- if (Ot(i))
187
- C(t) || et(r[s]) ? r[s] = tt(i, Array.isArray(i) ? [] : {}) : Fe(i, G(t) ? {} : t[s], r[s]);
188
- else {
189
- const n = t[s];
190
- r[s] = !de(i, n);
191
- }
192
- }
193
- return r;
194
- }
195
- const ht = {
196
- value: !1,
197
- isValid: !1
198
- }, mt = { value: !0, isValid: !0 };
199
- var Ct = (e) => {
200
- if (Array.isArray(e)) {
201
- if (e.length > 1) {
202
- const t = e.filter((r) => r && r.checked && !r.disabled).map((r) => r.value);
203
- return { value: t, isValid: !!t.length };
204
- }
205
- return e[0].checked && !e[0].disabled ? (
206
- // @ts-expect-error expected to work in the browser
207
- e[0].attributes && !C(e[0].attributes.value) ? C(e[0].value) || e[0].value === "" ? mt : { value: e[0].value, isValid: !0 } : mt
208
- ) : ht;
209
- }
210
- return ht;
211
- }, Tt = (e, { valueAsNumber: t, valueAsDate: r, setValueAs: s }) => C(e) ? e : t ? e === "" ? NaN : e && +e : r && Q(e) ? new Date(e) : s ? s(e) : e;
212
- const yt = {
213
- isValid: !1,
214
- value: null
215
- };
216
- var Lt = (e) => Array.isArray(e) ? e.reduce((t, r) => r && r.checked && !r.disabled ? {
217
- isValid: !0,
218
- value: r.value
219
- } : t, yt) : yt;
220
- function gt(e) {
221
- const t = e.ref;
222
- return at(t) ? t.files : nt(t) ? Lt(e.refs).value : Nt(t) ? [...t.selectedOptions].map(({ value: r }) => r) : Le(t) ? Ct(e.refs).value : Tt(C(t.value) ? e.ref.value : t.value, e);
223
- }
224
- var tr = (e, t, r, s) => {
225
- const i = {};
226
- for (const n of e) {
227
- const l = g(t, n);
228
- l && R(i, n, l._f);
229
- }
230
- return {
231
- criteriaMode: r,
232
- names: [...e],
233
- fields: i,
234
- shouldUseNativeValidation: s
235
- };
236
- }, We = (e) => e instanceof RegExp, Oe = (e) => C(e) ? e : We(e) ? e.source : I(e) ? We(e.value) ? e.value.source : e.value : e, pt = (e) => ({
237
- isOnSubmit: !e || e === se.onSubmit,
238
- isOnBlur: e === se.onBlur,
239
- isOnChange: e === se.onChange,
240
- isOnAll: e === se.all,
241
- isOnTouch: e === se.onTouched
242
- });
243
- const bt = "AsyncFunction";
244
- var rr = (e) => !!e && !!e.validate && !!(re(e.validate) && e.validate.constructor.name === bt || I(e.validate) && Object.values(e.validate).find((t) => t.constructor.name === bt)), sr = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate), wt = (e, t, r) => !r && (t.watchAll || t.watch.has(e) || [...t.watch].some((s) => e.startsWith(s) && /^\.\w+/.test(e.slice(s.length))));
245
- const Te = (e, t, r, s) => {
246
- for (const i of r || Object.keys(e)) {
247
- const n = g(e, i);
248
- if (n) {
249
- const { _f: l, ...d } = n;
250
- if (l) {
251
- if (l.refs && l.refs[0] && t(l.refs[0], i) && !s)
252
- return !0;
253
- if (l.ref && t(l.ref, l.name) && !s)
254
- return !0;
255
- if (Te(d, t))
256
- break;
257
- } else if (I(d) && Te(d, t))
258
- break;
259
- }
260
- }
261
- };
262
- function vt(e, t, r) {
263
- const s = g(e, r);
264
- if (s || He(r))
265
- return {
266
- error: s,
267
- name: r
268
- };
269
- const i = r.split(".");
270
- for (; i.length; ) {
271
- const n = i.join("."), l = g(t, n), d = g(e, n);
272
- if (l && !Array.isArray(l) && r !== n)
273
- return { name: r };
274
- if (d && d.type)
275
- return {
276
- name: n,
277
- error: d
278
- };
279
- if (d && d.root && d.root.type)
280
- return {
281
- name: `${n}.root`,
282
- error: d.root
283
- };
284
- i.pop();
285
- }
286
- return {
287
- name: r
288
- };
289
- }
290
- var ir = (e, t, r, s) => {
291
- r(e);
292
- const { name: i, ...n } = e;
293
- return Y(n) || Object.keys(n).length >= Object.keys(t).length || Object.keys(n).find((l) => t[l] === (!s || se.all));
294
- }, ar = (e, t, r) => !e || !t || e === t || Ce(e).some((s) => s && (r ? s === t : s.startsWith(t) || t.startsWith(s))), nr = (e, t, r, s, i) => i.isOnAll ? !1 : !r && i.isOnTouch ? !(t || e) : (r ? s.isOnBlur : i.isOnBlur) ? !e : (r ? s.isOnChange : i.isOnChange) ? e : !0, ur = (e, t) => !st(g(e, t)).length && M(e, t), or = (e, t, r) => {
295
- const s = Ce(g(e, r));
296
- return R(s, "root", t[r]), R(e, r, s), e;
297
- };
298
- function Ft(e, t, r = "validate") {
299
- if (Q(e) || Array.isArray(e) && e.every(Q) || ie(e) && !e)
300
- return {
301
- type: r,
302
- message: Q(e) ? e : "",
303
- ref: t
304
- };
305
- }
306
- var ve = (e) => I(e) && !We(e) ? e : {
307
- value: e,
308
- message: ""
309
- }, Vt = async (e, t, r, s, i, n) => {
310
- const { ref: l, refs: d, required: w, maxLength: p, minLength: N, min: D, max: v, pattern: m, validate: K, name: O, valueAsNumber: Z, mount: H } = e._f, x = g(r, O);
311
- if (!H || t.has(O))
312
- return {};
313
- const ee = d ? d[0] : l, L = (V) => {
314
- i && ee.reportValidity && (ee.setCustomValidity(ie(V) ? "" : V || ""), ee.reportValidity());
315
- }, T = {}, oe = nt(l), he = Le(l), ae = oe || he, ne = (Z || at(l)) && C(l.value) && C(x) || je(l) && l.value === "" || x === "" || Array.isArray(x) && !x.length, B = Gt.bind(null, O, s, T), le = (V, E, S, U = ue.maxLength, $ = ue.minLength) => {
316
- const j = V ? E : S;
317
- T[O] = {
318
- type: V ? U : $,
319
- message: j,
320
- ref: l,
321
- ...B(V ? U : $, j)
322
- };
323
- };
324
- if (n ? !Array.isArray(x) || !x.length : w && (!ae && (ne || G(x)) || ie(x) && !x || he && !Ct(d).isValid || oe && !Lt(d).isValid)) {
325
- const { value: V, message: E } = Q(w) ? { value: !!w, message: w } : ve(w);
326
- if (V && (T[O] = {
327
- type: ue.required,
328
- message: E,
329
- ref: ee,
330
- ...B(ue.required, E)
331
- }, !s))
332
- return L(E), T;
333
- }
334
- if (!ne && (!G(D) || !G(v))) {
335
- let V, E;
336
- const S = ve(v), U = ve(D);
337
- if (!G(x) && !isNaN(x)) {
338
- const $ = l.valueAsNumber || x && +x;
339
- G(S.value) || (V = $ > S.value), G(U.value) || (E = $ < U.value);
340
- } else {
341
- const $ = l.valueAsDate || new Date(x), j = (me) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + me), z = l.type == "time", ce = l.type == "week";
342
- Q(S.value) && x && (V = z ? j(x) > j(S.value) : ce ? x > S.value : $ > new Date(S.value)), Q(U.value) && x && (E = z ? j(x) < j(U.value) : ce ? x < U.value : $ < new Date(U.value));
343
- }
344
- if ((V || E) && (le(!!V, S.message, U.message, ue.max, ue.min), !s))
345
- return L(T[O].message), T;
346
- }
347
- if ((p || N) && !ne && (Q(x) || n && Array.isArray(x))) {
348
- const V = ve(p), E = ve(N), S = !G(V.value) && x.length > +V.value, U = !G(E.value) && x.length < +E.value;
349
- if ((S || U) && (le(S, V.message, E.message), !s))
350
- return L(T[O].message), T;
351
- }
352
- if (m && !ne && Q(x)) {
353
- const { value: V, message: E } = ve(m);
354
- if (We(V) && !x.match(V) && (T[O] = {
355
- type: ue.pattern,
356
- message: E,
357
- ref: l,
358
- ...B(ue.pattern, E)
359
- }, !s))
360
- return L(E), T;
361
- }
362
- if (K) {
363
- if (re(K)) {
364
- const V = await K(x, r), E = Ft(V, ee);
365
- if (E && (T[O] = {
366
- ...E,
367
- ...B(ue.validate, E.message)
368
- }, !s))
369
- return L(E.message), T;
370
- } else if (I(K)) {
371
- let V = {};
372
- for (const E in K) {
373
- if (!Y(V) && !s)
374
- break;
375
- const S = Ft(await K[E](x, r), ee, E);
376
- S && (V = {
377
- ...S,
378
- ...B(E, S.message)
379
- }, L(S.message), s && (T[O] = V));
380
- }
381
- if (!Y(V) && (T[O] = {
382
- ref: ee,
383
- ...V
384
- }, !s))
385
- return T;
386
- }
387
- }
388
- return L(!0), T;
389
- };
390
- const lr = {
391
- mode: se.onSubmit,
392
- reValidateMode: se.onChange,
393
- shouldFocusError: !0
394
- };
395
- function cr(e = {}) {
396
- let t = {
397
- ...lr,
398
- ...e
399
- }, r = {
400
- submitCount: 0,
401
- isDirty: !1,
402
- isReady: !1,
403
- isLoading: re(t.defaultValues),
404
- isValidating: !1,
405
- isSubmitted: !1,
406
- isSubmitting: !1,
407
- isSubmitSuccessful: !1,
408
- isValid: !1,
409
- touchedFields: {},
410
- dirtyFields: {},
411
- validatingFields: {},
412
- errors: t.errors || {},
413
- disabled: t.disabled || !1
414
- }, s = {}, i = I(t.defaultValues) || I(t.values) ? k(t.defaultValues || t.values) || {} : {}, n = t.shouldUnregister ? {} : k(i), l = {
415
- action: !1,
416
- mount: !1,
417
- watch: !1,
418
- keepIsValid: !1
419
- }, d = {
420
- mount: /* @__PURE__ */ new Set(),
421
- disabled: /* @__PURE__ */ new Set(),
422
- unMount: /* @__PURE__ */ new Set(),
423
- array: /* @__PURE__ */ new Set(),
424
- watch: /* @__PURE__ */ new Set()
425
- }, w, p = 0;
426
- const N = {
427
- isDirty: !1,
428
- dirtyFields: !1,
429
- validatingFields: !1,
430
- touchedFields: !1,
431
- isValidating: !1,
432
- isValid: !1,
433
- errors: !1
434
- }, D = {
435
- ...N
436
- };
437
- let v = {
438
- ...D
439
- };
440
- const m = {
441
- array: ft(),
442
- state: ft()
443
- }, K = t.criteriaMode === se.all, O = (a) => (u) => {
444
- clearTimeout(p), p = setTimeout(a, u);
445
- }, Z = async (a) => {
446
- if (!l.keepIsValid && !t.disabled && (D.isValid || v.isValid || a)) {
447
- let u;
448
- t.resolver ? (u = Y((await ae()).errors), H()) : u = await B(s, !0), u !== r.isValid && m.state.next({
449
- isValid: u
450
- });
451
- }
452
- }, H = (a, u) => {
453
- !t.disabled && (D.isValidating || D.validatingFields || v.isValidating || v.validatingFields) && ((a || Array.from(d.mount)).forEach((o) => {
454
- o && (u ? R(r.validatingFields, o, u) : M(r.validatingFields, o));
455
- }), m.state.next({
456
- validatingFields: r.validatingFields,
457
- isValidating: !Y(r.validatingFields)
458
- }));
459
- }, x = (a, u = [], o, f, h = !0, c = !0) => {
460
- if (f && o && !t.disabled) {
461
- if (l.action = !0, c && Array.isArray(g(s, a))) {
462
- const y = o(g(s, a), f.argA, f.argB);
463
- h && R(s, a, y);
464
- }
465
- if (c && Array.isArray(g(r.errors, a))) {
466
- const y = o(g(r.errors, a), f.argA, f.argB);
467
- h && R(r.errors, a, y), ur(r.errors, a);
468
- }
469
- if ((D.touchedFields || v.touchedFields) && c && Array.isArray(g(r.touchedFields, a))) {
470
- const y = o(g(r.touchedFields, a), f.argA, f.argB);
471
- h && R(r.touchedFields, a, y);
472
- }
473
- (D.dirtyFields || v.dirtyFields) && (r.dirtyFields = Fe(i, n)), m.state.next({
474
- name: a,
475
- isDirty: V(a, u),
476
- dirtyFields: r.dirtyFields,
477
- errors: r.errors,
478
- isValid: r.isValid
479
- });
480
- } else
481
- R(n, a, u);
482
- }, ee = (a, u) => {
483
- R(r.errors, a, u), m.state.next({
484
- errors: r.errors
485
- });
486
- }, L = (a) => {
487
- r.errors = a, m.state.next({
488
- errors: r.errors,
489
- isValid: !1
490
- });
491
- }, T = (a, u, o, f) => {
492
- const h = g(s, a);
493
- if (h) {
494
- const c = g(n, a, C(o) ? g(i, a) : o);
495
- C(c) || f && f.defaultChecked || u ? R(n, a, u ? c : gt(h._f)) : U(a, c), l.mount && !l.action && Z();
496
- }
497
- }, oe = (a, u, o, f, h) => {
498
- let c = !1, y = !1;
499
- const F = {
500
- name: a
501
- };
502
- if (!t.disabled) {
503
- if (!o || f) {
504
- (D.isDirty || v.isDirty) && (y = r.isDirty, r.isDirty = F.isDirty = V(), c = y !== F.isDirty);
505
- const b = de(g(i, a), u);
506
- y = !!g(r.dirtyFields, a), b ? M(r.dirtyFields, a) : R(r.dirtyFields, a, !0), F.dirtyFields = r.dirtyFields, c = c || (D.dirtyFields || v.dirtyFields) && y !== !b;
507
- }
508
- if (o) {
509
- const b = g(r.touchedFields, a);
510
- b || (R(r.touchedFields, a, o), F.touchedFields = r.touchedFields, c = c || (D.touchedFields || v.touchedFields) && b !== o);
511
- }
512
- c && h && m.state.next(F);
513
- }
514
- return c ? F : {};
515
- }, he = (a, u, o, f) => {
516
- const h = g(r.errors, a), c = (D.isValid || v.isValid) && ie(u) && r.isValid !== u;
517
- if (t.delayError && o ? (w = O(() => ee(a, o)), w(t.delayError)) : (clearTimeout(p), w = null, o ? R(r.errors, a, o) : M(r.errors, a)), (o ? !de(h, o) : h) || !Y(f) || c) {
518
- const y = {
519
- ...f,
520
- ...c && ie(u) ? { isValid: u } : {},
521
- errors: r.errors,
522
- name: a
523
- };
524
- r = {
525
- ...r,
526
- ...y
527
- }, m.state.next(y);
528
- }
529
- }, ae = async (a) => (H(a, !0), await t.resolver(n, t.context, tr(a || d.mount, s, t.criteriaMode, t.shouldUseNativeValidation))), ne = async (a) => {
530
- const { errors: u } = await ae(a);
531
- if (H(a), a)
532
- for (const o of a) {
533
- const f = g(u, o);
534
- f ? R(r.errors, o, f) : M(r.errors, o);
535
- }
536
- else
537
- r.errors = u;
538
- return u;
539
- }, B = async (a, u, o = {
540
- valid: !0
541
- }) => {
542
- for (const f in a) {
543
- const h = a[f];
544
- if (h) {
545
- const { _f: c, ...y } = h;
546
- if (c) {
547
- const F = d.array.has(c.name), b = h._f && rr(h._f);
548
- b && D.validatingFields && H([c.name], !0);
549
- const _ = await Vt(h, d.disabled, n, K, t.shouldUseNativeValidation && !u, F);
550
- if (b && D.validatingFields && H([c.name]), _[c.name] && (o.valid = !1, u || e.shouldUseNativeValidation))
551
- break;
552
- !u && (g(_, c.name) ? F ? or(r.errors, _, c.name) : R(r.errors, c.name, _[c.name]) : M(r.errors, c.name));
553
- }
554
- !Y(y) && await B(y, u, o);
555
- }
556
- }
557
- return o.valid;
558
- }, le = () => {
559
- for (const a of d.unMount) {
560
- const u = g(s, a);
561
- u && (u._f.refs ? u._f.refs.every((o) => !Qe(o)) : !Qe(u._f.ref)) && xe(a);
562
- }
563
- d.unMount = /* @__PURE__ */ new Set();
564
- }, V = (a, u) => !t.disabled && (a && u && R(n, a, u), !de(Me(), i)), E = (a, u, o) => Jt(a, d, {
565
- ...l.mount ? n : C(u) ? i : Q(a) ? { [a]: u } : u
566
- }, o, u), S = (a) => st(g(l.mount ? n : i, a, t.shouldUnregister ? g(i, a, []) : [])), U = (a, u, o = {}) => {
567
- const f = g(s, a);
568
- let h = u;
569
- if (f) {
570
- const c = f._f;
571
- c && (!c.disabled && R(n, a, Tt(u, c)), h = je(c.ref) && G(u) ? "" : u, Nt(c.ref) ? [...c.ref.options].forEach((y) => y.selected = h.includes(y.value)) : c.refs ? Le(c.ref) ? c.refs.forEach((y) => {
572
- (!y.defaultChecked || !y.disabled) && (Array.isArray(h) ? y.checked = !!h.find((F) => F === y.value) : y.checked = h === y.value || !!h);
573
- }) : c.refs.forEach((y) => y.checked = y.value === h) : at(c.ref) ? c.ref.value = "" : (c.ref.value = h, c.ref.type || m.state.next({
574
- name: a,
575
- values: k(n)
576
- })));
577
- }
578
- (o.shouldDirty || o.shouldTouch) && oe(a, h, o.shouldTouch, o.shouldDirty, !0), o.shouldValidate && me(a);
579
- }, $ = (a, u, o) => {
580
- for (const f in u) {
581
- if (!u.hasOwnProperty(f))
582
- return;
583
- const h = u[f], c = a + "." + f, y = g(s, c);
584
- (d.array.has(a) || I(h) || y && !y._f) && !ge(h) ? $(c, h, o) : U(c, h, o);
585
- }
586
- }, j = (a, u, o = {}) => {
587
- const f = g(s, a), h = d.array.has(a), c = k(u);
588
- R(n, a, c), h ? (m.array.next({
589
- name: a,
590
- values: k(n)
591
- }), (D.isDirty || D.dirtyFields || v.isDirty || v.dirtyFields) && o.shouldDirty && m.state.next({
592
- name: a,
593
- dirtyFields: Fe(i, n),
594
- isDirty: V(a, c)
595
- })) : f && !f._f && !G(c) ? $(a, c, o) : U(a, c, o), wt(a, d) ? m.state.next({
596
- ...r,
597
- name: a,
598
- values: k(n)
599
- }) : m.state.next({
600
- name: l.mount ? a : void 0,
601
- values: k(n)
602
- });
603
- }, z = async (a) => {
604
- l.mount = !0;
605
- const u = a.target;
606
- let o = u.name, f = !0;
607
- const h = g(s, o), c = (b) => {
608
- f = Number.isNaN(b) || ge(b) && isNaN(b.getTime()) || de(b, g(n, o, b));
609
- }, y = pt(t.mode), F = pt(t.reValidateMode);
610
- if (h) {
611
- let b, _;
612
- const P = u.type ? gt(h._f) : $t(a), W = a.type === dt.BLUR || a.type === dt.FOCUS_OUT, q = !sr(h._f) && !t.resolver && !g(r.errors, o) && !h._f.deps || nr(W, g(r.touchedFields, o), r.isSubmitted, F, y), J = wt(o, d, W);
613
- R(n, o, P), W ? (!u || !u.readOnly) && (h._f.onBlur && h._f.onBlur(a), w && w(0)) : h._f.onChange && h._f.onChange(a);
614
- const be = oe(o, P, W), ot = !Y(be) || J;
615
- if (!W && m.state.next({
616
- name: o,
617
- type: a.type,
618
- values: k(n)
619
- }), q)
620
- return (D.isValid || v.isValid) && (t.mode === "onBlur" ? W && Z() : W || Z()), ot && m.state.next({ name: o, ...J ? {} : be });
621
- if (!W && J && m.state.next({ ...r }), t.resolver) {
622
- const { errors: Xe } = await ae([o]);
623
- if (H([o]), c(P), f) {
624
- const Ut = vt(r.errors, s, o), lt = vt(Xe, s, Ut.name || o);
625
- b = lt.error, o = lt.name, _ = Y(Xe);
626
- }
627
- } else
628
- H([o], !0), b = (await Vt(h, d.disabled, n, K, t.shouldUseNativeValidation))[o], H([o]), c(P), f && (b ? _ = !1 : (D.isValid || v.isValid) && (_ = await B(s, !0)));
629
- f && (h._f.deps && (!Array.isArray(h._f.deps) || h._f.deps.length > 0) && me(h._f.deps), he(o, _, b, be));
630
- }
631
- }, ce = (a, u) => {
632
- if (g(r.errors, u) && a.focus)
633
- return a.focus(), 1;
634
- }, me = async (a, u = {}) => {
635
- let o, f;
636
- const h = Ce(a);
637
- if (t.resolver) {
638
- const c = await ne(C(a) ? a : h);
639
- o = Y(c), f = a ? !h.some((y) => g(c, y)) : o;
640
- } else a ? (f = (await Promise.all(h.map(async (c) => {
641
- const y = g(s, c);
642
- return await B(y && y._f ? { [c]: y } : y);
643
- }))).every(Boolean), !(!f && !r.isValid) && Z()) : f = o = await B(s);
644
- return m.state.next({
645
- ...!Q(a) || (D.isValid || v.isValid) && o !== r.isValid ? {} : { name: a },
646
- ...t.resolver || !a ? { isValid: o } : {},
647
- errors: r.errors
648
- }), u.shouldFocus && !f && Te(s, ce, a ? h : d.mount), f;
649
- }, Me = (a, u) => {
650
- let o = {
651
- ...l.mount ? n : i
652
- };
653
- return u && (o = Rt(u.dirtyFields ? r.dirtyFields : r.touchedFields, o)), C(a) ? o : Q(a) ? g(o, a) : a.map((f) => g(o, f));
654
- }, A = (a, u) => ({
655
- invalid: !!g((u || r).errors, a),
656
- isDirty: !!g((u || r).dirtyFields, a),
657
- error: g((u || r).errors, a),
658
- isValidating: !!g(r.validatingFields, a),
659
- isTouched: !!g((u || r).touchedFields, a)
660
- }), Ee = (a) => {
661
- a && Ce(a).forEach((u) => M(r.errors, u)), m.state.next({
662
- errors: a ? r.errors : {}
663
- });
664
- }, Ae = (a, u, o) => {
665
- const f = (g(s, a, { _f: {} })._f || {}).ref, h = g(r.errors, a) || {}, { ref: c, message: y, type: F, ...b } = h;
666
- R(r.errors, a, {
667
- ...b,
668
- ...u,
669
- ref: f
670
- }), m.state.next({
671
- name: a,
672
- errors: r.errors,
673
- isValid: !1
674
- }), o && o.shouldFocus && f && f.focus && f.focus();
675
- }, Ye = (a, u) => re(a) ? m.state.subscribe({
676
- next: (o) => "values" in o && a(E(void 0, u), o)
677
- }) : E(a, u, !0), Ie = (a) => m.state.subscribe({
678
- next: (u) => {
679
- ar(a.name, u.name, a.exact) && ir(u, a.formState || D, Ge, a.reRenderRoot) && a.callback({
680
- values: { ...n },
681
- ...r,
682
- ...u,
683
- defaultValues: i
684
- });
685
- }
686
- }).unsubscribe, Ke = (a) => (l.mount = !0, v = {
687
- ...v,
688
- ...a.formState
689
- }, Ie({
690
- ...a,
691
- formState: {
692
- ...N,
693
- ...a.formState
694
- }
695
- })), xe = (a, u = {}) => {
696
- for (const o of a ? Ce(a) : d.mount)
697
- d.mount.delete(o), d.array.delete(o), u.keepValue || (M(s, o), M(n, o)), !u.keepError && M(r.errors, o), !u.keepDirty && M(r.dirtyFields, o), !u.keepTouched && M(r.touchedFields, o), !u.keepIsValidating && M(r.validatingFields, o), !t.shouldUnregister && !u.keepDefaultValue && M(i, o);
698
- m.state.next({
699
- values: k(n)
700
- }), m.state.next({
701
- ...r,
702
- ...u.keepDirty ? { isDirty: V() } : {}
703
- }), !u.keepIsValid && Z();
704
- }, ke = ({ disabled: a, name: u }) => {
705
- (ie(a) && l.mount || a || d.disabled.has(u)) && (a ? d.disabled.add(u) : d.disabled.delete(u));
706
- }, _e = (a, u = {}) => {
707
- let o = g(s, a);
708
- const f = ie(u.disabled) || ie(t.disabled);
709
- return R(s, a, {
710
- ...o || {},
711
- _f: {
712
- ...o && o._f ? o._f : { ref: { name: a } },
713
- name: a,
714
- mount: !0,
715
- ...u
716
- }
717
- }), d.mount.add(a), o ? ke({
718
- disabled: ie(u.disabled) ? u.disabled : t.disabled,
719
- name: a
720
- }) : T(a, !0, u.value), {
721
- ...f ? { disabled: u.disabled || t.disabled } : {},
722
- ...t.progressive ? {
723
- required: !!u.required,
724
- min: Oe(u.min),
725
- max: Oe(u.max),
726
- minLength: Oe(u.minLength),
727
- maxLength: Oe(u.maxLength),
728
- pattern: Oe(u.pattern)
729
- } : {},
730
- name: a,
731
- onChange: z,
732
- onBlur: z,
733
- ref: (h) => {
734
- if (h) {
735
- _e(a, u), o = g(s, a);
736
- const c = C(h.value) && h.querySelectorAll && h.querySelectorAll("input,select,textarea")[0] || h, y = Xt(c), F = o._f.refs || [];
737
- if (y ? F.find((b) => b === c) : c === o._f.ref)
738
- return;
739
- R(s, a, {
740
- _f: {
741
- ...o._f,
742
- ...y ? {
743
- refs: [
744
- ...F.filter(Qe),
745
- c,
746
- ...Array.isArray(g(i, a)) ? [{}] : []
747
- ],
748
- ref: { type: c.type, name: a }
749
- } : { ref: c }
750
- }
751
- }), T(a, !1, void 0, c);
752
- } else
753
- o = g(s, a, {}), o._f && (o._f.mount = !1), (t.shouldUnregister || u.shouldUnregister) && !(Wt(d.array, a) && l.action) && d.unMount.add(a);
754
- }
755
- };
756
- }, De = () => t.shouldFocusError && Te(s, ce, d.mount), ze = (a) => {
757
- ie(a) && (m.state.next({ disabled: a }), Te(s, (u, o) => {
758
- const f = g(s, o);
759
- f && (u.disabled = f._f.disabled || a, Array.isArray(f._f.refs) && f._f.refs.forEach((h) => {
760
- h.disabled = f._f.disabled || a;
761
- }));
762
- }, 0, !1));
763
- }, Ue = (a, u) => async (o) => {
764
- let f;
765
- o && (o.preventDefault && o.preventDefault(), o.persist && o.persist());
766
- let h = k(n);
767
- if (m.state.next({
768
- isSubmitting: !0
769
- }), t.resolver) {
770
- const { errors: c, values: y } = await ae();
771
- H(), r.errors = c, h = k(y);
772
- } else
773
- await B(s);
774
- if (d.disabled.size)
775
- for (const c of d.disabled)
776
- M(h, c);
777
- if (M(r.errors, "root"), Y(r.errors)) {
778
- m.state.next({
779
- errors: {}
780
- });
781
- try {
782
- await a(h, o);
783
- } catch (c) {
784
- f = c;
785
- }
786
- } else
787
- u && await u({ ...r.errors }, o), De(), setTimeout(De);
788
- if (m.state.next({
789
- isSubmitted: !0,
790
- isSubmitting: !1,
791
- isSubmitSuccessful: Y(r.errors) && !f,
792
- submitCount: r.submitCount + 1,
793
- errors: r.errors
794
- }), f)
795
- throw f;
796
- }, Be = (a, u = {}) => {
797
- g(s, a) && (C(u.defaultValue) ? j(a, k(g(i, a))) : (j(a, u.defaultValue), R(i, a, k(u.defaultValue))), u.keepTouched || M(r.touchedFields, a), u.keepDirty || (M(r.dirtyFields, a), r.isDirty = u.defaultValue ? V(a, k(g(i, a))) : V()), u.keepError || (M(r.errors, a), D.isValid && Z()), m.state.next({ ...r }));
798
- }, Pe = (a, u = {}) => {
799
- const o = a ? k(a) : i, f = k(o), h = Y(a), c = h ? i : f;
800
- if (u.keepDefaultValues || (i = o), !u.keepValues) {
801
- if (u.keepDirtyValues) {
802
- const y = /* @__PURE__ */ new Set([
803
- ...d.mount,
804
- ...Object.keys(Fe(i, n))
805
- ]);
806
- for (const F of Array.from(y)) {
807
- const b = g(r.dirtyFields, F), _ = g(n, F), P = g(c, F);
808
- b && !C(_) ? R(c, F, _) : !b && !C(P) && j(F, P);
809
- }
810
- } else {
811
- if (rt && C(a))
812
- for (const y of d.mount) {
813
- const F = g(s, y);
814
- if (F && F._f) {
815
- const b = Array.isArray(F._f.refs) ? F._f.refs[0] : F._f.ref;
816
- if (je(b)) {
817
- const _ = b.closest("form");
818
- if (_) {
819
- _.reset();
820
- break;
821
- }
822
- }
823
- }
824
- }
825
- if (u.keepFieldsRef)
826
- for (const y of d.mount)
827
- j(y, g(c, y));
828
- else
829
- s = {};
830
- }
831
- n = t.shouldUnregister ? u.keepDefaultValues ? k(i) : {} : k(c), m.array.next({
832
- values: { ...c }
833
- }), m.state.next({
834
- values: { ...c }
835
- });
836
- }
837
- d = {
838
- mount: u.keepDirtyValues ? d.mount : /* @__PURE__ */ new Set(),
839
- unMount: /* @__PURE__ */ new Set(),
840
- array: /* @__PURE__ */ new Set(),
841
- disabled: /* @__PURE__ */ new Set(),
842
- watch: /* @__PURE__ */ new Set(),
843
- watchAll: !1,
844
- focus: ""
845
- }, l.mount = !D.isValid || !!u.keepIsValid || !!u.keepDirtyValues || !t.shouldUnregister && !Y(c), l.watch = !!t.shouldUnregister, l.keepIsValid = !!u.keepIsValid, l.action = !1, u.keepErrors || (r.errors = {}), m.state.next({
846
- submitCount: u.keepSubmitCount ? r.submitCount : 0,
847
- isDirty: h ? !1 : u.keepDirty ? r.isDirty : !!(u.keepDefaultValues && !de(a, i)),
848
- isSubmitted: u.keepIsSubmitted ? r.isSubmitted : !1,
849
- dirtyFields: h ? {} : u.keepDirtyValues ? u.keepDefaultValues && n ? Fe(i, n) : r.dirtyFields : u.keepDefaultValues && a ? Fe(i, a) : u.keepDirty ? r.dirtyFields : {},
850
- touchedFields: u.keepTouched ? r.touchedFields : {},
851
- errors: u.keepErrors ? r.errors : {},
852
- isSubmitSuccessful: u.keepIsSubmitSuccessful ? r.isSubmitSuccessful : !1,
853
- isSubmitting: !1,
854
- defaultValues: i
855
- });
856
- }, Se = (a, u) => Pe(re(a) ? a(n) : a, { ...t.resetOptions, ...u }), Je = (a, u = {}) => {
857
- const o = g(s, a), f = o && o._f;
858
- if (f) {
859
- const h = f.refs ? f.refs[0] : f.ref;
860
- h.focus && setTimeout(() => {
861
- h.focus(), u.shouldSelect && re(h.select) && h.select();
862
- });
863
- }
864
- }, Ge = (a) => {
865
- r = {
866
- ...r,
867
- ...a
868
- };
869
- }, Re = {
870
- control: {
871
- register: _e,
872
- unregister: xe,
873
- getFieldState: A,
874
- handleSubmit: Ue,
875
- setError: Ae,
876
- _subscribe: Ie,
877
- _runSchema: ae,
878
- _updateIsValidating: H,
879
- _focusError: De,
880
- _getWatch: E,
881
- _getDirty: V,
882
- _setValid: Z,
883
- _setFieldArray: x,
884
- _setDisabledField: ke,
885
- _setErrors: L,
886
- _getFieldArray: S,
887
- _reset: Pe,
888
- _resetDefaultValues: () => re(t.defaultValues) && t.defaultValues().then((a) => {
889
- Se(a, t.resetOptions), m.state.next({
890
- isLoading: !1
891
- });
892
- }),
893
- _removeUnmounted: le,
894
- _disableForm: ze,
895
- _subjects: m,
896
- _proxyFormState: D,
897
- get _fields() {
898
- return s;
899
- },
900
- get _formValues() {
901
- return n;
902
- },
903
- get _state() {
904
- return l;
905
- },
906
- set _state(a) {
907
- l = a;
908
- },
909
- get _defaultValues() {
910
- return i;
911
- },
912
- get _names() {
913
- return d;
914
- },
915
- set _names(a) {
916
- d = a;
917
- },
918
- get _formState() {
919
- return r;
920
- },
921
- get _options() {
922
- return t;
923
- },
924
- set _options(a) {
925
- t = {
926
- ...t,
927
- ...a
928
- };
929
- }
930
- },
931
- subscribe: Ke,
932
- trigger: me,
933
- register: _e,
934
- handleSubmit: Ue,
935
- watch: Ye,
936
- setValue: j,
937
- getValues: Me,
938
- reset: Se,
939
- resetField: Be,
940
- clearErrors: Ee,
941
- unregister: xe,
942
- setError: Ae,
943
- setFocus: Je,
944
- getFieldState: A
945
- };
946
- return {
947
- ...Re,
948
- formControl: Re
949
- };
950
- }
951
- function dr(e = {}) {
952
- const t = X.useRef(void 0), r = X.useRef(void 0), [s, i] = X.useState({
953
- isDirty: !1,
954
- isValidating: !1,
955
- isLoading: re(e.defaultValues),
956
- isSubmitted: !1,
957
- isSubmitting: !1,
958
- isSubmitSuccessful: !1,
959
- isValid: !1,
960
- submitCount: 0,
961
- dirtyFields: {},
962
- touchedFields: {},
963
- validatingFields: {},
964
- errors: e.errors || {},
965
- disabled: e.disabled || !1,
966
- isReady: !1,
967
- defaultValues: re(e.defaultValues) ? void 0 : e.defaultValues
968
- });
969
- if (!t.current)
970
- if (e.formControl)
971
- t.current = {
972
- ...e.formControl,
973
- formState: s
974
- }, e.defaultValues && !re(e.defaultValues) && e.formControl.reset(e.defaultValues, e.resetOptions);
975
- else {
976
- const { formControl: l, ...d } = cr(e);
977
- t.current = {
978
- ...d,
979
- formState: s
980
- };
981
- }
982
- const n = t.current.control;
983
- return n._options = e, zt(() => {
984
- const l = n._subscribe({
985
- formState: n._proxyFormState,
986
- callback: () => i({ ...n._formState }),
987
- reRenderRoot: !0
988
- });
989
- return i((d) => ({
990
- ...d,
991
- isReady: !0
992
- })), n._formState.isReady = !0, l;
993
- }, [n]), X.useEffect(() => n._disableForm(e.disabled), [n, e.disabled]), X.useEffect(() => {
994
- e.mode && (n._options.mode = e.mode), e.reValidateMode && (n._options.reValidateMode = e.reValidateMode);
995
- }, [n, e.mode, e.reValidateMode]), X.useEffect(() => {
996
- e.errors && (n._setErrors(e.errors), n._focusError());
997
- }, [n, e.errors]), X.useEffect(() => {
998
- e.shouldUnregister && n._subjects.state.next({
999
- values: n._getWatch()
1000
- });
1001
- }, [n, e.shouldUnregister]), X.useEffect(() => {
1002
- if (n._proxyFormState.isDirty) {
1003
- const l = n._getDirty();
1004
- l !== s.isDirty && n._subjects.state.next({
1005
- isDirty: l
1006
- });
1007
- }
1008
- }, [n, s.isDirty]), X.useEffect(() => {
1009
- var l;
1010
- e.values && !de(e.values, r.current) ? (n._reset(e.values, {
1011
- keepFieldsRef: !0,
1012
- ...n._options.resetOptions
1013
- }), !((l = n._options.resetOptions) === null || l === void 0) && l.keepIsValid || n._setValid(), r.current = e.values, i((d) => ({ ...d }))) : n._resetDefaultValues();
1014
- }, [n, e.values]), X.useEffect(() => {
1015
- n._state.mount || (n._setValid(), n._state.mount = !0), n._state.watch && (n._state.watch = !1, n._subjects.state.next({ ...n._formState })), n._removeUnmounted();
1016
- }), t.current.formState = Kt(s, n), t.current;
1017
- }
1018
- function fr() {
1019
- const e = /* @__PURE__ */ new Date();
1020
- return {
1021
- NOW: e,
1022
- TODAY: new Date(e.getFullYear(), e.getMonth(), e.getDate()),
12
+ NOW: t,
13
+ TODAY: new Date(t.getFullYear(), t.getMonth(), t.getDate()),
1023
14
  CURRENT_USER: {
1024
15
  // These would typically come from auth context
1025
16
  EmpId: 1,
@@ -1031,211 +22,211 @@ function fr() {
1031
22
  CURRENT_USER_ID: 1
1032
23
  };
1033
24
  }
1034
- const hr = {
25
+ const je = {
1035
26
  // String functions
1036
- CONCAT: (...e) => e.map((t) => String(t || "")).join(""),
1037
- TRIM: (e) => String(e || "").trim(),
1038
- LENGTH: (e) => String(e || "").length,
1039
- UPPER: (e) => String(e || "").toUpperCase(),
1040
- LOWER: (e) => String(e || "").toLowerCase(),
1041
- SUBSTRING: (e, t, r) => {
1042
- const s = String(e || "");
1043
- return r !== void 0 ? s.substring(t, t + r) : s.substring(t);
27
+ CONCAT: (...t) => t.map((e) => String(e || "")).join(""),
28
+ TRIM: (t) => String(t || "").trim(),
29
+ LENGTH: (t) => String(t || "").length,
30
+ UPPER: (t) => String(t || "").toUpperCase(),
31
+ LOWER: (t) => String(t || "").toLowerCase(),
32
+ SUBSTRING: (t, e, r) => {
33
+ const s = String(t || "");
34
+ return r !== void 0 ? s.substring(e, e + r) : s.substring(e);
1044
35
  },
1045
- CONTAINS: (e, t) => String(e || "").includes(String(t || "")),
36
+ CONTAINS: (t, e) => String(t || "").includes(String(e || "")),
1046
37
  // Date functions
1047
- YEAR: (e) => new Date(e).getFullYear(),
1048
- MONTH: (e) => new Date(e).getMonth() + 1,
38
+ YEAR: (t) => new Date(t).getFullYear(),
39
+ MONTH: (t) => new Date(t).getMonth() + 1,
1049
40
  // 1-based
1050
- DAY: (e) => new Date(e).getDate(),
1051
- DATE_DIFF: (e, t) => {
1052
- const r = new Date(e), s = new Date(t), i = Math.abs(r.getTime() - s.getTime());
1053
- return Math.ceil(i / (1e3 * 60 * 60 * 24));
41
+ DAY: (t) => new Date(t).getDate(),
42
+ DATE_DIFF: (t, e) => {
43
+ const r = new Date(t), s = new Date(e), a = Math.abs(r.getTime() - s.getTime());
44
+ return Math.ceil(a / (1e3 * 60 * 60 * 24));
1054
45
  },
1055
- ADD_DAYS: (e, t) => {
1056
- const r = new Date(e);
1057
- return r.setDate(r.getDate() + t), r;
46
+ ADD_DAYS: (t, e) => {
47
+ const r = new Date(t);
48
+ return r.setDate(r.getDate() + e), r;
1058
49
  },
1059
- ADD_MONTHS: (e, t) => {
1060
- const r = new Date(e);
1061
- return r.setMonth(r.getMonth() + t), r;
50
+ ADD_MONTHS: (t, e) => {
51
+ const r = new Date(t);
52
+ return r.setMonth(r.getMonth() + e), r;
1062
53
  },
1063
54
  // Math functions
1064
- SUM: (...e) => e.reduce((t, r) => t + (Number(r) || 0), 0),
1065
- AVG: (...e) => {
1066
- const t = e.filter((r) => !isNaN(Number(r)));
1067
- return t.length > 0 ? t.reduce((r, s) => r + Number(s), 0) / t.length : 0;
55
+ SUM: (...t) => t.reduce((e, r) => e + (Number(r) || 0), 0),
56
+ AVG: (...t) => {
57
+ const e = t.filter((r) => !isNaN(Number(r)));
58
+ return e.length > 0 ? e.reduce((r, s) => r + Number(s), 0) / e.length : 0;
1068
59
  },
1069
- MIN: (...e) => Math.min(...e.map((t) => Number(t) || 0)),
1070
- MAX: (...e) => Math.max(...e.map((t) => Number(t) || 0)),
1071
- ROUND: (e) => Math.round(Number(e) || 0),
1072
- FLOOR: (e) => Math.floor(Number(e) || 0),
1073
- CEIL: (e) => Math.ceil(Number(e) || 0),
1074
- ABS: (e) => Math.abs(Number(e) || 0),
60
+ MIN: (...t) => Math.min(...t.map((e) => Number(e) || 0)),
61
+ MAX: (...t) => Math.max(...t.map((e) => Number(e) || 0)),
62
+ ROUND: (t) => Math.round(Number(t) || 0),
63
+ FLOOR: (t) => Math.floor(Number(t) || 0),
64
+ CEIL: (t) => Math.ceil(Number(t) || 0),
65
+ ABS: (t) => Math.abs(Number(t) || 0),
1075
66
  // Conditional functions
1076
- IF: (e, t, r) => e ? t : r,
67
+ IF: (t, e, r) => t ? e : r,
1077
68
  // Validation functions
1078
- IS_NULL: (e) => e == null,
1079
- IS_EMPTY: (e) => !e || String(e).trim() === "",
1080
- IS_NUMBER: (e) => !isNaN(Number(e)) && e !== "" && e !== null && e !== void 0,
1081
- IS_DATE: (e) => {
1082
- const t = new Date(e);
1083
- return !isNaN(t.getTime());
69
+ IS_NULL: (t) => t == null,
70
+ IS_EMPTY: (t) => !t || String(t).trim() === "",
71
+ IS_NUMBER: (t) => !isNaN(Number(t)) && t !== "" && t !== null && t !== void 0,
72
+ IS_DATE: (t) => {
73
+ const e = new Date(t);
74
+ return !isNaN(e.getTime());
1084
75
  },
1085
76
  // System functions
1086
77
  AUTO_NUMBER: () => Math.floor(Math.random() * 1e4) + 1e3,
1087
78
  // Mock implementation
1088
- UUID: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
1089
- const t = Math.random() * 16 | 0;
1090
- return (e == "x" ? t : t & 3 | 8).toString(16);
79
+ UUID: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (t) => {
80
+ const e = Math.random() * 16 | 0;
81
+ return (t == "x" ? e : e & 3 | 8).toString(16);
1091
82
  }),
1092
83
  // Array functions
1093
- ARRAY_LENGTH: (e) => Array.isArray(e) ? e.length : 0,
1094
- ARRAY_CONTAINS: (e, t) => Array.isArray(e) ? e.includes(t) : !1,
1095
- ARRAY_JOIN: (e, t = ",") => Array.isArray(e) ? e.join(t) : ""
84
+ ARRAY_LENGTH: (t) => Array.isArray(t) ? t.length : 0,
85
+ ARRAY_CONTAINS: (t, e) => Array.isArray(t) ? t.includes(e) : !1,
86
+ ARRAY_JOIN: (t, e = ",") => Array.isArray(t) ? t.join(e) : ""
1096
87
  };
1097
- function fe(e, t) {
88
+ function x(t, e) {
1098
89
  var r;
1099
- switch (e.Type) {
90
+ switch (t.Type) {
1100
91
  case "Literal":
1101
- return e.Value;
92
+ return t.Value;
1102
93
  case "SystemIdentifier":
1103
- if (e.Property) {
1104
- const p = t.systemValues[e.Name];
1105
- return Ze(p, e.Property.Name);
94
+ if (t.Property) {
95
+ const f = e.systemValues[t.Name];
96
+ return W(f, t.Property.Name);
1106
97
  }
1107
- return t.systemValues[e.Name];
98
+ return e.systemValues[t.Name];
1108
99
  case "Identifier":
1109
- if (e.Property) {
1110
- const p = Et(e, t);
1111
- return Ze(p, e.Property.Name);
100
+ if (t.Property) {
101
+ const f = ce(t, e);
102
+ return W(f, t.Property.Name);
1112
103
  }
1113
- return Et(e, t);
104
+ return ce(t, e);
1114
105
  case "MemberExpression":
1115
- if (!e.Arguments || e.Arguments.length === 0)
106
+ if (!t.Arguments || t.Arguments.length === 0)
1116
107
  throw new Error("MemberExpression requires Arguments array");
1117
- const s = fe(e.Arguments[0], t), i = (r = e.Arguments[0].Property) == null ? void 0 : r.Name;
1118
- return i ? Ze(s, i) : s;
108
+ const s = x(t.Arguments[0], e), a = (r = t.Arguments[0].Property) == null ? void 0 : r.Name;
109
+ return a ? W(s, a) : s;
1119
110
  case "BinaryExpression":
1120
- if (!e.Arguments || e.Arguments.length !== 2)
111
+ if (!t.Arguments || t.Arguments.length !== 2)
1121
112
  throw new Error("BinaryExpression requires exactly 2 arguments");
1122
- const n = fe(e.Arguments[0], t), l = fe(e.Arguments[1], t);
1123
- return mr(e.Operator, n, l);
113
+ const n = x(t.Arguments[0], e), o = x(t.Arguments[1], e);
114
+ return Pe(t.Operator, n, o);
1124
115
  case "LogicalExpression":
1125
- if (!e.Arguments || e.Arguments.length < 2)
116
+ if (!t.Arguments || t.Arguments.length < 2)
1126
117
  throw new Error("LogicalExpression requires at least 2 arguments");
1127
- return yr(e.Operator, e.Arguments, t);
118
+ return ke(t.Operator, t.Arguments, e);
1128
119
  case "CallExpression":
1129
- if (!e.Callee)
120
+ if (!t.Callee)
1130
121
  throw new Error("CallExpression requires Callee");
1131
- const d = hr[e.Callee];
1132
- if (!d)
1133
- throw new Error(`Unknown function: ${e.Callee}`);
1134
- const w = (e.Arguments || []).map(
1135
- (p) => fe(p, t)
122
+ const u = je[t.Callee];
123
+ if (!u)
124
+ throw new Error(`Unknown function: ${t.Callee}`);
125
+ const p = (t.Arguments || []).map(
126
+ (f) => x(f, e)
1136
127
  );
1137
- return d(...w);
128
+ return u(...p);
1138
129
  case "AssignmentExpression":
1139
- if (!e.Arguments || e.Arguments.length !== 1)
130
+ if (!t.Arguments || t.Arguments.length !== 1)
1140
131
  throw new Error("AssignmentExpression requires exactly 1 argument");
1141
- return fe(e.Arguments[0], t);
132
+ return x(t.Arguments[0], e);
1142
133
  default:
1143
- throw new Error(`Unknown expression type: ${e.Type}`);
134
+ throw new Error(`Unknown expression type: ${t.Type}`);
1144
135
  }
1145
136
  }
1146
- function Et(e, t) {
1147
- const { Name: r, Source: s } = e;
137
+ function ce(t, e) {
138
+ const { Name: r, Source: s } = t;
1148
139
  if (!r)
1149
140
  throw new Error("Identifier requires Name");
1150
141
  switch (s) {
1151
142
  case "Input":
1152
143
  default:
1153
- return t.formValues[r];
144
+ return e.formValues[r];
1154
145
  }
1155
146
  }
1156
- function Ze(e, t) {
1157
- if (!(!e || typeof e != "object"))
1158
- return e[t];
147
+ function W(t, e) {
148
+ if (!(!t || typeof t != "object"))
149
+ return t[e];
1159
150
  }
1160
- function mr(e, t, r) {
1161
- const s = (i) => i == null ? 0 : typeof i == "number" ? i : typeof i == "object" && i !== null && "value" in i ? Number(i.value) || 0 : Number(i) || 0;
1162
- switch (e) {
151
+ function Pe(t, e, r) {
152
+ const s = (a) => a == null ? 0 : typeof a == "number" ? a : typeof a == "object" && a !== null && "value" in a ? Number(a.value) || 0 : Number(a) || 0;
153
+ switch (t) {
1163
154
  case "==":
1164
- return t == r;
155
+ return e == r;
1165
156
  case "!=":
1166
- return t != r;
157
+ return e != r;
1167
158
  case ">":
1168
- return s(t) > s(r);
159
+ return s(e) > s(r);
1169
160
  case "<":
1170
- return s(t) < s(r);
161
+ return s(e) < s(r);
1171
162
  case ">=":
1172
- return s(t) >= s(r);
163
+ return s(e) >= s(r);
1173
164
  case "<=":
1174
- return s(t) <= s(r);
165
+ return s(e) <= s(r);
1175
166
  case "+":
1176
- return s(t) + s(r);
167
+ return s(e) + s(r);
1177
168
  case "-":
1178
- return s(t) - s(r);
169
+ return s(e) - s(r);
1179
170
  case "*":
1180
- return s(t) * s(r);
171
+ return s(e) * s(r);
1181
172
  case "/":
1182
- const i = s(r);
1183
- return i !== 0 ? s(t) / i : 0;
173
+ const a = s(r);
174
+ return a !== 0 ? s(e) / a : 0;
1184
175
  default:
1185
- throw new Error(`Unknown binary operator: ${e}`);
176
+ throw new Error(`Unknown binary operator: ${t}`);
1186
177
  }
1187
178
  }
1188
- function yr(e, t, r) {
1189
- switch (e) {
179
+ function ke(t, e, r) {
180
+ switch (t) {
1190
181
  case "AND":
1191
- return t.every((s) => !!fe(s, r));
182
+ return e.every((s) => !!x(s, r));
1192
183
  case "OR":
1193
- return t.some((s) => !!fe(s, r));
184
+ return e.some((s) => !!x(s, r));
1194
185
  default:
1195
- throw new Error(`Unknown logical operator: ${e}`);
186
+ throw new Error(`Unknown logical operator: ${t}`);
1196
187
  }
1197
188
  }
1198
- function Mt(e, t, r = {}) {
189
+ function pe(t, e, r = {}) {
1199
190
  const s = {
1200
- formValues: t,
1201
- systemValues: fr(),
191
+ formValues: e,
192
+ systemValues: Be(),
1202
193
  referenceData: r
1203
194
  };
1204
195
  try {
1205
- return fe(e, s);
1206
- } catch (i) {
1207
- return console.warn("Expression evaluation failed:", i), !1;
196
+ return x(t, s);
197
+ } catch (a) {
198
+ return console.warn("Expression evaluation failed:", a), !1;
1208
199
  }
1209
200
  }
1210
- function At(e, t, r = {}) {
201
+ function le(t, e, r = {}) {
1211
202
  const s = [];
1212
- for (const i of e)
203
+ for (const a of t)
1213
204
  try {
1214
- Mt(
1215
- i.Condition.ExpressionTree,
1216
- t,
205
+ pe(
206
+ a.Condition.ExpressionTree,
207
+ e,
1217
208
  r
1218
209
  ) || s.push({
1219
210
  isValid: !1,
1220
- message: i.Message,
1221
- fieldName: i.Id
211
+ message: a.Message,
212
+ fieldName: a.Id
1222
213
  });
1223
214
  } catch (n) {
1224
- console.warn(`Cross-field validation rule ${i.Id} failed:`, n);
215
+ console.warn(`Cross-field validation rule ${a.Id} failed:`, n);
1225
216
  }
1226
217
  return s;
1227
218
  }
1228
- function gr(e, t = {}, r = {}) {
219
+ function Ye(t, e = {}, r = {}) {
1229
220
  try {
1230
- return Mt(e, t, r);
221
+ return pe(t, e, r);
1231
222
  } catch (s) {
1232
223
  return console.warn("Default value calculation failed:", s), null;
1233
224
  }
1234
225
  }
1235
- function xt(e, t) {
1236
- var d, w, p;
1237
- const r = ((d = e.Expression) == null ? void 0 : d.toLowerCase()) || "", s = ((w = e.Name) == null ? void 0 : w.toLowerCase()) || "", i = ((p = e.Id) == null ? void 0 : p.toLowerCase()) || "", n = t.toLowerCase();
1238
- return s.includes("required") || i.includes("required") ? !0 : [
226
+ function de(t, e) {
227
+ var u, p, f;
228
+ const r = ((u = t.Expression) == null ? void 0 : u.toLowerCase()) || "", s = ((p = t.Name) == null ? void 0 : p.toLowerCase()) || "", a = ((f = t.Id) == null ? void 0 : f.toLowerCase()) || "", n = e.toLowerCase();
229
+ return s.includes("required") || a.includes("required") ? !0 : [
1239
230
  `${n} != null`,
1240
231
  `${n} != ''`,
1241
232
  `trim(${n}) != ''`,
@@ -1243,124 +234,124 @@ function xt(e, t) {
1243
234
  `${n}!=''`
1244
235
  ].some((N) => r.includes(N));
1245
236
  }
1246
- function pr(e) {
1247
- const t = { ...e };
1248
- t.Rules || (t.Rules = {
237
+ function ze(t) {
238
+ const e = { ...t };
239
+ e.Rules || (e.Rules = {
1249
240
  Validation: {},
1250
241
  Computation: {},
1251
242
  BusinessLogic: {}
1252
- }), t.Rules.Validation || (t.Rules.Validation = {}), t.Rules.Computation || (t.Rules.Computation = {}), t.Rules.BusinessLogic || (t.Rules.BusinessLogic = {});
1253
- const r = { ...t.Fields };
1254
- return Object.entries(r).forEach(([s, i]) => {
1255
- let n = i.Required || !1;
1256
- if (i.Validation && Array.isArray(i.Validation))
1257
- if (i.Validation.length > 0 && typeof i.Validation[0] == "object") {
1258
- const l = [];
1259
- i.Validation.forEach((d) => {
1260
- t.Rules.Validation[d.Id] = d, l.push(d.Id), xt(d, s) && (n = !0);
243
+ }), e.Rules.Validation || (e.Rules.Validation = {}), e.Rules.Computation || (e.Rules.Computation = {}), e.Rules.BusinessLogic || (e.Rules.BusinessLogic = {});
244
+ const r = { ...e.Fields };
245
+ return Object.entries(r).forEach(([s, a]) => {
246
+ let n = a.Required || !1;
247
+ if (a.Validation && Array.isArray(a.Validation))
248
+ if (a.Validation.length > 0 && typeof a.Validation[0] == "object") {
249
+ const o = [];
250
+ a.Validation.forEach((u) => {
251
+ e.Rules.Validation[u.Id] = u, o.push(u.Id), de(u, s) && (n = !0);
1261
252
  }), r[s] = {
1262
- ...i,
1263
- Validation: l,
253
+ ...a,
254
+ Validation: o,
1264
255
  Required: n
1265
256
  };
1266
257
  } else
1267
- i.Validation.forEach((d) => {
1268
- var p;
1269
- const w = (p = t.Rules.Validation) == null ? void 0 : p[d];
1270
- w && xt(w, s) && (n = !0);
1271
- }), n && !i.Required && (r[s] = {
1272
- ...i,
258
+ a.Validation.forEach((u) => {
259
+ var f;
260
+ const p = (f = e.Rules.Validation) == null ? void 0 : f[u];
261
+ p && de(p, s) && (n = !0);
262
+ }), n && !a.Required && (r[s] = {
263
+ ...a,
1273
264
  Required: !0
1274
265
  });
1275
- if (i.Formula) {
1276
- const l = `RULE_COMPUTE_${s.toUpperCase()}`;
1277
- t.Rules.Computation[l] = {
1278
- Id: l,
1279
- Name: i.Formula.Id || `Compute ${s}`,
1280
- Description: i.Formula.Description || `Computes value for ${s}`,
1281
- Expression: i.Formula.Expression,
1282
- ExpressionTree: i.Formula.ExpressionTree,
1283
- ResultType: i.Type
266
+ if (a.Formula) {
267
+ const o = `RULE_COMPUTE_${s.toUpperCase()}`;
268
+ e.Rules.Computation[o] = {
269
+ Id: o,
270
+ Name: a.Formula.Id || `Compute ${s}`,
271
+ Description: a.Formula.Description || `Computes value for ${s}`,
272
+ Expression: a.Formula.Expression,
273
+ ExpressionTree: a.Formula.ExpressionTree,
274
+ ResultType: a.Type
1284
275
  };
1285
276
  }
1286
- }), t.Fields = r, t;
277
+ }), e.Fields = r, e;
1287
278
  }
1288
- function br(e) {
1289
- var r, s, i;
1290
- const t = {
279
+ function Ke(t) {
280
+ var r, s, a;
281
+ const e = {
1291
282
  validation: {},
1292
283
  computation: {},
1293
284
  businessLogic: {}
1294
285
  };
1295
- return (r = e.Rules) != null && r.Validation && (t.validation = { ...e.Rules.Validation }), (s = e.Rules) != null && s.Computation && (t.computation = { ...e.Rules.Computation }), (i = e.Rules) != null && i.BusinessLogic && (t.businessLogic = { ...e.Rules.BusinessLogic }), t;
286
+ return (r = t.Rules) != null && r.Validation && (e.validation = { ...t.Rules.Validation }), (s = t.Rules) != null && s.Computation && (e.computation = { ...t.Rules.Computation }), (a = t.Rules) != null && a.BusinessLogic && (e.businessLogic = { ...t.Rules.BusinessLogic }), e;
1296
287
  }
1297
- function wr(e) {
288
+ function Je(t) {
1298
289
  var s;
1299
- const t = {};
1300
- if (!((s = e.Rules) != null && s.Computation)) return t;
1301
- const r = Object.entries(e.Fields).filter(([i, n]) => n.Computed).map(([i]) => i);
1302
- return r.sort((i, n) => n.length - i.length), Object.entries(e.Rules.Computation).forEach(([i, n]) => {
1303
- const l = i.toUpperCase().replace(/[_-]/g, "");
1304
- for (const w of r) {
1305
- const p = w.toUpperCase().replace(/[_-]/g, "");
1306
- if (l.includes(p)) {
1307
- t[i] = w;
290
+ const e = {};
291
+ if (!((s = t.Rules) != null && s.Computation)) return e;
292
+ const r = Object.entries(t.Fields).filter(([a, n]) => n.Computed).map(([a]) => a);
293
+ return r.sort((a, n) => n.length - a.length), Object.entries(t.Rules.Computation).forEach(([a, n]) => {
294
+ const o = a.toUpperCase().replace(/[_-]/g, "");
295
+ for (const p of r) {
296
+ const f = p.toUpperCase().replace(/[_-]/g, "");
297
+ if (o.includes(f)) {
298
+ e[a] = p;
1308
299
  return;
1309
300
  }
1310
301
  }
1311
- const d = `${n.Name || ""} ${n.Description || ""}`.toLowerCase();
1312
- for (const w of r)
1313
- if (d.includes(w.toLowerCase())) {
1314
- t[i] = w;
302
+ const u = `${n.Name || ""} ${n.Description || ""}`.toLowerCase();
303
+ for (const p of r)
304
+ if (u.includes(p.toLowerCase())) {
305
+ e[a] = p;
1315
306
  return;
1316
307
  }
1317
- }), t;
308
+ }), e;
1318
309
  }
1319
- function vr(e, t) {
310
+ function We(t, e) {
1320
311
  const r = {};
1321
- Object.keys(e.Fields).forEach((i) => {
1322
- r[i] = {
312
+ Object.keys(t.Fields).forEach((a) => {
313
+ r[a] = {
1323
314
  validation: [],
1324
315
  computation: [],
1325
316
  businessLogic: []
1326
317
  };
1327
- }), Object.entries(e.Fields).forEach(([i, n]) => {
1328
- n.Validation && Array.isArray(n.Validation) && n.Validation.forEach((d) => {
1329
- t.validation[d] ? r[i].validation.push(d) : t.computation[d] ? r[i].computation.push(d) : t.businessLogic[d] && r[i].businessLogic.push(d);
1330
- }), n.Formula && Object.entries(t.computation).forEach(([l, d]) => {
1331
- var w;
1332
- d.Expression === ((w = n.Formula) == null ? void 0 : w.Expression) && (r[i].computation.includes(l) || r[i].computation.push(l));
318
+ }), Object.entries(t.Fields).forEach(([a, n]) => {
319
+ n.Validation && Array.isArray(n.Validation) && n.Validation.forEach((u) => {
320
+ e.validation[u] ? r[a].validation.push(u) : e.computation[u] ? r[a].computation.push(u) : e.businessLogic[u] && r[a].businessLogic.push(u);
321
+ }), n.Formula && Object.entries(e.computation).forEach(([o, u]) => {
322
+ var p;
323
+ u.Expression === ((p = n.Formula) == null ? void 0 : p.Expression) && (r[a].computation.includes(o) || r[a].computation.push(o));
1333
324
  });
1334
325
  });
1335
- const s = wr(e);
1336
- return Object.entries(s).forEach(([i, n]) => {
1337
- r[n] && !r[n].computation.includes(i) && r[n].computation.push(i);
326
+ const s = Je(t);
327
+ return Object.entries(s).forEach(([a, n]) => {
328
+ r[n] && !r[n].computation.includes(a) && r[n].computation.push(a);
1338
329
  }), r;
1339
330
  }
1340
- function Fr(e, t) {
331
+ function He(t, e) {
1341
332
  const r = {}, s = {
1342
333
  editable: !0,
1343
334
  readable: !0,
1344
335
  hidden: !1
1345
336
  };
1346
- return Object.keys(e.Fields).forEach((i) => {
1347
- var w, p, N, D, v, m;
1348
- if (!t || !((w = e.RolePermission) != null && w[t])) {
1349
- r[i] = s;
337
+ return Object.keys(t.Fields).forEach((a) => {
338
+ var p, f, N, L, b, i;
339
+ if (!e || !((p = t.RolePermission) != null && p[e])) {
340
+ r[a] = s;
1350
341
  return;
1351
342
  }
1352
- const n = e.RolePermission[t], l = ((p = n.Editable) == null ? void 0 : p.includes(i)) || ((N = n.Editable) == null ? void 0 : N.includes("*")) || !1, d = ((D = n.ReadOnly) == null ? void 0 : D.includes(i)) || ((v = n.ReadOnly) == null ? void 0 : v.includes("*")) || l;
1353
- r[i] = {
1354
- editable: l && !((m = n.ReadOnly) != null && m.includes(i)),
1355
- readable: d,
1356
- hidden: !d
343
+ const n = t.RolePermission[e], o = ((f = n.Editable) == null ? void 0 : f.includes(a)) || ((N = n.Editable) == null ? void 0 : N.includes("*")) || !1, u = ((L = n.ReadOnly) == null ? void 0 : L.includes(a)) || ((b = n.ReadOnly) == null ? void 0 : b.includes("*")) || o;
344
+ r[a] = {
345
+ editable: o && !((i = n.ReadOnly) != null && i.includes(a)),
346
+ readable: u,
347
+ hidden: !u
1357
348
  };
1358
349
  }), r;
1359
350
  }
1360
- function Vr(e, t) {
1361
- switch (e) {
351
+ function Ge(t, e) {
352
+ switch (t) {
1362
353
  case "String":
1363
- return t.toLowerCase().includes("email") ? "email" : t.toLowerCase().includes("password") ? "password" : "text";
354
+ return e.toLowerCase().includes("email") ? "email" : e.toLowerCase().includes("password") ? "password" : "text";
1364
355
  case "Number":
1365
356
  return "number";
1366
357
  case "Boolean":
@@ -1378,15 +369,15 @@ function Vr(e, t) {
1378
369
  return "text";
1379
370
  }
1380
371
  }
1381
- function It(e) {
1382
- return e.replace(/([A-Z])/g, " $1").replace(/^./, (t) => t.toUpperCase()).replace(/_/g, " ").trim();
372
+ function he(t) {
373
+ return t.replace(/([A-Z])/g, " $1").replace(/^./, (e) => e.toUpperCase()).replace(/_/g, " ").trim();
1383
374
  }
1384
- function Er(e, t, r) {
375
+ function Xe(t, e, r) {
1385
376
  const s = {};
1386
- switch (t.Required && (s.required = {
377
+ switch (e.Required && (s.required = {
1387
378
  value: !0,
1388
- message: `${It(e)} is required`
1389
- }), t.Type) {
379
+ message: `${he(t)} is required`
380
+ }), e.Type) {
1390
381
  case "Number":
1391
382
  s.valueAsNumber = !0;
1392
383
  break;
@@ -1395,17 +386,17 @@ function Er(e, t, r) {
1395
386
  s.valueAsDate = !0;
1396
387
  break;
1397
388
  }
1398
- return t.Validation && t.Validation.length > 0 && (s.validate = () => !0), s;
389
+ return e.Validation && e.Validation.length > 0 && (s.validate = () => !0), s;
1399
390
  }
1400
- function Ar(e) {
1401
- return e.Values ? e.Values.Mode === "Static" && e.Values.Items ? e.Values.Items.map((t) => ({
1402
- value: t.Value,
1403
- label: t.Label
1404
- })) : e.Values.Mode === "Dynamic" && e.Values.Reference ? [] : [] : [];
391
+ function Qe(t) {
392
+ return t.Values ? t.Values.Mode === "Static" && t.Values.Items ? t.Values.Items.map((e) => ({
393
+ value: e.Value,
394
+ label: e.Label
395
+ })) : t.Values.Mode === "Dynamic" && t.Values.Reference ? [] : [] : [];
1405
396
  }
1406
- function xr(e, t = {}) {
1407
- if (!e.DefaultValue)
1408
- switch (e.Type) {
397
+ function Ze(t, e = {}) {
398
+ if (!t.DefaultValue)
399
+ switch (t.Type) {
1409
400
  case "Boolean":
1410
401
  return !1;
1411
402
  case "Number":
@@ -1419,272 +410,272 @@ function xr(e, t = {}) {
1419
410
  default:
1420
411
  return;
1421
412
  }
1422
- return gr(
1423
- e.DefaultValue.ExpressionTree,
1424
- t
413
+ return Ye(
414
+ t.DefaultValue.ExpressionTree,
415
+ e
1425
416
  );
1426
417
  }
1427
- function _r(e, t, r, s = {}, i, n) {
1428
- const l = {
418
+ function et(t, e, r, s = {}, a, n) {
419
+ const o = {
1429
420
  editable: !0,
1430
421
  readable: !0,
1431
422
  hidden: !1
1432
- }, w = n || {
423
+ }, p = n || {
1433
424
  validation: [],
1434
425
  computation: [],
1435
426
  businessLogic: []
1436
- }, p = t.Computed || !!t.Formula || w.computation.length > 0, N = Er(e, t);
1437
- return p && (N.disabled = !0), {
1438
- name: e,
1439
- type: Vr(t.Type, e),
1440
- label: t.Name || It(e),
1441
- required: t.Required || !1,
1442
- computed: p,
1443
- defaultValue: xr(t, s),
1444
- options: Ar(t),
427
+ }, f = e.Computed || !!e.Formula || p.computation.length > 0, N = Xe(t, e);
428
+ return f && (N.disabled = !0), {
429
+ name: t,
430
+ type: Ge(e.Type, t),
431
+ label: e.Name || he(t),
432
+ required: e.Required || !1,
433
+ computed: f,
434
+ defaultValue: Ze(e, s),
435
+ options: Qe(e),
1445
436
  validation: N,
1446
- description: t.Description,
1447
- _bdoField: t,
1448
- permission: i || l,
1449
- rules: w
437
+ description: e.Description,
438
+ _bdoField: e,
439
+ permission: a || o,
440
+ rules: p
1450
441
  };
1451
442
  }
1452
- function Dr(e, t = {}, r) {
1453
- let s = e;
1454
- s = pr(s);
1455
- const i = {}, n = [], l = [], d = [], w = [], p = br(s), N = vr(s, p), D = Fr(s, r);
1456
- for (const [v, m] of Object.entries(s.Fields)) {
1457
- if (v.startsWith("_") && !["_id"].includes(v))
443
+ function tt(t, e = {}, r) {
444
+ let s = t;
445
+ s = ze(s);
446
+ const a = {}, n = [], o = [], u = [], p = [], f = Ke(s), N = We(s, f), L = He(s, r);
447
+ for (const [b, i] of Object.entries(s.Fields)) {
448
+ if (b.startsWith("_") && !["_id"].includes(b))
1458
449
  continue;
1459
- const K = D[v];
1460
- if (K.hidden)
450
+ const q = L[b];
451
+ if (q.hidden)
1461
452
  continue;
1462
- const O = _r(
1463
- v,
1464
- m,
453
+ const C = et(
454
+ b,
455
+ i,
1465
456
  s.Fields,
1466
- t,
1467
- K,
1468
- N[v] || {
457
+ e,
458
+ q,
459
+ N[b] || {
1469
460
  validation: [],
1470
461
  computation: [],
1471
462
  businessLogic: []
1472
463
  }
1473
464
  );
1474
- i[v] = O, n.push(v), O.computed && l.push(v), O.required && d.push(v);
465
+ a[b] = C, n.push(b), C.computed && o.push(b), C.required && u.push(b);
1475
466
  }
1476
467
  return {
1477
- fields: i,
468
+ fields: a,
1478
469
  fieldOrder: n,
1479
- computedFields: l,
1480
- requiredFields: d,
1481
- crossFieldValidation: w,
1482
- rules: p,
470
+ computedFields: o,
471
+ requiredFields: u,
472
+ crossFieldValidation: p,
473
+ rules: f,
1483
474
  fieldRules: N,
1484
475
  rolePermissions: s.RolePermission
1485
476
  };
1486
477
  }
1487
- function Sr(e) {
478
+ function rt(t) {
1488
479
  var r;
1489
- if (e.type !== "reference" || !((r = e._bdoField.Values) != null && r.Reference))
480
+ if (t.type !== "reference" || !((r = t._bdoField.Values) != null && r.Reference))
1490
481
  return null;
1491
- const t = e._bdoField.Values.Reference;
482
+ const e = t._bdoField.Values.Reference;
1492
483
  return {
1493
- businessObject: t.BusinessObject,
1494
- fields: t.Fields || ["_id"],
484
+ businessObject: e.BusinessObject,
485
+ fields: e.Fields || ["_id"],
1495
486
  // Default to ID field
1496
- filters: t.Filters,
1497
- sort: t.Sort
487
+ filters: e.Filters,
488
+ sort: e.Sort
1498
489
  };
1499
490
  }
1500
- function Rr(e) {
1501
- const t = {};
1502
- for (const [r, s] of Object.entries(e.fields))
491
+ function st(t) {
492
+ const e = {};
493
+ for (const [r, s] of Object.entries(t.fields))
1503
494
  if (s.type === "reference") {
1504
- const i = Sr(s);
1505
- i && (t[r] = i);
495
+ const a = rt(s);
496
+ a && (e[r] = a);
1506
497
  }
1507
- return t;
498
+ return e;
1508
499
  }
1509
- async function Nr(e) {
500
+ async function at(t) {
1510
501
  try {
1511
- const r = (await qt(e)).BOBlob;
502
+ const r = (await qe(t)).BOBlob;
1512
503
  if (!r || typeof r != "object" || !r.Fields)
1513
- throw new Error(`Invalid BDO schema response for ${e}`);
504
+ throw new Error(`Invalid BDO schema response for ${t}`);
1514
505
  return r;
1515
- } catch (t) {
1516
- throw console.error(`Schema fetch error for ${e}:`, t), new Error(
1517
- `Failed to load form schema: ${t instanceof Error ? t.message : "Unknown error"}`
506
+ } catch (e) {
507
+ throw console.error(`Schema fetch error for ${t}:`, e), new Error(
508
+ `Failed to load form schema: ${e instanceof Error ? e.message : "Unknown error"}`
1518
509
  );
1519
510
  }
1520
511
  }
1521
- async function Or(e, t = 3) {
512
+ async function nt(t, e = 3) {
1522
513
  let r;
1523
- for (let s = 1; s <= t; s++)
514
+ for (let s = 1; s <= e; s++)
1524
515
  try {
1525
- return await Nr(e);
1526
- } catch (i) {
1527
- if (r = i, s < t) {
516
+ return await at(t);
517
+ } catch (a) {
518
+ if (r = a, s < e) {
1528
519
  const n = Math.min(1e3 * Math.pow(2, s - 1), 5e3);
1529
- await new Promise((l) => setTimeout(l, n));
520
+ await new Promise((o) => setTimeout(o, n));
1530
521
  continue;
1531
522
  }
1532
523
  }
1533
524
  throw r;
1534
525
  }
1535
- async function Cr(e, t) {
526
+ async function it(t, e) {
1536
527
  try {
1537
- return await pe(e).get(t);
528
+ return await I(t).get(e);
1538
529
  } catch (r) {
1539
- throw console.error(`Record fetch error for ${e}/${t}:`, r), new Error(
530
+ throw console.error(`Record fetch error for ${t}/${e}:`, r), new Error(
1540
531
  `Failed to load record: ${r instanceof Error ? r.message : "Unknown error"}`
1541
532
  );
1542
533
  }
1543
534
  }
1544
- async function Tr(e, t, r, s) {
535
+ async function ot(t, e, r, s) {
1545
536
  try {
1546
- let i;
1547
- if (t === "create")
1548
- return i = await pe(e).create(r), {
537
+ let a;
538
+ if (e === "create")
539
+ return a = await I(t).create(r), {
1549
540
  success: !0,
1550
- data: i,
1551
- recordId: i._id || s
541
+ data: a,
542
+ recordId: a._id || s
1552
543
  };
1553
- if (t === "update") {
544
+ if (e === "update") {
1554
545
  if (!s)
1555
546
  throw new Error("Record ID is required for update operations");
1556
- return i = await pe(e).update(s, r), {
547
+ return a = await I(t).update(s, r), {
1557
548
  success: !0,
1558
- data: i,
1559
- recordId: i._id || s
549
+ data: a,
550
+ recordId: a._id || s
1560
551
  };
1561
552
  } else
1562
- throw new Error(`Unsupported operation: ${t}`);
1563
- } catch (i) {
1564
- return console.error("Form submission error:", i), {
553
+ throw new Error(`Unsupported operation: ${e}`);
554
+ } catch (a) {
555
+ return console.error("Form submission error:", a), {
1565
556
  success: !1,
1566
557
  error: new Error(
1567
- `Failed to ${t} record: ${i instanceof Error ? i.message : "Unknown error"}`
558
+ `Failed to ${e} record: ${a instanceof Error ? a.message : "Unknown error"}`
1568
559
  )
1569
560
  };
1570
561
  }
1571
562
  }
1572
- async function Lr(e, t = ["_id"], r, s) {
563
+ async function ut(t, e = ["_id"], r, s) {
1573
564
  try {
1574
- const i = {};
1575
- return r && (i.Filter = r), s && (i.Sort = s), t.length > 0 && (i.Field = t), (await pe(e).list(i)).Data || [];
1576
- } catch (i) {
1577
- return console.error(`Reference data fetch error for ${e}:`, i), [];
565
+ const a = {};
566
+ return r && (a.Filter = r), s && (a.Sort = s), e.length > 0 && (a.Field = e), (await I(t).list(a)).Data || [];
567
+ } catch (a) {
568
+ return console.error(`Reference data fetch error for ${t}:`, a), [];
1578
569
  }
1579
570
  }
1580
- async function Mr(e) {
1581
- const t = {}, r = Object.entries(e).map(
1582
- async ([i, n]) => {
571
+ async function ct(t) {
572
+ const e = {}, r = Object.entries(t).map(
573
+ async ([a, n]) => {
1583
574
  try {
1584
- const l = await Lr(
575
+ const o = await ut(
1585
576
  n.businessObject,
1586
577
  n.fields,
1587
578
  n.filters,
1588
579
  n.sort
1589
580
  );
1590
- return [i, l];
1591
- } catch (l) {
1592
- return console.warn(`Failed to fetch reference data for ${i}:`, l), [i, []];
581
+ return [a, o];
582
+ } catch (o) {
583
+ return console.warn(`Failed to fetch reference data for ${a}:`, o), [a, []];
1593
584
  }
1594
585
  }
1595
586
  );
1596
- return (await Promise.allSettled(r)).forEach((i) => {
1597
- if (i.status === "fulfilled") {
1598
- const [n, l] = i.value;
1599
- t[n] = Array.isArray(l) ? l : [];
587
+ return (await Promise.allSettled(r)).forEach((a) => {
588
+ if (a.status === "fulfilled") {
589
+ const [n, o] = a.value;
590
+ e[n] = Array.isArray(o) ? o : [];
1600
591
  }
1601
- }), t;
592
+ }), e;
1602
593
  }
1603
- function Ir(e, t, r = "create", s) {
1604
- const i = {};
1605
- return Object.keys(e).forEach((n) => {
1606
- const l = n, d = e[l];
1607
- if (!t.includes(n) && d !== void 0) {
594
+ function lt(t, e, r = "create", s) {
595
+ const a = {};
596
+ return Object.keys(t).forEach((n) => {
597
+ const o = n, u = t[o];
598
+ if (!e.includes(n) && u !== void 0) {
1608
599
  if (r === "create") {
1609
- i[l] = d;
600
+ a[o] = u;
1610
601
  return;
1611
602
  }
1612
603
  if (r === "update") {
1613
604
  if (!s) {
1614
- i[l] = d;
605
+ a[o] = u;
1615
606
  return;
1616
607
  }
1617
- const w = s[l];
1618
- JSON.stringify(d) !== JSON.stringify(w) && (i[l] = d);
608
+ const p = s[o];
609
+ JSON.stringify(u) !== JSON.stringify(p) && (a[o] = u);
1619
610
  }
1620
611
  }
1621
- }), i;
612
+ }), a;
1622
613
  }
1623
- function zr(e) {
1624
- var t, r, s, i;
1625
- return typeof e == "string" ? e : e != null && e.message ? e.message : (r = (t = e == null ? void 0 : e.response) == null ? void 0 : t.data) != null && r.message ? e.response.data.message : (i = (s = e == null ? void 0 : e.response) == null ? void 0 : s.data) != null && i.error ? e.response.data.error : "An unexpected error occurred";
614
+ function At(t) {
615
+ var e, r, s, a;
616
+ return typeof t == "string" ? t : t != null && t.message ? t.message : (r = (e = t == null ? void 0 : t.response) == null ? void 0 : e.data) != null && r.message ? t.response.data.message : (a = (s = t == null ? void 0 : t.response) == null ? void 0 : s.data) != null && a.error ? t.response.data.error : "An unexpected error occurred";
1626
617
  }
1627
- function Jr(e) {
1628
- var t, r;
1629
- return !navigator.onLine || (e == null ? void 0 : e.code) === "NETWORK_ERROR" || ((t = e == null ? void 0 : e.message) == null ? void 0 : t.toLowerCase().includes("network")) || ((r = e == null ? void 0 : e.message) == null ? void 0 : r.toLowerCase().includes("fetch"));
618
+ function Ct(t) {
619
+ var e, r;
620
+ return !navigator.onLine || (t == null ? void 0 : t.code) === "NETWORK_ERROR" || ((e = t == null ? void 0 : t.message) == null ? void 0 : e.toLowerCase().includes("network")) || ((r = t == null ? void 0 : t.message) == null ? void 0 : r.toLowerCase().includes("fetch"));
1630
621
  }
1631
- function Gr(e) {
1632
- var t, r, s;
1633
- return (e == null ? void 0 : e.status) === 400 || ((t = e == null ? void 0 : e.response) == null ? void 0 : t.status) === 400 || ((r = e == null ? void 0 : e.message) == null ? void 0 : r.toLowerCase().includes("validation")) || ((s = e == null ? void 0 : e.message) == null ? void 0 : s.toLowerCase().includes("invalid"));
622
+ function Dt(t) {
623
+ var e, r, s;
624
+ return (t == null ? void 0 : t.status) === 400 || ((e = t == null ? void 0 : t.response) == null ? void 0 : e.status) === 400 || ((r = t == null ? void 0 : t.message) == null ? void 0 : r.toLowerCase().includes("validation")) || ((s = t == null ? void 0 : t.message) == null ? void 0 : s.toLowerCase().includes("invalid"));
1634
625
  }
1635
- const Ve = /* @__PURE__ */ new Map();
1636
- function kr(e, t, r = 10) {
1637
- Ve.set(e, {
1638
- data: t,
626
+ const _ = /* @__PURE__ */ new Map();
627
+ function dt(t, e, r = 10) {
628
+ _.set(t, {
629
+ data: e,
1639
630
  timestamp: Date.now(),
1640
631
  ttl: r * 60 * 1e3
1641
632
  });
1642
633
  }
1643
- function Ur(e) {
1644
- const t = Ve.get(e);
1645
- return t ? Date.now() - t.timestamp > t.ttl ? (Ve.delete(e), null) : t.data : null;
634
+ function ft(t) {
635
+ const e = _.get(t);
636
+ return e ? Date.now() - e.timestamp > e.ttl ? (_.delete(t), null) : e.data : null;
1646
637
  }
1647
- function Xr(e) {
1648
- e ? Array.from(Ve.keys()).filter(
1649
- (r) => r.startsWith(e)
1650
- ).forEach((r) => Ve.delete(r)) : Ve.clear();
638
+ function Ot(t) {
639
+ t ? Array.from(_.keys()).filter(
640
+ (r) => r.startsWith(t)
641
+ ).forEach((r) => _.delete(r)) : _.clear();
1651
642
  }
1652
- async function Br(e) {
1653
- const t = `schema:${e}`, r = Ur(t);
643
+ async function mt(t) {
644
+ const e = `schema:${t}`, r = ft(e);
1654
645
  if (r)
1655
646
  return r;
1656
- const s = await Or(e);
1657
- return kr(t, s, 30), s;
647
+ const s = await nt(t);
648
+ return dt(e, s, 30), s;
1658
649
  }
1659
- class _t {
1660
- constructor(t = 1e3) {
1661
- we(this, "cache", /* @__PURE__ */ new Map());
1662
- we(this, "maxSize");
1663
- this.maxSize = t;
650
+ class fe {
651
+ constructor(e = 1e3) {
652
+ U(this, "cache", /* @__PURE__ */ new Map());
653
+ U(this, "maxSize");
654
+ this.maxSize = e;
1664
655
  }
1665
- get(t) {
1666
- const r = this.cache.get(t);
1667
- return r !== void 0 && (this.cache.delete(t), this.cache.set(t, r)), r;
656
+ get(e) {
657
+ const r = this.cache.get(e);
658
+ return r !== void 0 && (this.cache.delete(e), this.cache.set(e, r)), r;
1668
659
  }
1669
- set(t, r) {
1670
- if (this.cache.has(t))
1671
- this.cache.delete(t);
660
+ set(e, r) {
661
+ if (this.cache.has(e))
662
+ this.cache.delete(e);
1672
663
  else if (this.cache.size >= this.maxSize) {
1673
664
  const s = this.cache.keys().next().value;
1674
665
  this.cache.delete(s);
1675
666
  }
1676
- this.cache.set(t, r);
667
+ this.cache.set(e, r);
1677
668
  }
1678
669
  clear() {
1679
670
  this.cache.clear();
1680
671
  }
1681
672
  }
1682
- function Pr(e) {
1683
- const t = /* @__PURE__ */ new Set();
673
+ function pt(t) {
674
+ const e = /* @__PURE__ */ new Set();
1684
675
  function r(s) {
1685
676
  switch (s.Type) {
1686
677
  case "Identifier":
1687
- s.Name && !s.Name.startsWith("$") && t.add(s.Name);
678
+ s.Name && !s.Name.startsWith("$") && e.add(s.Name);
1688
679
  break;
1689
680
  case "MemberExpression":
1690
681
  s.Arguments && s.Arguments.forEach(r);
@@ -1696,159 +687,159 @@ function Pr(e) {
1696
687
  break;
1697
688
  }
1698
689
  }
1699
- return r(e), t;
690
+ return r(t), e;
1700
691
  }
1701
- class qr {
692
+ class ht {
1702
693
  constructor() {
1703
- we(this, "resultCache", new _t(500));
1704
- we(this, "dependencyCache", new _t(200));
1705
- we(this, "compiledExpressions", /* @__PURE__ */ new Map());
694
+ U(this, "resultCache", new fe(500));
695
+ U(this, "dependencyCache", new fe(200));
696
+ U(this, "compiledExpressions", /* @__PURE__ */ new Map());
1706
697
  }
1707
698
  /**
1708
699
  * Create cache key from expression and context
1709
700
  */
1710
- createCacheKey(t, r) {
1711
- const s = JSON.stringify(t), i = JSON.stringify(r);
1712
- return `${s}:${i}`;
701
+ createCacheKey(e, r) {
702
+ const s = JSON.stringify(e), a = JSON.stringify(r);
703
+ return `${s}:${a}`;
1713
704
  }
1714
705
  /**
1715
706
  * Get expression dependencies (cached)
1716
707
  */
1717
- getDependencies(t) {
1718
- const r = JSON.stringify(t);
708
+ getDependencies(e) {
709
+ const r = JSON.stringify(e);
1719
710
  let s = this.dependencyCache.get(r);
1720
- return s || (s = Pr(t), this.dependencyCache.set(r, s)), s;
711
+ return s || (s = pt(e), this.dependencyCache.set(r, s)), s;
1721
712
  }
1722
713
  /**
1723
714
  * Check if expression result is cached and context hasn't changed
1724
715
  */
1725
- getCachedResult(t, r, s) {
716
+ getCachedResult(e, r, s) {
1726
717
  if (!s) return;
1727
- const i = this.getDependencies(t);
1728
- for (const l of i)
1729
- if (r[l] !== s[l])
718
+ const a = this.getDependencies(e);
719
+ for (const o of a)
720
+ if (r[o] !== s[o])
1730
721
  return;
1731
- const n = this.createCacheKey(t, r);
722
+ const n = this.createCacheKey(e, r);
1732
723
  return this.resultCache.get(n);
1733
724
  }
1734
725
  /**
1735
726
  * Evaluate expression with caching
1736
727
  */
1737
- evaluate(t, r, s) {
1738
- const i = this.getCachedResult(t, r, s);
1739
- if (i !== void 0)
1740
- return i;
1741
- const n = this.evaluateNode(t, r), l = this.createCacheKey(t, r);
1742
- return this.resultCache.set(l, n), n;
728
+ evaluate(e, r, s) {
729
+ const a = this.getCachedResult(e, r, s);
730
+ if (a !== void 0)
731
+ return a;
732
+ const n = this.evaluateNode(e, r), o = this.createCacheKey(e, r);
733
+ return this.resultCache.set(o, n), n;
1743
734
  }
1744
735
  /**
1745
736
  * Core expression evaluation logic
1746
737
  */
1747
- evaluateNode(t, r) {
1748
- switch (t.Type) {
738
+ evaluateNode(e, r) {
739
+ switch (e.Type) {
1749
740
  case "Literal":
1750
- return t.Value;
741
+ return e.Value;
1751
742
  case "Identifier":
1752
- return this.getIdentifierValue(t, r);
743
+ return this.getIdentifierValue(e, r);
1753
744
  case "BinaryExpression":
1754
- return this.evaluateBinaryExpression(t, r);
745
+ return this.evaluateBinaryExpression(e, r);
1755
746
  case "LogicalExpression":
1756
- return this.evaluateLogicalExpression(t, r);
747
+ return this.evaluateLogicalExpression(e, r);
1757
748
  case "CallExpression":
1758
- return this.evaluateCallExpression(t, r);
749
+ return this.evaluateCallExpression(e, r);
1759
750
  case "MemberExpression":
1760
- return this.evaluateMemberExpression(t, r);
751
+ return this.evaluateMemberExpression(e, r);
1761
752
  default:
1762
- throw new Error(`Unsupported expression type: ${t.Type}`);
753
+ throw new Error(`Unsupported expression type: ${e.Type}`);
1763
754
  }
1764
755
  }
1765
756
  /**
1766
757
  * Get identifier value with system context support
1767
758
  */
1768
- getIdentifierValue(t, r) {
1769
- if (t.Name) {
1770
- if (t.Name === "NOW") return /* @__PURE__ */ new Date();
1771
- if (t.Name === "TODAY") {
759
+ getIdentifierValue(e, r) {
760
+ if (e.Name) {
761
+ if (e.Name === "NOW") return /* @__PURE__ */ new Date();
762
+ if (e.Name === "TODAY") {
1772
763
  const s = /* @__PURE__ */ new Date();
1773
764
  return new Date(s.getFullYear(), s.getMonth(), s.getDate());
1774
765
  }
1775
- return t.Name === "CURRENT_USER_ID" ? 1 : t.Name === "CURRENT_USER" ? {
766
+ return e.Name === "CURRENT_USER_ID" ? 1 : e.Name === "CURRENT_USER" ? {
1776
767
  EmpId: 1,
1777
768
  Email: "user@example.com",
1778
769
  FirstName: "John",
1779
770
  LastName: "Doe",
1780
771
  Role: "User"
1781
- } : r[t.Name];
772
+ } : r[e.Name];
1782
773
  }
1783
774
  }
1784
775
  /**
1785
776
  * Evaluate binary expressions with type coercion
1786
777
  */
1787
- evaluateBinaryExpression(t, r) {
1788
- if (!t.Arguments || t.Arguments.length !== 2)
778
+ evaluateBinaryExpression(e, r) {
779
+ if (!e.Arguments || e.Arguments.length !== 2)
1789
780
  throw new Error("Binary expression requires exactly 2 arguments");
1790
- const s = this.evaluateNode(t.Arguments[0], r), i = this.evaluateNode(t.Arguments[1], r);
1791
- switch (t.Operator) {
781
+ const s = this.evaluateNode(e.Arguments[0], r), a = this.evaluateNode(e.Arguments[1], r);
782
+ switch (e.Operator) {
1792
783
  case "==":
1793
- return s == i;
784
+ return s == a;
1794
785
  case "!=":
1795
- return s != i;
786
+ return s != a;
1796
787
  case "===":
1797
- return s === i;
788
+ return s === a;
1798
789
  case "!==":
1799
- return s !== i;
790
+ return s !== a;
1800
791
  case "<":
1801
- return Number(s) < Number(i);
792
+ return Number(s) < Number(a);
1802
793
  case "<=":
1803
- return Number(s) <= Number(i);
794
+ return Number(s) <= Number(a);
1804
795
  case ">":
1805
- return Number(s) > Number(i);
796
+ return Number(s) > Number(a);
1806
797
  case ">=":
1807
- return Number(s) >= Number(i);
798
+ return Number(s) >= Number(a);
1808
799
  case "+":
1809
- return Number(s) + Number(i);
800
+ return Number(s) + Number(a);
1810
801
  case "-":
1811
- return Number(s) - Number(i);
802
+ return Number(s) - Number(a);
1812
803
  case "*":
1813
- return Number(s) * Number(i);
804
+ return Number(s) * Number(a);
1814
805
  case "/":
1815
- return Number(s) / Number(i);
806
+ return Number(s) / Number(a);
1816
807
  case "%":
1817
- return Number(s) % Number(i);
808
+ return Number(s) % Number(a);
1818
809
  default:
1819
- throw new Error(`Unsupported binary operator: ${t.Operator}`);
810
+ throw new Error(`Unsupported binary operator: ${e.Operator}`);
1820
811
  }
1821
812
  }
1822
813
  /**
1823
814
  * Evaluate logical expressions with short-circuiting
1824
815
  */
1825
- evaluateLogicalExpression(t, r) {
1826
- if (!t.Arguments || t.Arguments.length < 2)
816
+ evaluateLogicalExpression(e, r) {
817
+ if (!e.Arguments || e.Arguments.length < 2)
1827
818
  throw new Error("Logical expression requires at least 2 arguments");
1828
- switch (t.Operator) {
819
+ switch (e.Operator) {
1829
820
  case "AND":
1830
- for (const s of t.Arguments)
821
+ for (const s of e.Arguments)
1831
822
  if (!this.evaluateNode(s, r)) return !1;
1832
823
  return !0;
1833
824
  case "OR":
1834
- for (const s of t.Arguments)
825
+ for (const s of e.Arguments)
1835
826
  if (this.evaluateNode(s, r)) return !0;
1836
827
  return !1;
1837
828
  default:
1838
- throw new Error(`Unsupported logical operator: ${t.Operator}`);
829
+ throw new Error(`Unsupported logical operator: ${e.Operator}`);
1839
830
  }
1840
831
  }
1841
832
  /**
1842
833
  * Evaluate function calls with built-in functions
1843
834
  */
1844
- evaluateCallExpression(t, r) {
1845
- var i;
1846
- if (!t.Callee)
835
+ evaluateCallExpression(e, r) {
836
+ var a;
837
+ if (!e.Callee)
1847
838
  throw new Error("Call expression requires a function name");
1848
- const s = ((i = t.Arguments) == null ? void 0 : i.map((n) => this.evaluateNode(n, r))) || [];
1849
- switch (t.Callee) {
839
+ const s = ((a = e.Arguments) == null ? void 0 : a.map((n) => this.evaluateNode(n, r))) || [];
840
+ switch (e.Callee) {
1850
841
  case "CONCAT":
1851
- return s.map((p) => String(p || "")).join("");
842
+ return s.map((f) => String(f || "")).join("");
1852
843
  case "TRIM":
1853
844
  return String(s[0] || "").trim();
1854
845
  case "LENGTH":
@@ -1862,14 +853,14 @@ class qr {
1862
853
  case "MATCHES":
1863
854
  return new RegExp(String(s[1])).test(String(s[0] || ""));
1864
855
  case "SUM":
1865
- return s.reduce((p, N) => p + (Number(N) || 0), 0);
856
+ return s.reduce((f, N) => f + (Number(N) || 0), 0);
1866
857
  case "AVG":
1867
- const n = s.filter((p) => !isNaN(Number(p)));
1868
- return n.length > 0 ? n.reduce((p, N) => p + Number(N), 0) / n.length : 0;
858
+ const n = s.filter((f) => !isNaN(Number(f)));
859
+ return n.length > 0 ? n.reduce((f, N) => f + Number(N), 0) / n.length : 0;
1869
860
  case "MIN":
1870
- return Math.min(...s.map((p) => Number(p) || 0));
861
+ return Math.min(...s.map((f) => Number(f) || 0));
1871
862
  case "MAX":
1872
- return Math.max(...s.map((p) => Number(p) || 0));
863
+ return Math.max(...s.map((f) => Number(f) || 0));
1873
864
  case "ROUND":
1874
865
  return Math.round(Number(s[0]) || 0);
1875
866
  case "FLOOR":
@@ -1885,25 +876,25 @@ class qr {
1885
876
  case "DAY":
1886
877
  return new Date(s[0]).getDate();
1887
878
  case "DATE_DIFF":
1888
- const l = new Date(s[0]), d = new Date(s[1]), w = Math.abs(l.getTime() - d.getTime());
1889
- return Math.ceil(w / (1e3 * 60 * 60 * 24));
879
+ const o = new Date(s[0]), u = new Date(s[1]), p = Math.abs(o.getTime() - u.getTime());
880
+ return Math.ceil(p / (1e3 * 60 * 60 * 24));
1890
881
  case "IF":
1891
882
  return s[0] ? s[1] : s[2];
1892
883
  case "AUTO_NUMBER":
1893
884
  return Math.floor(Math.random() * 1e4);
1894
885
  default:
1895
- throw new Error(`Unknown function: ${t.Callee}`);
886
+ throw new Error(`Unknown function: ${e.Callee}`);
1896
887
  }
1897
888
  }
1898
889
  /**
1899
890
  * Evaluate member expressions
1900
891
  */
1901
- evaluateMemberExpression(t, r) {
892
+ evaluateMemberExpression(e, r) {
1902
893
  var n;
1903
- if (!t.Arguments || t.Arguments.length === 0)
894
+ if (!e.Arguments || e.Arguments.length === 0)
1904
895
  throw new Error("Member expression requires arguments");
1905
- const s = this.evaluateNode(t.Arguments[0], r), i = (n = t.Arguments[0].Property) == null ? void 0 : n.Name;
1906
- return i && s && typeof s == "object" ? s[i] : s;
896
+ const s = this.evaluateNode(e.Arguments[0], r), a = (n = e.Arguments[0].Property) == null ? void 0 : n.Name;
897
+ return a && s && typeof s == "object" ? s[a] : s;
1907
898
  }
1908
899
  /**
1909
900
  * Clear all caches
@@ -1912,58 +903,58 @@ class qr {
1912
903
  this.resultCache.clear(), this.dependencyCache.clear(), this.compiledExpressions.clear();
1913
904
  }
1914
905
  }
1915
- const kt = new qr();
1916
- function $r(e, t, r, s, i) {
906
+ const ge = new ht();
907
+ function gt(t, e, r, s, a) {
1917
908
  if (!r || r.length === 0)
1918
909
  return { isValid: !0 };
1919
- const n = { ...s, [e]: t };
1920
- for (const l of r)
910
+ const n = { ...s, [t]: e };
911
+ for (const o of r)
1921
912
  try {
1922
- if (!kt.evaluate(
1923
- l.ExpressionTree,
913
+ if (!ge.evaluate(
914
+ o.ExpressionTree,
1924
915
  n,
1925
- i
916
+ a
1926
917
  ))
1927
918
  return {
1928
919
  isValid: !1,
1929
- message: l.Message || `Validation failed for ${l.Name}`,
1930
- fieldName: e
920
+ message: o.Message || `Validation failed for ${o.Name}`,
921
+ fieldName: t
1931
922
  };
1932
- } catch (d) {
1933
- console.warn(`Validation rule ${l.Id} failed to evaluate:`, d);
923
+ } catch (u) {
924
+ console.warn(`Validation rule ${o.Id} failed to evaluate:`, u);
1934
925
  }
1935
926
  return { isValid: !0 };
1936
927
  }
1937
- function Dt(e) {
1938
- return Array.from(kt.getDependencies(e));
928
+ function me(t) {
929
+ return Array.from(ge.getDependencies(t));
1939
930
  }
1940
- function Qr(e) {
931
+ function xt(t) {
1941
932
  const {
1942
- source: t,
933
+ source: e,
1943
934
  operation: r,
1944
935
  recordId: s,
1945
- defaultValues: i = {},
936
+ defaultValues: a = {},
1946
937
  mode: n = "onBlur",
1947
938
  // Validation mode - controls when errors are shown (see types.ts for details)
1948
- enabled: l = !0,
1949
- userRole: d,
1950
- onSchemaError: w,
1951
- skipSchemaFetch: p = !1,
939
+ enabled: o = !0,
940
+ userRole: u,
941
+ onSchemaError: p,
942
+ skipSchemaFetch: f = !1,
1952
943
  schema: N,
1953
- interactionMode: D = "interactive"
1954
- } = e, v = D === "interactive", [m, K] = ye(null), [O, Z] = ye({}), [H, x] = ye(!1), [ee] = ye({}), [L, T] = ye(null), [oe, he] = ye(!1), [ae, ne] = ye(null), B = qe(!1), le = qe(null), V = qe(null), E = qe(w);
1955
- $e(() => {
1956
- E.current = w;
1957
- }, [w]);
944
+ interactionMode: L = "interactive"
945
+ } = t, b = L === "interactive", [i, q] = M(null), [C, be] = M({}), [H, G] = M(!1), [we] = M({}), [V, X] = M(null), [Q, Z] = M(!1), [ye, ee] = M(null), B = Y(!1), K = Y(null), j = Y(null), v = Y(p);
946
+ z(() => {
947
+ v.current = p;
948
+ }, [p]);
1958
949
  const {
1959
- data: S,
1960
- isLoading: U,
1961
- error: $,
1962
- refetch: j
1963
- } = ct({
1964
- queryKey: ["form-schema", t],
1965
- queryFn: () => p ? Promise.resolve(N || {}) : Br(t),
1966
- enabled: l && (!p || !!N),
950
+ data: P,
951
+ isLoading: Ee,
952
+ error: k,
953
+ refetch: te
954
+ } = ue({
955
+ queryKey: ["form-schema", e],
956
+ queryFn: () => f ? Promise.resolve(N || {}) : mt(e),
957
+ enabled: o && (!f || !!N),
1967
958
  retry: 3,
1968
959
  staleTime: 30 * 60 * 1e3,
1969
960
  // 30 minutes - schemas don't change frequently
@@ -1971,133 +962,133 @@ function Qr(e) {
1971
962
  // 1 hour - keep schemas in cache longer
1972
963
  throwOnError: !1
1973
964
  }), {
1974
- data: z,
1975
- isLoading: ce,
1976
- error: me
1977
- } = ct({
1978
- queryKey: ["form-record", t, s],
1979
- queryFn: () => Cr(t, s),
1980
- enabled: l && r === "update" && !!s,
965
+ data: O,
966
+ isLoading: re,
967
+ error: Ne
968
+ } = ue({
969
+ queryKey: ["form-record", e, s],
970
+ queryFn: () => it(e, s),
971
+ enabled: o && r === "update" && !!s,
1981
972
  retry: 3,
1982
973
  staleTime: 5 * 60 * 1e3,
1983
974
  // 5 minutes - records can change more frequently
1984
975
  gcTime: 15 * 60 * 1e3,
1985
976
  // 15 minutes - keep records for a reasonable time
1986
977
  throwOnError: !1
1987
- }), Me = Ne(() => {
1988
- const u = { ...i };
1989
- if (r === "update" && z && Object.assign(u, z), m)
1990
- for (const [o, f] of Object.entries(m.fields))
1991
- f.defaultValue !== void 0 && !(o in u) && (u[o] = f.defaultValue);
1992
- return u;
1993
- }, [i, z, r, m]), A = dr({
978
+ }), Fe = $(() => {
979
+ const c = { ...a };
980
+ if (r === "update" && O && Object.assign(c, O), i)
981
+ for (const [d, l] of Object.entries(i.fields))
982
+ l.defaultValue !== void 0 && !(d in c) && (c[d] = l.defaultValue);
983
+ return c;
984
+ }, [a, O, r, i]), m = $e({
1994
985
  mode: n,
1995
- defaultValues: i,
1996
- values: r === "update" && z ? Me : void 0
986
+ defaultValues: a,
987
+ values: r === "update" && O ? Fe : void 0
1997
988
  });
1998
- $e(() => {
1999
- var u;
2000
- if (S)
989
+ z(() => {
990
+ var c;
991
+ if (P)
2001
992
  try {
2002
- const o = Dr(
2003
- S,
993
+ const d = tt(
994
+ P,
2004
995
  {},
2005
996
  // Pass empty object - validation functions get live values from react-hook-form
2006
- d
997
+ u
2007
998
  );
2008
- K(o);
2009
- const f = Rr(o);
2010
- Object.keys(f).length > 0 && Mr(f).then(Z).catch(console.warn);
2011
- } catch (o) {
2012
- console.error("Schema processing failed:", o), (u = E.current) == null || u.call(E, o);
999
+ q(d);
1000
+ const l = st(d);
1001
+ Object.keys(l).length > 0 && ct(l).then(be).catch(console.warn);
1002
+ } catch (d) {
1003
+ console.error("Schema processing failed:", d), (c = v.current) == null || c.call(v, d);
2013
1004
  }
2014
- }, [S, d]), $e(() => {
2015
- var u;
2016
- $ && ((u = E.current) == null || u.call(E, $));
2017
- }, [$]), $e(() => {
2018
- if (!v || r !== "create" || !m || !l || L)
1005
+ }, [P, u]), z(() => {
1006
+ var c;
1007
+ k && ((c = v.current) == null || c.call(v, k));
1008
+ }, [k]), z(() => {
1009
+ if (!b || r !== "create" || !i || !o || V)
2019
1010
  return;
2020
1011
  (async () => {
2021
- he(!0), ne(null);
1012
+ Z(!0), ee(null);
2022
1013
  try {
2023
- const f = await pe(t).draftInteraction({});
2024
- T(f._id), f && typeof f == "object" && Object.entries(f).forEach(([h, c]) => {
1014
+ const l = await I(e).draftInteraction({});
1015
+ X(l._id), l && typeof l == "object" && Object.entries(l).forEach(([h, g]) => {
2025
1016
  if (h === "_id") return;
2026
- A.getValues(h) !== c && A.setValue(h, c, {
1017
+ m.getValues(h) !== g && m.setValue(h, g, {
2027
1018
  shouldDirty: !1,
2028
1019
  shouldValidate: !1
2029
1020
  });
2030
1021
  });
2031
- } catch (o) {
2032
- console.error("Failed to create initial draft:", o), ne(o);
1022
+ } catch (d) {
1023
+ console.error("Failed to create initial draft:", d), ee(d);
2033
1024
  } finally {
2034
- he(!1);
1025
+ Z(!1);
2035
1026
  }
2036
1027
  })();
2037
- }, [v, r, m, l, L, t, A]);
2038
- const Ee = Ne(() => {
2039
- if (!m) return [];
2040
- const u = /* @__PURE__ */ new Set(), o = new Set(m.computedFields);
2041
- return Object.entries(m.fieldRules).forEach(([f, h]) => {
2042
- h.computation.forEach((c) => {
2043
- const y = m.rules.computation[c];
2044
- y != null && y.ExpressionTree && Dt(y.ExpressionTree).forEach((b) => {
2045
- m.fields[b] && b !== f && !o.has(b) && u.add(b);
1028
+ }, [b, r, i, o, V, e, m]);
1029
+ const J = $(() => {
1030
+ if (!i) return [];
1031
+ const c = /* @__PURE__ */ new Set(), d = new Set(i.computedFields);
1032
+ return Object.entries(i.fieldRules).forEach(([l, h]) => {
1033
+ h.computation.forEach((g) => {
1034
+ const w = i.rules.computation[g];
1035
+ w != null && w.ExpressionTree && me(w.ExpressionTree).forEach((y) => {
1036
+ i.fields[y] && y !== l && !d.has(y) && c.add(y);
2046
1037
  });
2047
1038
  });
2048
- }), m.computedFields.forEach((f) => {
2049
- const h = m.fields[f];
2050
- h._bdoField.Formula && Dt(
1039
+ }), i.computedFields.forEach((l) => {
1040
+ const h = i.fields[l];
1041
+ h._bdoField.Formula && me(
2051
1042
  h._bdoField.Formula.ExpressionTree
2052
- ).forEach((y) => {
2053
- m.fields[y] && y !== f && !o.has(y) && u.add(y);
1043
+ ).forEach((w) => {
1044
+ i.fields[w] && w !== l && !d.has(w) && c.add(w);
2054
1045
  });
2055
- }), Array.from(u);
2056
- }, [m]), Ae = te(
2057
- async (u) => {
2058
- if (!(!m || !(v || Ee.length > 0 && Ee.includes(u)))) {
2059
- if (v && r === "create" && !L) {
1046
+ }), Array.from(c);
1047
+ }, [i]), se = S(
1048
+ async (c) => {
1049
+ if (!(!i || !(b || J.length > 0 && J.includes(c)))) {
1050
+ if (b && r === "create" && !V) {
2060
1051
  console.warn("Interactive create mode: waiting for draft ID");
2061
1052
  return;
2062
1053
  }
2063
- B.current || (le.current && clearTimeout(le.current), le.current = setTimeout(() => {
2064
- if (!m || B.current)
1054
+ B.current || (K.current && clearTimeout(K.current), K.current = setTimeout(() => {
1055
+ if (!i || B.current)
2065
1056
  return;
2066
- const f = A.getValues();
1057
+ const l = m.getValues();
2067
1058
  (async () => {
2068
1059
  B.current = !0;
2069
1060
  try {
2070
- const c = pe(t), y = {};
2071
- r === "update" && s && "_id" in f && (y._id = f._id), v && r === "create" && L && (y._id = L);
2072
- const F = V.current ?? (r === "update" ? z : null) ?? {}, b = new Set(
2073
- m.computedFields || []
1061
+ const g = I(e), w = {};
1062
+ r === "update" && s && "_id" in l && (w._id = l._id), b && r === "create" && V && (w._id = V);
1063
+ const R = j.current ?? (r === "update" ? O : null) ?? {}, y = new Set(
1064
+ i.computedFields || []
2074
1065
  );
2075
- Object.keys(f).forEach((q) => {
2076
- if (q === "_id" || b.has(q)) return;
2077
- const J = f[q], be = F[q];
2078
- JSON.stringify(J) !== JSON.stringify(be) && (J !== "" && J !== null && J !== void 0) && (y[q] = J);
1066
+ Object.keys(l).forEach((F) => {
1067
+ if (F === "_id" || y.has(F)) return;
1068
+ const A = l[F], oe = R[F];
1069
+ JSON.stringify(A) !== JSON.stringify(oe) && (A !== "" && A !== null && A !== void 0) && (w[F] = A);
2079
1070
  });
2080
- const _ = y, P = {
2081
- ...V.current
1071
+ const E = w, D = {
1072
+ ...j.current
2082
1073
  };
2083
- Object.keys(f).forEach((q) => {
2084
- b.has(q) || (P[q] = f[q]);
2085
- }), V.current = P;
2086
- let W;
2087
- r === "update" && s ? W = await c.draftPatch(s, _) : v && L ? W = await c.draftInteraction(_) : W = await c.draft(_), W && typeof W == "object" && (Object.entries(W).forEach(
2088
- ([q, J]) => {
2089
- f[q] !== J && A.setValue(q, J, {
1074
+ Object.keys(l).forEach((F) => {
1075
+ y.has(F) || (D[F] = l[F]);
1076
+ }), j.current = D;
1077
+ let T;
1078
+ r === "update" && s ? T = await g.draftPatch(s, E) : b && V ? T = await g.draftInteraction(E) : T = await g.draft(E), T && typeof T == "object" && (Object.entries(T).forEach(
1079
+ ([F, A]) => {
1080
+ l[F] !== A && m.setValue(F, A, {
2090
1081
  shouldDirty: !1,
2091
1082
  shouldValidate: !1
2092
1083
  });
2093
1084
  }
2094
- ), Object.entries(W).forEach(
2095
- ([q, J]) => {
2096
- b.has(q) && (V.current[q] = J);
1085
+ ), Object.entries(T).forEach(
1086
+ ([F, A]) => {
1087
+ y.has(F) && (j.current[F] = A);
2097
1088
  }
2098
1089
  ));
2099
- } catch (c) {
2100
- console.warn("Failed to compute fields via API:", c);
1090
+ } catch (g) {
1091
+ console.warn("Failed to compute fields via API:", g);
2101
1092
  } finally {
2102
1093
  B.current = !1;
2103
1094
  }
@@ -2106,160 +1097,160 @@ function Qr(e) {
2106
1097
  }
2107
1098
  },
2108
1099
  [
2109
- m,
1100
+ i,
2110
1101
  r,
2111
1102
  s,
2112
- z,
2113
- t,
2114
- A,
2115
- Ee,
2116
- v,
2117
- L
1103
+ O,
1104
+ e,
1105
+ m,
1106
+ J,
1107
+ b,
1108
+ V
2118
1109
  ]
2119
- ), Ye = te(async () => {
2120
- if (!m)
1110
+ ), Re = S(async () => {
1111
+ if (!i)
2121
1112
  return !1;
2122
- const u = A.getValues();
2123
- if (!await A.trigger())
1113
+ const c = m.getValues();
1114
+ if (!await m.trigger())
2124
1115
  return !1;
2125
- const f = m.crossFieldValidation.map(
2126
- (c) => ({
2127
- Id: c.Id,
2128
- Condition: { ExpressionTree: c.ExpressionTree },
2129
- Message: c.Message || `Validation failed for ${c.Name}`
1116
+ const l = i.crossFieldValidation.map(
1117
+ (g) => ({
1118
+ Id: g.Id,
1119
+ Condition: { ExpressionTree: g.ExpressionTree },
1120
+ Message: g.Message || `Validation failed for ${g.Name}`
2130
1121
  })
2131
- ), h = At(
2132
- f,
2133
- u,
2134
- O
1122
+ ), h = le(
1123
+ l,
1124
+ c,
1125
+ C
2135
1126
  );
2136
- return h.length > 0 ? (h.forEach((c, y) => {
2137
- A.setError(`root.crossField${y}`, {
1127
+ return h.length > 0 ? (h.forEach((g, w) => {
1128
+ m.setError(`root.crossField${w}`, {
2138
1129
  type: "validate",
2139
- message: c.message
1130
+ message: g.message
2140
1131
  });
2141
1132
  }), !1) : !0;
2142
1133
  }, [
2143
- m,
2144
- A.getValues,
2145
- A.trigger,
2146
- A.setError,
2147
- O
2148
- ]), Ie = te(
2149
- (u, o) => A.handleSubmit(
1134
+ i,
1135
+ m.getValues,
1136
+ m.trigger,
1137
+ m.setError,
1138
+ C
1139
+ ]), Ve = S(
1140
+ (c, d) => m.handleSubmit(
2150
1141
  // RHF onValid handler - validation passed, now do cross-field + API
2151
- async (f, h) => {
2152
- if (!m) {
2153
- const c = new Error("Schema not loaded");
2154
- o == null || o(c, h);
1142
+ async (l, h) => {
1143
+ if (!i) {
1144
+ const g = new Error("Schema not loaded");
1145
+ d == null || d(g, h);
2155
1146
  return;
2156
1147
  }
2157
- x(!0);
1148
+ G(!0);
2158
1149
  try {
2159
- const c = m.crossFieldValidation.map(
2160
- (_) => ({
2161
- Id: _.Id,
2162
- Condition: { ExpressionTree: _.ExpressionTree },
2163
- Message: _.Message || `Validation failed for ${_.Name}`
1150
+ const g = i.crossFieldValidation.map(
1151
+ (E) => ({
1152
+ Id: E.Id,
1153
+ Condition: { ExpressionTree: E.ExpressionTree },
1154
+ Message: E.Message || `Validation failed for ${E.Name}`
2164
1155
  })
2165
- ), y = At(
2166
- c,
2167
- f,
2168
- O
1156
+ ), w = le(
1157
+ g,
1158
+ l,
1159
+ C
2169
1160
  );
2170
- if (y.length > 0) {
2171
- y.forEach((_, P) => {
2172
- A.setError(`root.crossField${P}`, {
1161
+ if (w.length > 0) {
1162
+ w.forEach((E, D) => {
1163
+ m.setError(`root.crossField${D}`, {
2173
1164
  type: "validate",
2174
- message: _.message
1165
+ message: E.message
2175
1166
  });
2176
- }), o == null || o(A.formState.errors, h);
1167
+ }), d == null || d(m.formState.errors, h);
2177
1168
  return;
2178
1169
  }
2179
- const F = Ir(
2180
- f,
2181
- m.computedFields,
1170
+ const R = lt(
1171
+ l,
1172
+ i.computedFields,
2182
1173
  r,
2183
- z
1174
+ O
2184
1175
  );
2185
- let b;
2186
- if (v) {
2187
- const _ = pe(t);
1176
+ let y;
1177
+ if (b) {
1178
+ const E = I(e);
2188
1179
  if (r === "create") {
2189
- if (!L)
1180
+ if (!V)
2190
1181
  throw new Error(
2191
1182
  "Interactive create mode requires a draft ID. Draft creation may have failed."
2192
1183
  );
2193
- b = { success: !0, data: await _.draft({
2194
- ...F,
2195
- _id: L
1184
+ y = { success: !0, data: await E.draft({
1185
+ ...R,
1186
+ _id: V
2196
1187
  }) };
2197
1188
  } else
2198
- b = { success: !0, data: await _.draftUpdate(s, F) };
2199
- } else if (b = await Tr(
2200
- t,
1189
+ y = { success: !0, data: await E.draftUpdate(s, R) };
1190
+ } else if (y = await ot(
1191
+ e,
2201
1192
  r,
2202
- F,
1193
+ R,
2203
1194
  s
2204
- ), !b.success)
2205
- throw b.error || new Error("Submission failed");
2206
- r === "create" && (A.reset(), v && T(null)), await (u == null ? void 0 : u(b.data || f, h));
2207
- } catch (c) {
2208
- o == null || o(c, h);
1195
+ ), !y.success)
1196
+ throw y.error || new Error("Submission failed");
1197
+ r === "create" && (m.reset(), b && X(null)), await (c == null ? void 0 : c(y.data || l, h));
1198
+ } catch (g) {
1199
+ d == null || d(g, h);
2209
1200
  } finally {
2210
- x(!1);
1201
+ G(!1);
2211
1202
  }
2212
1203
  },
2213
1204
  // RHF onInvalid handler - validation failed
2214
- (f, h) => {
2215
- o == null || o(f, h);
1205
+ (l, h) => {
1206
+ d == null || d(l, h);
2216
1207
  }
2217
1208
  ),
2218
1209
  [
2219
- A,
2220
1210
  m,
2221
- O,
2222
- t,
1211
+ i,
1212
+ C,
1213
+ e,
2223
1214
  r,
2224
1215
  s,
2225
- z,
2226
- v,
2227
- L
1216
+ O,
1217
+ b,
1218
+ V
2228
1219
  ]
2229
- ), Ke = te(
2230
- (u) => (m == null ? void 0 : m.fields[u]) || null,
2231
- [m]
2232
- ), xe = te(() => {
2233
- if (!m) return {};
2234
- const u = {};
2235
- return Object.entries(m.fields).forEach(([o, f]) => {
2236
- u[o] = f;
2237
- }), u;
2238
- }, [m]), ke = te(
2239
- (u) => !!(m != null && m.fields[u]),
2240
- [m]
2241
- ), _e = te(
2242
- (u) => (m == null ? void 0 : m.requiredFields.includes(u)) || !1,
2243
- [m]
2244
- ), De = te(
2245
- (u) => (m == null ? void 0 : m.computedFields.includes(u)) || !1,
2246
- [m]
2247
- ), ze = te(async () => {
2248
- await j();
2249
- }, [j]), Ue = te(() => {
2250
- A.clearErrors();
2251
- }, [A]), Be = U || r === "update" && ce || v && r === "create" && oe, Pe = Be || H, Se = $ || me || ae, Je = !!Se, Ge = Ne(
2252
- () => (m == null ? void 0 : m.computedFields) || [],
2253
- [m]
2254
- ), ut = Ne(
2255
- () => (m == null ? void 0 : m.requiredFields) || [],
2256
- [m]
2257
- ), Re = Ne(() => {
2258
- if (!m) return {};
2259
- const u = {};
2260
- return Object.entries(m.fields).forEach(([o, f]) => {
1220
+ ), Se = S(
1221
+ (c) => (i == null ? void 0 : i.fields[c]) || null,
1222
+ [i]
1223
+ ), Ae = S(() => {
1224
+ if (!i) return {};
1225
+ const c = {};
1226
+ return Object.entries(i.fields).forEach(([d, l]) => {
1227
+ c[d] = l;
1228
+ }), c;
1229
+ }, [i]), Ce = S(
1230
+ (c) => !!(i != null && i.fields[c]),
1231
+ [i]
1232
+ ), De = S(
1233
+ (c) => (i == null ? void 0 : i.requiredFields.includes(c)) || !1,
1234
+ [i]
1235
+ ), Oe = S(
1236
+ (c) => (i == null ? void 0 : i.computedFields.includes(c)) || !1,
1237
+ [i]
1238
+ ), xe = S(async () => {
1239
+ await te();
1240
+ }, [te]), ve = S(() => {
1241
+ m.clearErrors();
1242
+ }, [m]), ae = Ee || r === "update" && re || b && r === "create" && Q, Te = ae || H, ne = k || Ne || ye, Me = !!ne, Ie = $(
1243
+ () => (i == null ? void 0 : i.computedFields) || [],
1244
+ [i]
1245
+ ), Le = $(
1246
+ () => (i == null ? void 0 : i.requiredFields) || [],
1247
+ [i]
1248
+ ), ie = $(() => {
1249
+ if (!i) return {};
1250
+ const c = {};
1251
+ return Object.entries(i.fields).forEach(([d, l]) => {
2261
1252
  const h = {};
2262
- switch (f.required && (h.required = `${f.label} is required`), f.permission.editable || (h.disabled = !0), f.type) {
1253
+ switch (l.required && (h.required = `${l.label} is required`), l.permission.editable || (h.disabled = !0), l.type) {
2263
1254
  case "number":
2264
1255
  h.valueAsNumber = !0;
2265
1256
  break;
@@ -2268,88 +1259,88 @@ function Qr(e) {
2268
1259
  h.valueAsDate = !0;
2269
1260
  break;
2270
1261
  }
2271
- const c = f.rules.validation;
2272
- c.length > 0 && (h.validate = {
2273
- expressionValidation: (y) => {
2274
- const F = A.getValues();
2275
- for (const b of c) {
2276
- const _ = m.rules.validation[b];
2277
- if (_) {
2278
- const P = $r(
2279
- o,
2280
- y,
2281
- [_],
2282
- F,
2283
- ee
1262
+ const g = l.rules.validation;
1263
+ g.length > 0 && (h.validate = {
1264
+ expressionValidation: (w) => {
1265
+ const R = m.getValues();
1266
+ for (const y of g) {
1267
+ const E = i.rules.validation[y];
1268
+ if (E) {
1269
+ const D = gt(
1270
+ d,
1271
+ w,
1272
+ [E],
1273
+ R,
1274
+ we
2284
1275
  );
2285
- if (!P.isValid)
2286
- return P.message || _.Message || "Invalid value";
1276
+ if (!D.isValid)
1277
+ return D.message || E.Message || "Invalid value";
2287
1278
  }
2288
1279
  }
2289
1280
  return !0;
2290
1281
  }
2291
- }), u[o] = h;
2292
- }), u;
2293
- }, [m, A, O]);
1282
+ }), c[d] = h;
1283
+ }), c;
1284
+ }, [i, m, C]);
2294
1285
  return {
2295
1286
  // Form methods with strict typing
2296
- register: te(
2297
- (u, o) => {
2298
- const f = Re[u], h = o == null ? void 0 : o.onBlur, c = async (y) => {
2299
- h && await h(y);
2300
- let F = !0;
2301
- n === "onBlur" || n === "onTouched" || n === "all" ? F = await A.trigger(u) : F = !A.getFieldState(u, A.formState).error, F && await Ae(u);
1287
+ register: S(
1288
+ (c, d) => {
1289
+ const l = ie[c], h = d == null ? void 0 : d.onBlur, g = async (w) => {
1290
+ h && await h(w);
1291
+ let R = !0;
1292
+ n === "onBlur" || n === "onTouched" || n === "all" ? R = await m.trigger(c) : R = !m.getFieldState(c, m.formState).error, R && await se(c);
2302
1293
  };
2303
- return A.register(u, {
2304
- ...f,
2305
- ...o,
2306
- onBlur: c
1294
+ return m.register(c, {
1295
+ ...l,
1296
+ ...d,
1297
+ onBlur: g
2307
1298
  });
2308
1299
  },
2309
- [A, Re, Ae, n]
1300
+ [m, ie, se, n]
2310
1301
  ),
2311
- handleSubmit: Ie,
2312
- watch: A.watch,
1302
+ handleSubmit: Ve,
1303
+ watch: m.watch,
2313
1304
  // Type assertion for complex generic constraints
2314
- setValue: A.setValue,
2315
- reset: A.reset,
1305
+ setValue: m.setValue,
1306
+ reset: m.reset,
2316
1307
  // Flattened form state (NEW - direct access, no nested formState)
2317
- errors: A.formState.errors,
2318
- isValid: A.formState.isValid,
2319
- isDirty: A.formState.isDirty,
2320
- isSubmitting: A.formState.isSubmitting || H,
2321
- isSubmitSuccessful: A.formState.isSubmitSuccessful,
1308
+ errors: m.formState.errors,
1309
+ isValid: m.formState.isValid,
1310
+ isDirty: m.formState.isDirty,
1311
+ isSubmitting: m.formState.isSubmitting || H,
1312
+ isSubmitSuccessful: m.formState.isSubmitSuccessful,
2322
1313
  // Loading states
2323
- isLoadingInitialData: Be,
2324
- isLoadingRecord: ce,
2325
- isLoading: Pe,
1314
+ isLoadingInitialData: ae,
1315
+ isLoadingRecord: re,
1316
+ isLoading: Te,
2326
1317
  // Interactive mode state
2327
- draftId: L,
2328
- isCreatingDraft: oe,
1318
+ draftId: V,
1319
+ isCreatingDraft: Q,
2329
1320
  // Error handling
2330
- loadError: Se,
2331
- hasError: Je,
1321
+ loadError: ne,
1322
+ hasError: Me,
2332
1323
  // Schema information
2333
- schema: S,
2334
- schemaConfig: m,
2335
- computedFields: Ge,
2336
- requiredFields: ut,
1324
+ schema: P,
1325
+ schemaConfig: i,
1326
+ computedFields: Ie,
1327
+ requiredFields: Le,
2337
1328
  // Field helpers
2338
- getField: Ke,
2339
- getFields: xe,
2340
- hasField: ke,
2341
- isFieldRequired: _e,
2342
- isFieldComputed: De,
1329
+ getField: Se,
1330
+ getFields: Ae,
1331
+ hasField: Ce,
1332
+ isFieldRequired: De,
1333
+ isFieldComputed: Oe,
2343
1334
  // Operations
2344
- refreshSchema: ze,
2345
- validateForm: Ye,
2346
- clearErrors: Ue
1335
+ refreshSchema: xe,
1336
+ validateForm: Re,
1337
+ clearErrors: ve
2347
1338
  };
2348
1339
  }
2349
1340
  export {
2350
- Xr as clearFormCache,
2351
- Jr as isNetworkError,
2352
- Gr as isValidationError,
2353
- zr as parseApiError,
2354
- Qr as useForm
1341
+ Ot as clearFormCache,
1342
+ Ct as isNetworkError,
1343
+ Dt as isValidationError,
1344
+ At as parseApiError,
1345
+ xt as useForm
2355
1346
  };