@ram_28/kf-ai-sdk 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/README.md +55 -48
  2. package/dist/api/client.d.ts +14 -14
  3. package/dist/api/client.d.ts.map +1 -1
  4. package/dist/api/datetime.d.ts +5 -5
  5. package/dist/api/datetime.d.ts.map +1 -1
  6. package/dist/api/index.d.ts +1 -1
  7. package/dist/api/index.d.ts.map +1 -1
  8. package/dist/api/metadata.d.ts +2 -2
  9. package/dist/api/metadata.d.ts.map +1 -1
  10. package/dist/api.cjs +1 -0
  11. package/dist/api.d.ts +4 -0
  12. package/dist/api.d.ts.map +1 -0
  13. package/dist/api.mjs +27 -0
  14. package/dist/api.types.cjs +1 -0
  15. package/dist/api.types.d.ts +4 -0
  16. package/dist/api.types.d.ts.map +1 -0
  17. package/dist/api.types.mjs +1 -0
  18. package/dist/auth/AuthProvider.d.ts +3 -3
  19. package/dist/auth/AuthProvider.d.ts.map +1 -1
  20. package/dist/auth/authClient.d.ts +4 -4
  21. package/dist/auth/authClient.d.ts.map +1 -1
  22. package/dist/auth/authConfig.d.ts +5 -5
  23. package/dist/auth/authConfig.d.ts.map +1 -1
  24. package/dist/auth/index.d.ts +1 -1
  25. package/dist/auth/index.d.ts.map +1 -1
  26. package/dist/auth/types.d.ts +21 -21
  27. package/dist/auth/types.d.ts.map +1 -1
  28. package/dist/auth/useAuth.d.ts +2 -2
  29. package/dist/auth/useAuth.d.ts.map +1 -1
  30. package/dist/auth.cjs +1 -0
  31. package/dist/auth.d.ts +5 -0
  32. package/dist/auth.d.ts.map +1 -0
  33. package/dist/auth.mjs +280 -0
  34. package/dist/auth.types.cjs +1 -0
  35. package/dist/auth.types.d.ts +2 -0
  36. package/dist/auth.types.d.ts.map +1 -0
  37. package/dist/auth.types.mjs +1 -0
  38. package/dist/base-types.d.ts +2 -0
  39. package/dist/base-types.d.ts.map +1 -0
  40. package/dist/client-C15j4O5B.cjs +1 -0
  41. package/dist/client-CfvLiGfP.js +233 -0
  42. package/dist/cn-Dr87sK3i.js +2775 -0
  43. package/dist/cn-mXUIg4vp.cjs +1 -0
  44. package/dist/components/hooks/index.d.ts +3 -3
  45. package/dist/components/hooks/index.d.ts.map +1 -1
  46. package/dist/components/hooks/useFilter/index.d.ts +2 -2
  47. package/dist/components/hooks/useFilter/index.d.ts.map +1 -1
  48. package/dist/components/hooks/useFilter/types.d.ts +19 -31
  49. package/dist/components/hooks/useFilter/types.d.ts.map +1 -1
  50. package/dist/components/hooks/useFilter/useFilter.d.ts +2 -2
  51. package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -1
  52. package/dist/components/hooks/useForm/apiClient.d.ts +6 -6
  53. package/dist/components/hooks/useForm/apiClient.d.ts.map +1 -1
  54. package/dist/components/hooks/useForm/expressionValidator.utils.d.ts +7 -7
  55. package/dist/components/hooks/useForm/expressionValidator.utils.d.ts.map +1 -1
  56. package/dist/components/hooks/useForm/index.d.ts +5 -5
  57. package/dist/components/hooks/useForm/index.d.ts.map +1 -1
  58. package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts +10 -10
  59. package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts.map +1 -1
  60. package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts +7 -12
  61. package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts.map +1 -1
  62. package/dist/components/hooks/useForm/schemaParser.utils.d.ts +7 -7
  63. package/dist/components/hooks/useForm/schemaParser.utils.d.ts.map +1 -1
  64. package/dist/components/hooks/useForm/types.d.ts +67 -76
  65. package/dist/components/hooks/useForm/types.d.ts.map +1 -1
  66. package/dist/components/hooks/useForm/useForm.d.ts +2 -2
  67. package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
  68. package/dist/components/hooks/useKanban/apiClient.d.ts +16 -16
  69. package/dist/components/hooks/useKanban/apiClient.d.ts.map +1 -1
  70. package/dist/components/hooks/useKanban/context.d.ts +3 -3
  71. package/dist/components/hooks/useKanban/context.d.ts.map +1 -1
  72. package/dist/components/hooks/useKanban/dragDropManager.d.ts +7 -7
  73. package/dist/components/hooks/useKanban/dragDropManager.d.ts.map +1 -1
  74. package/dist/components/hooks/useKanban/index.d.ts +1 -1
  75. package/dist/components/hooks/useKanban/index.d.ts.map +1 -1
  76. package/dist/components/hooks/useKanban/types.d.ts +65 -67
  77. package/dist/components/hooks/useKanban/types.d.ts.map +1 -1
  78. package/dist/components/hooks/useKanban/useKanban.d.ts +2 -2
  79. package/dist/components/hooks/useKanban/useKanban.d.ts.map +1 -1
  80. package/dist/components/hooks/useTable/index.d.ts +1 -1
  81. package/dist/components/hooks/useTable/index.d.ts.map +1 -1
  82. package/dist/components/hooks/useTable/types.d.ts +10 -10
  83. package/dist/components/hooks/useTable/types.d.ts.map +1 -1
  84. package/dist/components/hooks/useTable/useTable.d.ts +2 -2
  85. package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
  86. package/dist/filter.cjs +1 -0
  87. package/dist/filter.d.ts +3 -0
  88. package/dist/filter.d.ts.map +1 -0
  89. package/dist/filter.mjs +6 -0
  90. package/dist/filter.types.cjs +1 -0
  91. package/dist/filter.types.d.ts +2 -0
  92. package/dist/filter.types.d.ts.map +1 -0
  93. package/dist/filter.types.mjs +1 -0
  94. package/dist/form.cjs +1 -0
  95. package/dist/form.d.ts +3 -0
  96. package/dist/form.d.ts.map +1 -0
  97. package/dist/form.mjs +2355 -0
  98. package/dist/form.types.cjs +1 -0
  99. package/dist/form.types.d.ts +2 -0
  100. package/dist/form.types.d.ts.map +1 -0
  101. package/dist/form.types.mjs +1 -0
  102. package/dist/jsx-runtime-BYECrxsp.cjs +30 -0
  103. package/dist/jsx-runtime-DGlMoOmv.js +630 -0
  104. package/dist/kanban.cjs +13 -0
  105. package/dist/kanban.d.ts +5 -0
  106. package/dist/kanban.d.ts.map +1 -0
  107. package/dist/kanban.mjs +1060 -0
  108. package/dist/kanban.types.cjs +1 -0
  109. package/dist/kanban.types.d.ts +2 -0
  110. package/dist/kanban.types.d.ts.map +1 -0
  111. package/dist/kanban.types.mjs +1 -0
  112. package/dist/kanban.ui.cjs +1 -0
  113. package/dist/kanban.ui.d.ts +2 -0
  114. package/dist/kanban.ui.d.ts.map +1 -0
  115. package/dist/kanban.ui.mjs +104 -0
  116. package/dist/metadata-2FLBsFcf.cjs +1 -0
  117. package/dist/metadata-DBcoDth-.js +43 -0
  118. package/dist/table.cjs +1 -0
  119. package/dist/table.d.ts +2 -0
  120. package/dist/table.d.ts.map +1 -0
  121. package/dist/table.mjs +148 -0
  122. package/dist/table.types.cjs +1 -0
  123. package/dist/table.types.d.ts +2 -0
  124. package/dist/table.types.d.ts.map +1 -0
  125. package/dist/table.types.mjs +1 -0
  126. package/dist/types/base-fields.d.ts +45 -45
  127. package/dist/types/base-fields.d.ts.map +1 -1
  128. package/dist/types/common.d.ts +45 -61
  129. package/dist/types/common.d.ts.map +1 -1
  130. package/dist/types.cjs +1 -0
  131. package/dist/types.mjs +1 -0
  132. package/dist/useFilter-CXFqEHyI.js +129 -0
  133. package/dist/useFilter-D-bCDo6Z.cjs +1 -0
  134. package/dist/useQuery-BScHEo7x.cjs +1 -0
  135. package/dist/useQuery-KpZFg80c.js +748 -0
  136. package/dist/utils/formatting.d.ts +4 -4
  137. package/dist/utils/formatting.d.ts.map +1 -1
  138. package/dist/utils.cjs +4 -0
  139. package/dist/utils.d.ts +3 -0
  140. package/dist/utils.d.ts.map +1 -0
  141. package/dist/utils.mjs +105 -0
  142. package/package.json +147 -9
  143. package/sdk/api/client.ts +51 -51
  144. package/sdk/api/datetime.ts +5 -5
  145. package/sdk/api/index.ts +28 -33
  146. package/sdk/api/metadata.ts +4 -4
  147. package/sdk/api.ts +24 -0
  148. package/sdk/api.types.ts +58 -0
  149. package/sdk/auth/AuthProvider.tsx +18 -18
  150. package/sdk/auth/authClient.ts +9 -9
  151. package/sdk/auth/authConfig.ts +9 -9
  152. package/sdk/auth/index.ts +5 -5
  153. package/sdk/auth/types.ts +21 -21
  154. package/sdk/auth/useAuth.ts +2 -2
  155. package/sdk/auth.ts +22 -0
  156. package/sdk/auth.types.ts +28 -0
  157. package/sdk/base-types.ts +45 -0
  158. package/sdk/components/hooks/index.ts +22 -22
  159. package/sdk/components/hooks/useFilter/index.ts +8 -14
  160. package/sdk/components/hooks/useFilter/types.ts +29 -58
  161. package/sdk/components/hooks/useFilter/useFilter.ts +41 -44
  162. package/sdk/components/hooks/useForm/apiClient.ts +8 -8
  163. package/sdk/components/hooks/useForm/expressionValidator.utils.ts +18 -18
  164. package/sdk/components/hooks/useForm/index.ts +24 -24
  165. package/sdk/components/hooks/useForm/optimizedExpressionValidator.utils.ts +22 -22
  166. package/sdk/components/hooks/useForm/ruleClassifier.utils.ts +26 -62
  167. package/sdk/components/hooks/useForm/schemaParser.utils.ts +24 -24
  168. package/sdk/components/hooks/useForm/types.ts +66 -82
  169. package/sdk/components/hooks/useForm/useForm.ts +15 -21
  170. package/sdk/components/hooks/useKanban/apiClient.ts +54 -54
  171. package/sdk/components/hooks/useKanban/context.ts +3 -3
  172. package/sdk/components/hooks/useKanban/dragDropManager.ts +19 -19
  173. package/sdk/components/hooks/useKanban/index.ts +26 -26
  174. package/sdk/components/hooks/useKanban/types.ts +69 -71
  175. package/sdk/components/hooks/useKanban/useKanban.ts +43 -51
  176. package/sdk/components/hooks/useKanban/useKanbanSimple.ts +4 -4
  177. package/sdk/components/hooks/useTable/index.ts +5 -1
  178. package/sdk/components/hooks/useTable/types.ts +10 -10
  179. package/sdk/components/hooks/useTable/useTable.ts +10 -10
  180. package/sdk/filter.ts +13 -0
  181. package/sdk/filter.types.ts +17 -0
  182. package/sdk/form.ts +15 -0
  183. package/sdk/form.types.ts +46 -0
  184. package/sdk/kanban.ts +23 -0
  185. package/sdk/kanban.types.ts +50 -0
  186. package/sdk/kanban.ui.ts +16 -0
  187. package/sdk/table.ts +7 -0
  188. package/sdk/table.types.ts +13 -0
  189. package/sdk/types/base-fields.ts +47 -47
  190. package/sdk/types/common.ts +47 -71
  191. package/sdk/types/index.ts +1 -1
  192. package/sdk/utils/formatting.ts +4 -4
  193. package/sdk/utils.ts +10 -0
  194. package/dist/index.cjs +0 -45
  195. package/dist/index.mjs +0 -6387
package/dist/form.mjs ADDED
@@ -0,0 +1,2355 @@
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 = [];
113
+ 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()),
1023
+ CURRENT_USER: {
1024
+ // These would typically come from auth context
1025
+ EmpId: 1,
1026
+ Email: "user@example.com",
1027
+ FirstName: "John",
1028
+ LastName: "Doe",
1029
+ Role: "User"
1030
+ },
1031
+ CURRENT_USER_ID: 1
1032
+ };
1033
+ }
1034
+ const hr = {
1035
+ // 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);
1044
+ },
1045
+ CONTAINS: (e, t) => String(e || "").includes(String(t || "")),
1046
+ // Date functions
1047
+ YEAR: (e) => new Date(e).getFullYear(),
1048
+ MONTH: (e) => new Date(e).getMonth() + 1,
1049
+ // 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));
1054
+ },
1055
+ ADD_DAYS: (e, t) => {
1056
+ const r = new Date(e);
1057
+ return r.setDate(r.getDate() + t), r;
1058
+ },
1059
+ ADD_MONTHS: (e, t) => {
1060
+ const r = new Date(e);
1061
+ return r.setMonth(r.getMonth() + t), r;
1062
+ },
1063
+ // 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;
1068
+ },
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),
1075
+ // Conditional functions
1076
+ IF: (e, t, r) => e ? t : r,
1077
+ // 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());
1084
+ },
1085
+ // System functions
1086
+ AUTO_NUMBER: () => Math.floor(Math.random() * 1e4) + 1e3,
1087
+ // 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);
1091
+ }),
1092
+ // 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) : ""
1096
+ };
1097
+ function fe(e, t) {
1098
+ var r;
1099
+ switch (e.Type) {
1100
+ case "Literal":
1101
+ return e.Value;
1102
+ case "SystemIdentifier":
1103
+ if (e.Property) {
1104
+ const p = t.systemValues[e.Name];
1105
+ return Ze(p, e.Property.Name);
1106
+ }
1107
+ return t.systemValues[e.Name];
1108
+ case "Identifier":
1109
+ if (e.Property) {
1110
+ const p = Et(e, t);
1111
+ return Ze(p, e.Property.Name);
1112
+ }
1113
+ return Et(e, t);
1114
+ case "MemberExpression":
1115
+ if (!e.Arguments || e.Arguments.length === 0)
1116
+ 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;
1119
+ case "BinaryExpression":
1120
+ if (!e.Arguments || e.Arguments.length !== 2)
1121
+ 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);
1124
+ case "LogicalExpression":
1125
+ if (!e.Arguments || e.Arguments.length < 2)
1126
+ throw new Error("LogicalExpression requires at least 2 arguments");
1127
+ return yr(e.Operator, e.Arguments, t);
1128
+ case "CallExpression":
1129
+ if (!e.Callee)
1130
+ 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)
1136
+ );
1137
+ return d(...w);
1138
+ case "AssignmentExpression":
1139
+ if (!e.Arguments || e.Arguments.length !== 1)
1140
+ throw new Error("AssignmentExpression requires exactly 1 argument");
1141
+ return fe(e.Arguments[0], t);
1142
+ default:
1143
+ throw new Error(`Unknown expression type: ${e.Type}`);
1144
+ }
1145
+ }
1146
+ function Et(e, t) {
1147
+ const { Name: r, Source: s } = e;
1148
+ if (!r)
1149
+ throw new Error("Identifier requires Name");
1150
+ switch (s) {
1151
+ case "Input":
1152
+ default:
1153
+ return t.formValues[r];
1154
+ }
1155
+ }
1156
+ function Ze(e, t) {
1157
+ if (!(!e || typeof e != "object"))
1158
+ return e[t];
1159
+ }
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) {
1163
+ case "==":
1164
+ return t == r;
1165
+ case "!=":
1166
+ return t != r;
1167
+ case ">":
1168
+ return s(t) > s(r);
1169
+ case "<":
1170
+ return s(t) < s(r);
1171
+ case ">=":
1172
+ return s(t) >= s(r);
1173
+ case "<=":
1174
+ return s(t) <= s(r);
1175
+ case "+":
1176
+ return s(t) + s(r);
1177
+ case "-":
1178
+ return s(t) - s(r);
1179
+ case "*":
1180
+ return s(t) * s(r);
1181
+ case "/":
1182
+ const i = s(r);
1183
+ return i !== 0 ? s(t) / i : 0;
1184
+ default:
1185
+ throw new Error(`Unknown binary operator: ${e}`);
1186
+ }
1187
+ }
1188
+ function yr(e, t, r) {
1189
+ switch (e) {
1190
+ case "AND":
1191
+ return t.every((s) => !!fe(s, r));
1192
+ case "OR":
1193
+ return t.some((s) => !!fe(s, r));
1194
+ default:
1195
+ throw new Error(`Unknown logical operator: ${e}`);
1196
+ }
1197
+ }
1198
+ function Mt(e, t, r = {}) {
1199
+ const s = {
1200
+ formValues: t,
1201
+ systemValues: fr(),
1202
+ referenceData: r
1203
+ };
1204
+ try {
1205
+ return fe(e, s);
1206
+ } catch (i) {
1207
+ return console.warn("Expression evaluation failed:", i), !1;
1208
+ }
1209
+ }
1210
+ function At(e, t, r = {}) {
1211
+ const s = [];
1212
+ for (const i of e)
1213
+ try {
1214
+ Mt(
1215
+ i.Condition.ExpressionTree,
1216
+ t,
1217
+ r
1218
+ ) || s.push({
1219
+ isValid: !1,
1220
+ message: i.Message,
1221
+ fieldName: i.Id
1222
+ });
1223
+ } catch (n) {
1224
+ console.warn(`Cross-field validation rule ${i.Id} failed:`, n);
1225
+ }
1226
+ return s;
1227
+ }
1228
+ function gr(e, t = {}, r = {}) {
1229
+ try {
1230
+ return Mt(e, t, r);
1231
+ } catch (s) {
1232
+ return console.warn("Default value calculation failed:", s), null;
1233
+ }
1234
+ }
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 : [
1239
+ `${n} != null`,
1240
+ `${n} != ''`,
1241
+ `trim(${n}) != ''`,
1242
+ `${n}!=null`,
1243
+ `${n}!=''`
1244
+ ].some((N) => r.includes(N));
1245
+ }
1246
+ function pr(e) {
1247
+ const t = { ...e };
1248
+ t.Rules || (t.Rules = {
1249
+ Validation: {},
1250
+ Computation: {},
1251
+ 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);
1261
+ }), r[s] = {
1262
+ ...i,
1263
+ Validation: l,
1264
+ Required: n
1265
+ };
1266
+ } 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,
1273
+ Required: !0
1274
+ });
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
1284
+ };
1285
+ }
1286
+ }), t.Fields = r, t;
1287
+ }
1288
+ function br(e) {
1289
+ var r, s, i;
1290
+ const t = {
1291
+ validation: {},
1292
+ computation: {},
1293
+ businessLogic: {}
1294
+ };
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;
1296
+ }
1297
+ function wr(e) {
1298
+ 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;
1308
+ return;
1309
+ }
1310
+ }
1311
+ const d = `${n.Name || ""} ${n.Description || ""}`.toLowerCase();
1312
+ for (const w of r)
1313
+ if (d.includes(w.toLowerCase())) {
1314
+ t[i] = w;
1315
+ return;
1316
+ }
1317
+ }), t;
1318
+ }
1319
+ function vr(e, t) {
1320
+ const r = {};
1321
+ Object.keys(e.Fields).forEach((i) => {
1322
+ r[i] = {
1323
+ validation: [],
1324
+ computation: [],
1325
+ businessLogic: []
1326
+ };
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));
1333
+ });
1334
+ });
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);
1338
+ }), r;
1339
+ }
1340
+ function Fr(e, t) {
1341
+ const r = {}, s = {
1342
+ editable: !0,
1343
+ readable: !0,
1344
+ hidden: !1
1345
+ };
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;
1350
+ return;
1351
+ }
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
1357
+ };
1358
+ }), r;
1359
+ }
1360
+ function Vr(e, t) {
1361
+ switch (e) {
1362
+ case "String":
1363
+ return t.toLowerCase().includes("email") ? "email" : t.toLowerCase().includes("password") ? "password" : "text";
1364
+ case "Number":
1365
+ return "number";
1366
+ case "Boolean":
1367
+ return "checkbox";
1368
+ case "Date":
1369
+ return "date";
1370
+ case "DateTime":
1371
+ return "datetime-local";
1372
+ case "Reference":
1373
+ return "reference";
1374
+ case "Array":
1375
+ case "Object":
1376
+ return "textarea";
1377
+ default:
1378
+ return "text";
1379
+ }
1380
+ }
1381
+ function It(e) {
1382
+ return e.replace(/([A-Z])/g, " $1").replace(/^./, (t) => t.toUpperCase()).replace(/_/g, " ").trim();
1383
+ }
1384
+ function Er(e, t, r) {
1385
+ const s = {};
1386
+ switch (t.Required && (s.required = {
1387
+ value: !0,
1388
+ message: `${It(e)} is required`
1389
+ }), t.Type) {
1390
+ case "Number":
1391
+ s.valueAsNumber = !0;
1392
+ break;
1393
+ case "Date":
1394
+ case "DateTime":
1395
+ s.valueAsDate = !0;
1396
+ break;
1397
+ }
1398
+ return t.Validation && t.Validation.length > 0 && (s.validate = () => !0), s;
1399
+ }
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 ? [] : [] : [];
1405
+ }
1406
+ function xr(e, t = {}) {
1407
+ if (!e.DefaultValue)
1408
+ switch (e.Type) {
1409
+ case "Boolean":
1410
+ return !1;
1411
+ case "Number":
1412
+ return 0;
1413
+ case "String":
1414
+ return "";
1415
+ case "Array":
1416
+ return [];
1417
+ case "Object":
1418
+ return {};
1419
+ default:
1420
+ return;
1421
+ }
1422
+ return gr(
1423
+ e.DefaultValue.ExpressionTree,
1424
+ t
1425
+ );
1426
+ }
1427
+ function _r(e, t, r, s = {}, i, n) {
1428
+ const l = {
1429
+ editable: !0,
1430
+ readable: !0,
1431
+ hidden: !1
1432
+ }, w = n || {
1433
+ validation: [],
1434
+ computation: [],
1435
+ 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),
1445
+ validation: N,
1446
+ description: t.Description,
1447
+ _bdoField: t,
1448
+ permission: i || l,
1449
+ rules: w
1450
+ };
1451
+ }
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))
1458
+ continue;
1459
+ const K = D[v];
1460
+ if (K.hidden)
1461
+ continue;
1462
+ const O = _r(
1463
+ v,
1464
+ m,
1465
+ s.Fields,
1466
+ t,
1467
+ K,
1468
+ N[v] || {
1469
+ validation: [],
1470
+ computation: [],
1471
+ businessLogic: []
1472
+ }
1473
+ );
1474
+ i[v] = O, n.push(v), O.computed && l.push(v), O.required && d.push(v);
1475
+ }
1476
+ return {
1477
+ fields: i,
1478
+ fieldOrder: n,
1479
+ computedFields: l,
1480
+ requiredFields: d,
1481
+ crossFieldValidation: w,
1482
+ rules: p,
1483
+ fieldRules: N,
1484
+ rolePermissions: s.RolePermission
1485
+ };
1486
+ }
1487
+ function Sr(e) {
1488
+ var r;
1489
+ if (e.type !== "reference" || !((r = e._bdoField.Values) != null && r.Reference))
1490
+ return null;
1491
+ const t = e._bdoField.Values.Reference;
1492
+ return {
1493
+ businessObject: t.BusinessObject,
1494
+ fields: t.Fields || ["_id"],
1495
+ // Default to ID field
1496
+ filters: t.Filters,
1497
+ sort: t.Sort
1498
+ };
1499
+ }
1500
+ function Rr(e) {
1501
+ const t = {};
1502
+ for (const [r, s] of Object.entries(e.fields))
1503
+ if (s.type === "reference") {
1504
+ const i = Sr(s);
1505
+ i && (t[r] = i);
1506
+ }
1507
+ return t;
1508
+ }
1509
+ async function Nr(e) {
1510
+ try {
1511
+ const r = (await qt(e)).BOBlob;
1512
+ if (!r || typeof r != "object" || !r.Fields)
1513
+ throw new Error(`Invalid BDO schema response for ${e}`);
1514
+ 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"}`
1518
+ );
1519
+ }
1520
+ }
1521
+ async function Or(e, t = 3) {
1522
+ let r;
1523
+ for (let s = 1; s <= t; s++)
1524
+ try {
1525
+ return await Nr(e);
1526
+ } catch (i) {
1527
+ if (r = i, s < t) {
1528
+ const n = Math.min(1e3 * Math.pow(2, s - 1), 5e3);
1529
+ await new Promise((l) => setTimeout(l, n));
1530
+ continue;
1531
+ }
1532
+ }
1533
+ throw r;
1534
+ }
1535
+ async function Cr(e, t) {
1536
+ try {
1537
+ return await pe(e).get(t);
1538
+ } catch (r) {
1539
+ throw console.error(`Record fetch error for ${e}/${t}:`, r), new Error(
1540
+ `Failed to load record: ${r instanceof Error ? r.message : "Unknown error"}`
1541
+ );
1542
+ }
1543
+ }
1544
+ async function Tr(e, t, r, s) {
1545
+ try {
1546
+ let i;
1547
+ if (t === "create")
1548
+ return i = await pe(e).create(r), {
1549
+ success: !0,
1550
+ data: i,
1551
+ recordId: i._id || s
1552
+ };
1553
+ if (t === "update") {
1554
+ if (!s)
1555
+ throw new Error("Record ID is required for update operations");
1556
+ return i = await pe(e).update(s, r), {
1557
+ success: !0,
1558
+ data: i,
1559
+ recordId: i._id || s
1560
+ };
1561
+ } else
1562
+ throw new Error(`Unsupported operation: ${t}`);
1563
+ } catch (i) {
1564
+ return console.error("Form submission error:", i), {
1565
+ success: !1,
1566
+ error: new Error(
1567
+ `Failed to ${t} record: ${i instanceof Error ? i.message : "Unknown error"}`
1568
+ )
1569
+ };
1570
+ }
1571
+ }
1572
+ async function Lr(e, t = ["_id"], r, s) {
1573
+ 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), [];
1578
+ }
1579
+ }
1580
+ async function Mr(e) {
1581
+ const t = {}, r = Object.entries(e).map(
1582
+ async ([i, n]) => {
1583
+ try {
1584
+ const l = await Lr(
1585
+ n.businessObject,
1586
+ n.fields,
1587
+ n.filters,
1588
+ n.sort
1589
+ );
1590
+ return [i, l];
1591
+ } catch (l) {
1592
+ return console.warn(`Failed to fetch reference data for ${i}:`, l), [i, []];
1593
+ }
1594
+ }
1595
+ );
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 : [];
1600
+ }
1601
+ }), t;
1602
+ }
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) {
1608
+ if (r === "create") {
1609
+ i[l] = d;
1610
+ return;
1611
+ }
1612
+ if (r === "update") {
1613
+ if (!s) {
1614
+ i[l] = d;
1615
+ return;
1616
+ }
1617
+ const w = s[l];
1618
+ JSON.stringify(d) !== JSON.stringify(w) && (i[l] = d);
1619
+ }
1620
+ }
1621
+ }), i;
1622
+ }
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";
1626
+ }
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"));
1630
+ }
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"));
1634
+ }
1635
+ const Ve = /* @__PURE__ */ new Map();
1636
+ function kr(e, t, r = 10) {
1637
+ Ve.set(e, {
1638
+ data: t,
1639
+ timestamp: Date.now(),
1640
+ ttl: r * 60 * 1e3
1641
+ });
1642
+ }
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;
1646
+ }
1647
+ function Xr(e) {
1648
+ e ? Array.from(Ve.keys()).filter(
1649
+ (r) => r.startsWith(e)
1650
+ ).forEach((r) => Ve.delete(r)) : Ve.clear();
1651
+ }
1652
+ async function Br(e) {
1653
+ const t = `schema:${e}`, r = Ur(t);
1654
+ if (r)
1655
+ return r;
1656
+ const s = await Or(e);
1657
+ return kr(t, s, 30), s;
1658
+ }
1659
+ class _t {
1660
+ constructor(t = 1e3) {
1661
+ we(this, "cache", /* @__PURE__ */ new Map());
1662
+ we(this, "maxSize");
1663
+ this.maxSize = t;
1664
+ }
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;
1668
+ }
1669
+ set(t, r) {
1670
+ if (this.cache.has(t))
1671
+ this.cache.delete(t);
1672
+ else if (this.cache.size >= this.maxSize) {
1673
+ const s = this.cache.keys().next().value;
1674
+ this.cache.delete(s);
1675
+ }
1676
+ this.cache.set(t, r);
1677
+ }
1678
+ clear() {
1679
+ this.cache.clear();
1680
+ }
1681
+ }
1682
+ function Pr(e) {
1683
+ const t = /* @__PURE__ */ new Set();
1684
+ function r(s) {
1685
+ switch (s.Type) {
1686
+ case "Identifier":
1687
+ s.Name && !s.Name.startsWith("$") && t.add(s.Name);
1688
+ break;
1689
+ case "MemberExpression":
1690
+ s.Arguments && s.Arguments.forEach(r);
1691
+ break;
1692
+ case "CallExpression":
1693
+ case "BinaryExpression":
1694
+ case "LogicalExpression":
1695
+ s.Arguments && s.Arguments.forEach(r);
1696
+ break;
1697
+ }
1698
+ }
1699
+ return r(e), t;
1700
+ }
1701
+ class qr {
1702
+ constructor() {
1703
+ we(this, "resultCache", new _t(500));
1704
+ we(this, "dependencyCache", new _t(200));
1705
+ we(this, "compiledExpressions", /* @__PURE__ */ new Map());
1706
+ }
1707
+ /**
1708
+ * Create cache key from expression and context
1709
+ */
1710
+ createCacheKey(t, r) {
1711
+ const s = JSON.stringify(t), i = JSON.stringify(r);
1712
+ return `${s}:${i}`;
1713
+ }
1714
+ /**
1715
+ * Get expression dependencies (cached)
1716
+ */
1717
+ getDependencies(t) {
1718
+ const r = JSON.stringify(t);
1719
+ let s = this.dependencyCache.get(r);
1720
+ return s || (s = Pr(t), this.dependencyCache.set(r, s)), s;
1721
+ }
1722
+ /**
1723
+ * Check if expression result is cached and context hasn't changed
1724
+ */
1725
+ getCachedResult(t, r, s) {
1726
+ if (!s) return;
1727
+ const i = this.getDependencies(t);
1728
+ for (const l of i)
1729
+ if (r[l] !== s[l])
1730
+ return;
1731
+ const n = this.createCacheKey(t, r);
1732
+ return this.resultCache.get(n);
1733
+ }
1734
+ /**
1735
+ * Evaluate expression with caching
1736
+ */
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;
1743
+ }
1744
+ /**
1745
+ * Core expression evaluation logic
1746
+ */
1747
+ evaluateNode(t, r) {
1748
+ switch (t.Type) {
1749
+ case "Literal":
1750
+ return t.Value;
1751
+ case "Identifier":
1752
+ return this.getIdentifierValue(t, r);
1753
+ case "BinaryExpression":
1754
+ return this.evaluateBinaryExpression(t, r);
1755
+ case "LogicalExpression":
1756
+ return this.evaluateLogicalExpression(t, r);
1757
+ case "CallExpression":
1758
+ return this.evaluateCallExpression(t, r);
1759
+ case "MemberExpression":
1760
+ return this.evaluateMemberExpression(t, r);
1761
+ default:
1762
+ throw new Error(`Unsupported expression type: ${t.Type}`);
1763
+ }
1764
+ }
1765
+ /**
1766
+ * Get identifier value with system context support
1767
+ */
1768
+ getIdentifierValue(t, r) {
1769
+ if (t.Name) {
1770
+ if (t.Name === "NOW") return /* @__PURE__ */ new Date();
1771
+ if (t.Name === "TODAY") {
1772
+ const s = /* @__PURE__ */ new Date();
1773
+ return new Date(s.getFullYear(), s.getMonth(), s.getDate());
1774
+ }
1775
+ return t.Name === "CURRENT_USER_ID" ? 1 : t.Name === "CURRENT_USER" ? {
1776
+ EmpId: 1,
1777
+ Email: "user@example.com",
1778
+ FirstName: "John",
1779
+ LastName: "Doe",
1780
+ Role: "User"
1781
+ } : r[t.Name];
1782
+ }
1783
+ }
1784
+ /**
1785
+ * Evaluate binary expressions with type coercion
1786
+ */
1787
+ evaluateBinaryExpression(t, r) {
1788
+ if (!t.Arguments || t.Arguments.length !== 2)
1789
+ 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) {
1792
+ case "==":
1793
+ return s == i;
1794
+ case "!=":
1795
+ return s != i;
1796
+ case "===":
1797
+ return s === i;
1798
+ case "!==":
1799
+ return s !== i;
1800
+ case "<":
1801
+ return Number(s) < Number(i);
1802
+ case "<=":
1803
+ return Number(s) <= Number(i);
1804
+ case ">":
1805
+ return Number(s) > Number(i);
1806
+ case ">=":
1807
+ return Number(s) >= Number(i);
1808
+ case "+":
1809
+ return Number(s) + Number(i);
1810
+ case "-":
1811
+ return Number(s) - Number(i);
1812
+ case "*":
1813
+ return Number(s) * Number(i);
1814
+ case "/":
1815
+ return Number(s) / Number(i);
1816
+ case "%":
1817
+ return Number(s) % Number(i);
1818
+ default:
1819
+ throw new Error(`Unsupported binary operator: ${t.Operator}`);
1820
+ }
1821
+ }
1822
+ /**
1823
+ * Evaluate logical expressions with short-circuiting
1824
+ */
1825
+ evaluateLogicalExpression(t, r) {
1826
+ if (!t.Arguments || t.Arguments.length < 2)
1827
+ throw new Error("Logical expression requires at least 2 arguments");
1828
+ switch (t.Operator) {
1829
+ case "AND":
1830
+ for (const s of t.Arguments)
1831
+ if (!this.evaluateNode(s, r)) return !1;
1832
+ return !0;
1833
+ case "OR":
1834
+ for (const s of t.Arguments)
1835
+ if (this.evaluateNode(s, r)) return !0;
1836
+ return !1;
1837
+ default:
1838
+ throw new Error(`Unsupported logical operator: ${t.Operator}`);
1839
+ }
1840
+ }
1841
+ /**
1842
+ * Evaluate function calls with built-in functions
1843
+ */
1844
+ evaluateCallExpression(t, r) {
1845
+ var i;
1846
+ if (!t.Callee)
1847
+ 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) {
1850
+ case "CONCAT":
1851
+ return s.map((p) => String(p || "")).join("");
1852
+ case "TRIM":
1853
+ return String(s[0] || "").trim();
1854
+ case "LENGTH":
1855
+ return String(s[0] || "").length;
1856
+ case "UPPER":
1857
+ return String(s[0] || "").toUpperCase();
1858
+ case "LOWER":
1859
+ return String(s[0] || "").toLowerCase();
1860
+ case "CONTAINS":
1861
+ return String(s[0] || "").includes(String(s[1] || ""));
1862
+ case "MATCHES":
1863
+ return new RegExp(String(s[1])).test(String(s[0] || ""));
1864
+ case "SUM":
1865
+ return s.reduce((p, N) => p + (Number(N) || 0), 0);
1866
+ 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;
1869
+ case "MIN":
1870
+ return Math.min(...s.map((p) => Number(p) || 0));
1871
+ case "MAX":
1872
+ return Math.max(...s.map((p) => Number(p) || 0));
1873
+ case "ROUND":
1874
+ return Math.round(Number(s[0]) || 0);
1875
+ case "FLOOR":
1876
+ return Math.floor(Number(s[0]) || 0);
1877
+ case "CEIL":
1878
+ return Math.ceil(Number(s[0]) || 0);
1879
+ case "ABS":
1880
+ return Math.abs(Number(s[0]) || 0);
1881
+ case "YEAR":
1882
+ return new Date(s[0]).getFullYear();
1883
+ case "MONTH":
1884
+ return new Date(s[0]).getMonth() + 1;
1885
+ case "DAY":
1886
+ return new Date(s[0]).getDate();
1887
+ 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));
1890
+ case "IF":
1891
+ return s[0] ? s[1] : s[2];
1892
+ case "AUTO_NUMBER":
1893
+ return Math.floor(Math.random() * 1e4);
1894
+ default:
1895
+ throw new Error(`Unknown function: ${t.Callee}`);
1896
+ }
1897
+ }
1898
+ /**
1899
+ * Evaluate member expressions
1900
+ */
1901
+ evaluateMemberExpression(t, r) {
1902
+ var n;
1903
+ if (!t.Arguments || t.Arguments.length === 0)
1904
+ 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;
1907
+ }
1908
+ /**
1909
+ * Clear all caches
1910
+ */
1911
+ clearCache() {
1912
+ this.resultCache.clear(), this.dependencyCache.clear(), this.compiledExpressions.clear();
1913
+ }
1914
+ }
1915
+ const kt = new qr();
1916
+ function $r(e, t, r, s, i) {
1917
+ if (!r || r.length === 0)
1918
+ return { isValid: !0 };
1919
+ const n = { ...s, [e]: t };
1920
+ for (const l of r)
1921
+ try {
1922
+ if (!kt.evaluate(
1923
+ l.ExpressionTree,
1924
+ n,
1925
+ i
1926
+ ))
1927
+ return {
1928
+ isValid: !1,
1929
+ message: l.Message || `Validation failed for ${l.Name}`,
1930
+ fieldName: e
1931
+ };
1932
+ } catch (d) {
1933
+ console.warn(`Validation rule ${l.Id} failed to evaluate:`, d);
1934
+ }
1935
+ return { isValid: !0 };
1936
+ }
1937
+ function Dt(e) {
1938
+ return Array.from(kt.getDependencies(e));
1939
+ }
1940
+ function Qr(e) {
1941
+ const {
1942
+ source: t,
1943
+ operation: r,
1944
+ recordId: s,
1945
+ defaultValues: i = {},
1946
+ mode: n = "onBlur",
1947
+ // 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,
1952
+ 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]);
1958
+ 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),
1967
+ retry: 3,
1968
+ staleTime: 30 * 60 * 1e3,
1969
+ // 30 minutes - schemas don't change frequently
1970
+ gcTime: 60 * 60 * 1e3,
1971
+ // 1 hour - keep schemas in cache longer
1972
+ throwOnError: !1
1973
+ }), {
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,
1981
+ retry: 3,
1982
+ staleTime: 5 * 60 * 1e3,
1983
+ // 5 minutes - records can change more frequently
1984
+ gcTime: 15 * 60 * 1e3,
1985
+ // 15 minutes - keep records for a reasonable time
1986
+ 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({
1994
+ mode: n,
1995
+ defaultValues: i,
1996
+ values: r === "update" && z ? Me : void 0
1997
+ });
1998
+ $e(() => {
1999
+ var u;
2000
+ if (S)
2001
+ try {
2002
+ const o = Dr(
2003
+ S,
2004
+ {},
2005
+ // Pass empty object - validation functions get live values from react-hook-form
2006
+ d
2007
+ );
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);
2013
+ }
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)
2019
+ return;
2020
+ (async () => {
2021
+ he(!0), ne(null);
2022
+ try {
2023
+ const f = await pe(t).draftInteraction({});
2024
+ T(f._id), f && typeof f == "object" && Object.entries(f).forEach(([h, c]) => {
2025
+ if (h === "_id") return;
2026
+ A.getValues(h) !== c && A.setValue(h, c, {
2027
+ shouldDirty: !1,
2028
+ shouldValidate: !1
2029
+ });
2030
+ });
2031
+ } catch (o) {
2032
+ console.error("Failed to create initial draft:", o), ne(o);
2033
+ } finally {
2034
+ he(!1);
2035
+ }
2036
+ })();
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);
2046
+ });
2047
+ });
2048
+ }), m.computedFields.forEach((f) => {
2049
+ const h = m.fields[f];
2050
+ h._bdoField.Formula && Dt(
2051
+ h._bdoField.Formula.ExpressionTree
2052
+ ).forEach((y) => {
2053
+ m.fields[y] && y !== f && !o.has(y) && u.add(y);
2054
+ });
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) {
2060
+ console.warn("Interactive create mode: waiting for draft ID");
2061
+ return;
2062
+ }
2063
+ B.current || (le.current && clearTimeout(le.current), le.current = setTimeout(() => {
2064
+ if (!m || B.current)
2065
+ return;
2066
+ const f = A.getValues();
2067
+ (async () => {
2068
+ B.current = !0;
2069
+ 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 || []
2074
+ );
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);
2079
+ });
2080
+ const _ = y, P = {
2081
+ ...V.current
2082
+ };
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, {
2090
+ shouldDirty: !1,
2091
+ shouldValidate: !1
2092
+ });
2093
+ }
2094
+ ), Object.entries(W).forEach(
2095
+ ([q, J]) => {
2096
+ b.has(q) && (V.current[q] = J);
2097
+ }
2098
+ ));
2099
+ } catch (c) {
2100
+ console.warn("Failed to compute fields via API:", c);
2101
+ } finally {
2102
+ B.current = !1;
2103
+ }
2104
+ })();
2105
+ }, 300));
2106
+ }
2107
+ },
2108
+ [
2109
+ m,
2110
+ r,
2111
+ s,
2112
+ z,
2113
+ t,
2114
+ A,
2115
+ Ee,
2116
+ v,
2117
+ L
2118
+ ]
2119
+ ), Ye = te(async () => {
2120
+ if (!m)
2121
+ return !1;
2122
+ const u = A.getValues();
2123
+ if (!await A.trigger())
2124
+ 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}`
2130
+ })
2131
+ ), h = At(
2132
+ f,
2133
+ u,
2134
+ O
2135
+ );
2136
+ return h.length > 0 ? (h.forEach((c, y) => {
2137
+ A.setError(`root.crossField${y}`, {
2138
+ type: "validate",
2139
+ message: c.message
2140
+ });
2141
+ }), !1) : !0;
2142
+ }, [
2143
+ m,
2144
+ A.getValues,
2145
+ A.trigger,
2146
+ A.setError,
2147
+ O
2148
+ ]), Ie = te(
2149
+ (u, o) => A.handleSubmit(
2150
+ // 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);
2155
+ return;
2156
+ }
2157
+ x(!0);
2158
+ try {
2159
+ const c = m.crossFieldValidation.map(
2160
+ (_) => ({
2161
+ Id: _.Id,
2162
+ Condition: { ExpressionTree: _.ExpressionTree },
2163
+ Message: _.Message || `Validation failed for ${_.Name}`
2164
+ })
2165
+ ), y = At(
2166
+ c,
2167
+ f,
2168
+ O
2169
+ );
2170
+ if (y.length > 0) {
2171
+ y.forEach((_, P) => {
2172
+ A.setError(`root.crossField${P}`, {
2173
+ type: "validate",
2174
+ message: _.message
2175
+ });
2176
+ }), o == null || o(A.formState.errors, h);
2177
+ return;
2178
+ }
2179
+ const F = Ir(
2180
+ f,
2181
+ m.computedFields,
2182
+ r,
2183
+ z
2184
+ );
2185
+ let b;
2186
+ if (v) {
2187
+ const _ = pe(t);
2188
+ if (r === "create") {
2189
+ if (!L)
2190
+ throw new Error(
2191
+ "Interactive create mode requires a draft ID. Draft creation may have failed."
2192
+ );
2193
+ b = { success: !0, data: await _.draft({
2194
+ ...F,
2195
+ _id: L
2196
+ }) };
2197
+ } else
2198
+ b = { success: !0, data: await _.draftUpdate(s, F) };
2199
+ } else if (b = await Tr(
2200
+ t,
2201
+ r,
2202
+ F,
2203
+ 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);
2209
+ } finally {
2210
+ x(!1);
2211
+ }
2212
+ },
2213
+ // RHF onInvalid handler - validation failed
2214
+ (f, h) => {
2215
+ o == null || o(f, h);
2216
+ }
2217
+ ),
2218
+ [
2219
+ A,
2220
+ m,
2221
+ O,
2222
+ t,
2223
+ r,
2224
+ s,
2225
+ z,
2226
+ v,
2227
+ L
2228
+ ]
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]) => {
2261
+ const h = {};
2262
+ switch (f.required && (h.required = `${f.label} is required`), f.permission.editable || (h.disabled = !0), f.type) {
2263
+ case "number":
2264
+ h.valueAsNumber = !0;
2265
+ break;
2266
+ case "date":
2267
+ case "datetime-local":
2268
+ h.valueAsDate = !0;
2269
+ break;
2270
+ }
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
2284
+ );
2285
+ if (!P.isValid)
2286
+ return P.message || _.Message || "Invalid value";
2287
+ }
2288
+ }
2289
+ return !0;
2290
+ }
2291
+ }), u[o] = h;
2292
+ }), u;
2293
+ }, [m, A, O]);
2294
+ return {
2295
+ // 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);
2302
+ };
2303
+ return A.register(u, {
2304
+ ...f,
2305
+ ...o,
2306
+ onBlur: c
2307
+ });
2308
+ },
2309
+ [A, Re, Ae, n]
2310
+ ),
2311
+ handleSubmit: Ie,
2312
+ watch: A.watch,
2313
+ // Type assertion for complex generic constraints
2314
+ setValue: A.setValue,
2315
+ reset: A.reset,
2316
+ // 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,
2322
+ // Loading states
2323
+ isLoadingInitialData: Be,
2324
+ isLoadingRecord: ce,
2325
+ isLoading: Pe,
2326
+ // Interactive mode state
2327
+ draftId: L,
2328
+ isCreatingDraft: oe,
2329
+ // Error handling
2330
+ loadError: Se,
2331
+ hasError: Je,
2332
+ // Schema information
2333
+ schema: S,
2334
+ schemaConfig: m,
2335
+ computedFields: Ge,
2336
+ requiredFields: ut,
2337
+ // Field helpers
2338
+ getField: Ke,
2339
+ getFields: xe,
2340
+ hasField: ke,
2341
+ isFieldRequired: _e,
2342
+ isFieldComputed: De,
2343
+ // Operations
2344
+ refreshSchema: ze,
2345
+ validateForm: Ye,
2346
+ clearErrors: Ue
2347
+ };
2348
+ }
2349
+ export {
2350
+ Xr as clearFormCache,
2351
+ Jr as isNetworkError,
2352
+ Gr as isValidationError,
2353
+ zr as parseApiError,
2354
+ Qr as useForm
2355
+ };