@karni/ui 0.0.0-stage → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +288 -2
  3. package/dist/index.cjs +9 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.js +4764 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/manifest.json +85 -0
  8. package/dist/mockServiceWorker.js +361 -0
  9. package/dist/src/auth/AuthGuard.d.ts +12 -0
  10. package/dist/src/auth/LoginForm.d.ts +29 -0
  11. package/dist/src/auth/engine.d.ts +99 -0
  12. package/dist/src/auth/provider.d.ts +43 -0
  13. package/dist/src/auth/storage.d.ts +26 -0
  14. package/dist/src/auth/types.d.ts +32 -0
  15. package/dist/src/auth/usePermission.d.ts +7 -0
  16. package/dist/src/components/brand/karni-mark.d.ts +21 -0
  17. package/dist/src/components/brand/mark-paths.d.ts +8 -0
  18. package/dist/src/components/chart/data-chart.d.ts +74 -0
  19. package/dist/src/components/empty-state/empty-state.d.ts +20 -0
  20. package/dist/src/components/file-upload/FileUpload.d.ts +44 -0
  21. package/dist/src/components/layout/layout.d.ts +55 -0
  22. package/dist/src/components/modal/modal.d.ts +45 -0
  23. package/dist/src/components/page/page.d.ts +29 -0
  24. package/dist/src/components/primitives/button.d.ts +44 -0
  25. package/dist/src/components/primitives/checkbox.d.ts +5 -0
  26. package/dist/src/components/primitives/dropdown-menu.d.ts +24 -0
  27. package/dist/src/components/primitives/icons.d.ts +11 -0
  28. package/dist/src/components/primitives/input.d.ts +4 -0
  29. package/dist/src/components/primitives/label.d.ts +5 -0
  30. package/dist/src/components/primitives/select.d.ts +63 -0
  31. package/dist/src/components/primitives/skeleton.d.ts +4 -0
  32. package/dist/src/components/primitives/switch.d.ts +5 -0
  33. package/dist/src/components/primitives/tabs.d.ts +10 -0
  34. package/dist/src/components/primitives/textarea.d.ts +4 -0
  35. package/dist/src/components/resource/ResourceDetail.d.ts +7 -0
  36. package/dist/src/components/resource/ResourceForm.d.ts +7 -0
  37. package/dist/src/components/resource/ResourceSelect.d.ts +7 -0
  38. package/dist/src/components/resource/ResourceTable.d.ts +11 -0
  39. package/dist/src/components/resource/audit-fields.d.ts +17 -0
  40. package/dist/src/components/resource/detail/ResourceDetail.d.ts +30 -0
  41. package/dist/src/components/resource/displayLabel.d.ts +12 -0
  42. package/dist/src/components/resource/form/ResourceForm.d.ts +50 -0
  43. package/dist/src/components/resource/form/field-inputs.d.ts +20 -0
  44. package/dist/src/components/resource/form/fixtures.d.ts +24 -0
  45. package/dist/src/components/resource/form/prepare.d.ts +54 -0
  46. package/dist/src/components/resource/history/ChangeHistory.d.ts +18 -0
  47. package/dist/src/components/resource/import/ResourceImport.d.ts +18 -0
  48. package/dist/src/components/resource/select/ResourceSelect.d.ts +36 -0
  49. package/dist/src/components/resource/select/use-debounced-value.d.ts +2 -0
  50. package/dist/src/components/resource/table/BulkActionsBar.d.ts +20 -0
  51. package/dist/src/components/resource/table/ExportButtons.d.ts +17 -0
  52. package/dist/src/components/resource/table/FilterBar.d.ts +29 -0
  53. package/dist/src/components/resource/table/PaginationControls.d.ts +19 -0
  54. package/dist/src/components/resource/table/ResourceTable.d.ts +72 -0
  55. package/dist/src/components/resource/table/demo-fixtures.d.ts +25 -0
  56. package/dist/src/components/resource/table/derive-columns.d.ts +33 -0
  57. package/dist/src/components/resource/table/table-utils.d.ts +24 -0
  58. package/dist/src/components/resource/table/use-debounced-value.d.ts +1 -0
  59. package/dist/src/components/stat/stat.d.ts +24 -0
  60. package/dist/src/components/toast/toast-store.d.ts +36 -0
  61. package/dist/src/components/toast/toaster.d.ts +33 -0
  62. package/dist/src/components/toast/use-toast.d.ts +24 -0
  63. package/dist/src/hooks/keys.d.ts +24 -0
  64. package/dist/src/hooks/multipart.d.ts +44 -0
  65. package/dist/src/hooks/params.d.ts +25 -0
  66. package/dist/src/hooks/types.d.ts +41 -0
  67. package/dist/src/hooks/useChangeHistory.d.ts +29 -0
  68. package/dist/src/hooks/useResourceImport.d.ts +107 -0
  69. package/dist/src/hooks/useResourceItem.d.ts +4 -0
  70. package/dist/src/hooks/useResourceList.d.ts +4 -0
  71. package/dist/src/hooks/useResourceMutations.d.ts +13 -0
  72. package/dist/src/index.d.ts +95 -0
  73. package/dist/src/lib/cn.d.ts +8 -0
  74. package/dist/src/lib/roles.d.ts +45 -0
  75. package/dist/src/lib/variants.d.ts +33 -0
  76. package/dist/src/schema/client.d.ts +90 -0
  77. package/dist/src/schema/parse.d.ts +101 -0
  78. package/dist/src/schema/provider.d.ts +13 -0
  79. package/dist/src/schema/types.d.ts +84 -0
  80. package/dist/src/schema/useSchema.d.ts +17 -0
  81. package/dist/src/schema/zod.d.ts +4 -0
  82. package/dist/styles.css +87 -0
  83. package/dist/tailwind-preset.cjs +2 -0
  84. package/dist/tailwind-preset.cjs.map +1 -0
  85. package/dist/tailwind-preset.d.ts +58 -0
  86. package/dist/tailwind-preset.js +64 -0
  87. package/dist/tailwind-preset.js.map +1 -0
  88. package/eslint-plugin/index.js +72 -0
  89. package/eslint-plugin/lib/docs.js +11 -0
  90. package/eslint-plugin/lib/glob.js +51 -0
  91. package/eslint-plugin/rules/max-page-lines.js +65 -0
  92. package/eslint-plugin/rules/no-deep-imports.js +61 -0
  93. package/eslint-plugin/rules/no-direct-http.js +128 -0
  94. package/eslint-plugin/rules/no-raw-elements.js +65 -0
  95. package/eslint-plugin/rules.json +26 -0
  96. package/package.json +153 -4
package/dist/index.js ADDED
@@ -0,0 +1,4764 @@
1
+ var Hn = Object.defineProperty;
2
+ var Wn = (e, t, n) => t in e ? Hn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var G = (e, t, n) => Wn(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { clsx as Qn } from "clsx";
5
+ import { twMerge as Jn } from "tailwind-merge";
6
+ import { jsx as r, jsxs as d, Fragment as Q } from "react/jsx-runtime";
7
+ import * as m from "react";
8
+ import { useState as Zn, useContext as dn, createContext as mn, useCallback as Gn, useMemo as Xe, useEffect as Ft, useSyncExternalStore as Yn, useRef as Xn } from "react";
9
+ import * as ie from "@radix-ui/react-select";
10
+ import * as Pt from "@radix-ui/react-checkbox";
11
+ import * as Bt from "@radix-ui/react-switch";
12
+ import * as qn from "@radix-ui/react-label";
13
+ import * as et from "@radix-ui/react-tabs";
14
+ import * as fe from "@radix-ui/react-dropdown-menu";
15
+ import { QueryClient as In, QueryClientProvider as er, useQuery as _e, useQueryClient as tt, useMutation as $e, keepPreviousData as tr } from "@tanstack/react-query";
16
+ import { z } from "zod";
17
+ import * as ve from "@radix-ui/react-dialog";
18
+ import * as je from "@radix-ui/react-toast";
19
+ import * as nr from "@radix-ui/react-visually-hidden";
20
+ import { zodResolver as rr } from "@hookform/resolvers/zod";
21
+ import { Controller as ir, useForm as or, FormProvider as ar } from "react-hook-form";
22
+ import * as Ge from "@radix-ui/react-popover";
23
+ import { useReactTable as sr, getCoreRowModel as lr, flexRender as it } from "@tanstack/react-table";
24
+ function b(...e) {
25
+ return Jn(Qn(e));
26
+ }
27
+ const De = /* @__PURE__ */ new Map();
28
+ function cr() {
29
+ var e, t;
30
+ try {
31
+ const n = import.meta;
32
+ return !(!n.hot || ((e = n.env) == null ? void 0 : e.MODE) === "test" || typeof process < "u" && ((t = process.env) == null ? void 0 : t.VITEST) !== void 0);
33
+ } catch {
34
+ return !1;
35
+ }
36
+ }
37
+ let ur = cr;
38
+ function ee(e, t, n) {
39
+ var a;
40
+ if (n != null && n.replace) {
41
+ const s = ((a = n.reason) == null ? void 0 : a.trim()) ?? "";
42
+ if (s === "")
43
+ throw new Error(
44
+ `[karni] registerComponentRole: replacing role "${e}" requires a non-empty reason — pass { replace: true, reason: "<why>" }.`
45
+ );
46
+ const u = De.get(e);
47
+ u !== void 0 && u !== t && console.warn(
48
+ `[karni] component role "${e}" replaced: "${u}" -> "${t}" (${s})`
49
+ ), De.set(e, t);
50
+ return;
51
+ }
52
+ const i = De.get(e);
53
+ if (i === void 0 || i === t) {
54
+ De.set(e, t);
55
+ return;
56
+ }
57
+ const o = `[karni] duplicate component role "${e}": already registered by "${i}", now claimed by "${t}". Compose or extend the existing component instead, or replace it on purpose with { replace: true, reason: "<why>" }.`;
58
+ if (ur()) {
59
+ console.error(o), De.set(e, t);
60
+ return;
61
+ }
62
+ throw new Error(o);
63
+ }
64
+ function sa() {
65
+ return Object.freeze(Object.fromEntries(De));
66
+ }
67
+ function fn(e) {
68
+ const t = Object.keys(e.variants);
69
+ return (n) => {
70
+ var l;
71
+ const { className: i, ...o } = n ?? {}, a = o, s = {}, u = [];
72
+ e.base && u.push(e.base);
73
+ for (const c of t) {
74
+ const f = a[c] ?? ((l = e.defaultVariants) == null ? void 0 : l[c]);
75
+ if (f == null)
76
+ continue;
77
+ s[c] = f;
78
+ const g = e.variants[c][f];
79
+ g && u.push(g);
80
+ }
81
+ for (const c of e.compoundVariants ?? []) {
82
+ const { className: f, ...g } = c, x = g;
83
+ Object.keys(x).every((v) => {
84
+ const k = x[v];
85
+ return k != null && s[v] === k;
86
+ }) && u.push(f);
87
+ }
88
+ return b(...u, i);
89
+ };
90
+ }
91
+ const dr = fn({
92
+ base: "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
93
+ variants: {
94
+ variant: {
95
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
96
+ destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
97
+ outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
98
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
99
+ ghost: "hover:bg-accent hover:text-accent-foreground",
100
+ link: "text-primary underline-offset-4 hover:underline"
101
+ },
102
+ size: {
103
+ default: "h-10 px-4 py-2",
104
+ sm: "h-9 rounded-md px-3",
105
+ lg: "h-11 rounded-md px-8",
106
+ icon: "h-10 w-10"
107
+ }
108
+ },
109
+ defaultVariants: {
110
+ variant: "default",
111
+ size: "default"
112
+ }
113
+ }), Y = m.forwardRef(
114
+ ({ className: e, variant: t, size: n, type: i, ...o }, a) => /* @__PURE__ */ r(
115
+ "button",
116
+ {
117
+ ref: a,
118
+ type: i ?? "button",
119
+ className: dr({ variant: t, size: n, className: e }),
120
+ ...o
121
+ }
122
+ )
123
+ );
124
+ Y.displayName = "Button";
125
+ const we = m.forwardRef(
126
+ ({ className: e, ...t }, n) => /* @__PURE__ */ r(
127
+ "input",
128
+ {
129
+ ref: n,
130
+ className: b(
131
+ "flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
132
+ e
133
+ ),
134
+ ...t
135
+ }
136
+ )
137
+ );
138
+ we.displayName = "Input";
139
+ const ft = m.forwardRef(
140
+ ({ className: e, ...t }, n) => /* @__PURE__ */ r(
141
+ "textarea",
142
+ {
143
+ ref: n,
144
+ className: b(
145
+ "flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
146
+ e
147
+ ),
148
+ ...t
149
+ }
150
+ )
151
+ );
152
+ ft.displayName = "Textarea";
153
+ function Nt(e) {
154
+ return {
155
+ viewBox: "0 0 24 24",
156
+ fill: "none",
157
+ stroke: "currentColor",
158
+ strokeWidth: 2,
159
+ strokeLinecap: "round",
160
+ strokeLinejoin: "round",
161
+ "aria-hidden": !0,
162
+ focusable: !1,
163
+ ...e
164
+ };
165
+ }
166
+ function We(e) {
167
+ return /* @__PURE__ */ r("svg", { ...Nt(e), children: /* @__PURE__ */ r("polyline", { points: "20 6 9 17 4 12" }) });
168
+ }
169
+ function nt(e) {
170
+ return /* @__PURE__ */ r("svg", { ...Nt(e), children: /* @__PURE__ */ r("polyline", { points: "6 9 12 15 18 9" }) });
171
+ }
172
+ function hn(e) {
173
+ return /* @__PURE__ */ r("svg", { ...Nt(e), children: /* @__PURE__ */ r("polyline", { points: "18 15 12 9 6 15" }) });
174
+ }
175
+ const Ue = "__karni_empty__", mr = ie.Root, la = ie.Group, fr = ie.Value, gn = m.forwardRef(({ className: e, children: t, ...n }, i) => /* @__PURE__ */ d(
176
+ ie.Trigger,
177
+ {
178
+ ref: i,
179
+ className: b(
180
+ "flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
181
+ e
182
+ ),
183
+ ...n,
184
+ children: [
185
+ t,
186
+ /* @__PURE__ */ r(ie.Icon, { asChild: !0, children: /* @__PURE__ */ r(nt, { className: "h-4 w-4 shrink-0 opacity-50" }) })
187
+ ]
188
+ }
189
+ ));
190
+ gn.displayName = "SelectTrigger";
191
+ const pn = m.forwardRef(({ className: e, ...t }, n) => /* @__PURE__ */ r(
192
+ ie.ScrollUpButton,
193
+ {
194
+ ref: n,
195
+ className: b("flex cursor-default items-center justify-center py-1", e),
196
+ ...t,
197
+ children: /* @__PURE__ */ r(hn, { className: "h-4 w-4" })
198
+ }
199
+ ));
200
+ pn.displayName = "SelectScrollUpButton";
201
+ const bn = m.forwardRef(({ className: e, ...t }, n) => /* @__PURE__ */ r(
202
+ ie.ScrollDownButton,
203
+ {
204
+ ref: n,
205
+ className: b("flex cursor-default items-center justify-center py-1", e),
206
+ ...t,
207
+ children: /* @__PURE__ */ r(nt, { className: "h-4 w-4" })
208
+ }
209
+ ));
210
+ bn.displayName = "SelectScrollDownButton";
211
+ const yn = m.forwardRef(({ className: e, children: t, position: n = "popper", ...i }, o) => /* @__PURE__ */ r(ie.Portal, { children: /* @__PURE__ */ d(
212
+ ie.Content,
213
+ {
214
+ ref: o,
215
+ position: n,
216
+ className: b(
217
+ "relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border border-border bg-popover text-popover-foreground shadow-md",
218
+ n === "popper" && "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
219
+ e
220
+ ),
221
+ ...i,
222
+ children: [
223
+ /* @__PURE__ */ r(pn, {}),
224
+ /* @__PURE__ */ r(
225
+ ie.Viewport,
226
+ {
227
+ className: b(
228
+ "p-1",
229
+ n === "popper" && "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
230
+ ),
231
+ children: t
232
+ }
233
+ ),
234
+ /* @__PURE__ */ r(bn, {})
235
+ ]
236
+ }
237
+ ) }));
238
+ yn.displayName = "SelectContent";
239
+ const hr = m.forwardRef(({ className: e, ...t }, n) => /* @__PURE__ */ r(
240
+ ie.Label,
241
+ {
242
+ ref: n,
243
+ className: b("py-1.5 pl-8 pr-2 text-sm font-semibold", e),
244
+ ...t
245
+ }
246
+ ));
247
+ hr.displayName = "SelectLabel";
248
+ const ht = m.forwardRef(({ className: e, children: t, ...n }, i) => /* @__PURE__ */ d(
249
+ ie.Item,
250
+ {
251
+ ref: i,
252
+ className: b(
253
+ "relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
254
+ e
255
+ ),
256
+ ...n,
257
+ children: [
258
+ /* @__PURE__ */ r("span", { className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center", children: /* @__PURE__ */ r(ie.ItemIndicator, { children: /* @__PURE__ */ r(We, { className: "h-4 w-4" }) }) }),
259
+ /* @__PURE__ */ r(ie.ItemText, { children: t })
260
+ ]
261
+ }
262
+ ));
263
+ ht.displayName = "SelectItem";
264
+ const gr = m.forwardRef(({ className: e, ...t }, n) => /* @__PURE__ */ r(
265
+ ie.Separator,
266
+ {
267
+ ref: n,
268
+ className: b("-mx-1 my-1 h-px bg-muted", e),
269
+ ...t
270
+ }
271
+ ));
272
+ gr.displayName = "SelectSeparator";
273
+ const Qe = m.forwardRef((e, t) => {
274
+ const {
275
+ value: n,
276
+ onValueChange: i,
277
+ options: o,
278
+ placeholder: a,
279
+ clearable: s = !1,
280
+ clearLabel: u = "—",
281
+ disabled: l,
282
+ name: c,
283
+ id: f,
284
+ className: g,
285
+ contentClassName: x,
286
+ children: L,
287
+ "aria-label": T
288
+ } = e, v = m.useMemo(() => {
289
+ const S = o.filter(
290
+ (j) => j.value !== "" && j.value !== Ue
291
+ );
292
+ return S.length !== o.length && console.warn(
293
+ `[karni-ui] <Select> option values "" and "${Ue}" are reserved; those options were dropped. Use the \`clearable\` prop for an empty choice.`
294
+ ), S;
295
+ }, [o]), h = n == null || n === "" ? s ? Ue : "" : n, w = m.useCallback(
296
+ (S) => {
297
+ i == null || i(S === Ue ? null : S);
298
+ },
299
+ [i]
300
+ );
301
+ return /* @__PURE__ */ d(
302
+ mr,
303
+ {
304
+ value: h,
305
+ onValueChange: w,
306
+ disabled: l,
307
+ name: c,
308
+ children: [
309
+ /* @__PURE__ */ r(gn, { ref: t, id: f, className: g, "aria-label": T, children: /* @__PURE__ */ r(fr, { placeholder: a }) }),
310
+ /* @__PURE__ */ d(yn, { className: x, children: [
311
+ s ? /* @__PURE__ */ r(ht, { value: Ue, className: "text-muted-foreground", children: u }) : null,
312
+ v.map((S) => /* @__PURE__ */ r(ht, { value: S.value, disabled: S.disabled, children: S.label }, S.value)),
313
+ L
314
+ ] })
315
+ ]
316
+ }
317
+ );
318
+ });
319
+ Qe.displayName = "Select";
320
+ const gt = m.forwardRef(({ className: e, ...t }, n) => /* @__PURE__ */ r(
321
+ Pt.Root,
322
+ {
323
+ ref: n,
324
+ className: b(
325
+ "peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
326
+ e
327
+ ),
328
+ ...t,
329
+ children: /* @__PURE__ */ r(Pt.Indicator, { className: "flex items-center justify-center text-current", children: /* @__PURE__ */ r(We, { className: "h-3.5 w-3.5" }) })
330
+ }
331
+ ));
332
+ gt.displayName = "Checkbox";
333
+ const xn = m.forwardRef(
334
+ ({ className: e, ...t }, n) => /* @__PURE__ */ r(
335
+ Bt.Root,
336
+ {
337
+ ref: n,
338
+ className: b(
339
+ "peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
340
+ e
341
+ ),
342
+ ...t,
343
+ children: /* @__PURE__ */ r(Bt.Thumb, { className: "pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0" })
344
+ }
345
+ )
346
+ );
347
+ xn.displayName = "Switch";
348
+ const qe = m.forwardRef(
349
+ ({ className: e, ...t }, n) => /* @__PURE__ */ r(
350
+ qn.Root,
351
+ {
352
+ ref: n,
353
+ className: b(
354
+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
355
+ e
356
+ ),
357
+ ...t
358
+ }
359
+ )
360
+ );
361
+ qe.displayName = "Label";
362
+ const ca = et.Root, pr = m.forwardRef(({ className: e, ...t }, n) => /* @__PURE__ */ r(
363
+ et.List,
364
+ {
365
+ ref: n,
366
+ className: b(
367
+ "inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
368
+ e
369
+ ),
370
+ ...t
371
+ }
372
+ ));
373
+ pr.displayName = "TabsList";
374
+ const br = m.forwardRef(({ className: e, ...t }, n) => /* @__PURE__ */ r(
375
+ et.Trigger,
376
+ {
377
+ ref: n,
378
+ className: b(
379
+ "inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
380
+ e
381
+ ),
382
+ ...t
383
+ }
384
+ ));
385
+ br.displayName = "TabsTrigger";
386
+ const yr = m.forwardRef(({ className: e, ...t }, n) => /* @__PURE__ */ r(
387
+ et.Content,
388
+ {
389
+ ref: n,
390
+ className: b(
391
+ "mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
392
+ e
393
+ ),
394
+ ...t
395
+ }
396
+ ));
397
+ yr.displayName = "TabsContent";
398
+ const ua = fe.Root, da = fe.Trigger, ma = fe.Group, fa = fe.Portal, xr = m.forwardRef(({ className: e, sideOffset: t = 4, ...n }, i) => /* @__PURE__ */ r(fe.Portal, { children: /* @__PURE__ */ r(
399
+ fe.Content,
400
+ {
401
+ ref: i,
402
+ sideOffset: t,
403
+ className: b(
404
+ "z-50 min-w-[8rem] overflow-hidden rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md",
405
+ e
406
+ ),
407
+ ...n
408
+ }
409
+ ) }));
410
+ xr.displayName = "DropdownMenuContent";
411
+ const vr = m.forwardRef(({ className: e, inset: t, ...n }, i) => /* @__PURE__ */ r(
412
+ fe.Item,
413
+ {
414
+ ref: i,
415
+ className: b(
416
+ "relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
417
+ t && "pl-8",
418
+ e
419
+ ),
420
+ ...n
421
+ }
422
+ ));
423
+ vr.displayName = "DropdownMenuItem";
424
+ const wr = m.forwardRef(({ className: e, children: t, checked: n, ...i }, o) => /* @__PURE__ */ d(
425
+ fe.CheckboxItem,
426
+ {
427
+ ref: o,
428
+ checked: n,
429
+ className: b(
430
+ "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
431
+ e
432
+ ),
433
+ ...i,
434
+ children: [
435
+ /* @__PURE__ */ r("span", { className: "absolute left-2 flex h-3.5 w-3.5 items-center justify-center", children: /* @__PURE__ */ r(fe.ItemIndicator, { children: /* @__PURE__ */ r(We, { className: "h-4 w-4" }) }) }),
436
+ t
437
+ ]
438
+ }
439
+ ));
440
+ wr.displayName = "DropdownMenuCheckboxItem";
441
+ const Nr = m.forwardRef(({ className: e, inset: t, ...n }, i) => /* @__PURE__ */ r(
442
+ fe.Label,
443
+ {
444
+ ref: i,
445
+ className: b("px-2 py-1.5 text-sm font-semibold", t && "pl-8", e),
446
+ ...n
447
+ }
448
+ ));
449
+ Nr.displayName = "DropdownMenuLabel";
450
+ const Sr = m.forwardRef(({ className: e, ...t }, n) => /* @__PURE__ */ r(
451
+ fe.Separator,
452
+ {
453
+ ref: n,
454
+ className: b("-mx-1 my-1 h-px bg-muted", e),
455
+ ...t
456
+ }
457
+ ));
458
+ Sr.displayName = "DropdownMenuSeparator";
459
+ const me = m.forwardRef(
460
+ ({ className: e, ...t }, n) => /* @__PURE__ */ r("div", { ref: n, className: b("animate-pulse rounded-md bg-muted", e), ...t })
461
+ );
462
+ me.displayName = "Skeleton";
463
+ function _t(e) {
464
+ return typeof e == "string" ? e : String(e);
465
+ }
466
+ function kr(e) {
467
+ return Array.isArray(e);
468
+ }
469
+ function St(e) {
470
+ const t = {};
471
+ if (e === void 0) return t;
472
+ if (e.filters !== void 0)
473
+ for (const [n, i] of Object.entries(e.filters))
474
+ i != null && (kr(i) ? i.length > 0 && (t[n] = i.map(_t)) : t[n] = _t(i));
475
+ return e.page !== void 0 && (t.page = String(e.page)), e.pageSize !== void 0 && (t.page_size = String(e.pageSize)), e.ordering !== void 0 && e.ordering !== "" && (t.ordering = e.ordering), e.search !== void 0 && e.search !== "" && (t.search = e.search), e.expand !== void 0 && e.expand.length > 0 && (t.expand = e.expand.join(",")), t;
476
+ }
477
+ function vn(e) {
478
+ const t = {};
479
+ return (e == null ? void 0 : e.expand) !== void 0 && e.expand.length > 0 && (t.expand = e.expand.join(",")), t;
480
+ }
481
+ function pt(e) {
482
+ const t = {};
483
+ for (const n of Object.keys(e).sort()) {
484
+ const i = Cr(e[n]);
485
+ i !== void 0 && (t[n] = i);
486
+ }
487
+ return t;
488
+ }
489
+ function Cr(e) {
490
+ if (e != null)
491
+ return Array.isArray(e) ? e.filter((t) => t != null).map(
492
+ (t) => typeof t == "object" && t !== null ? JSON.stringify(t) : String(t)
493
+ ) : typeof e == "object" ? pt(e) : String(e);
494
+ }
495
+ function Je(e) {
496
+ return `/${e.replace(/^\/+|\/+$/g, "")}/`;
497
+ }
498
+ function Ie(e, t) {
499
+ return `${Je(e)}${encodeURIComponent(String(t))}/`;
500
+ }
501
+ const he = {
502
+ /** Cache key of the parsed OpenAPI schema document. */
503
+ schema() {
504
+ return ["karni", "$schema"];
505
+ },
506
+ /**
507
+ * The invalidation root for one resource — every list and detail key of
508
+ * `resource` lives under this prefix.
509
+ */
510
+ resource(e) {
511
+ return ["karni", e];
512
+ },
513
+ /**
514
+ * Key for one list page. Params are normalized (D4): undefined/null
515
+ * dropped, keys sorted recursively, values stringified as they hit the
516
+ * query string — `{search: "x", page: 2}` and `{page: 2, search: "x"}`
517
+ * share one entry.
518
+ */
519
+ list(e, t) {
520
+ return ["karni", e, "list", pt(St(t))];
521
+ },
522
+ /**
523
+ * Key for one item. The id is always stringified, so `detail("events", 5)`
524
+ * and `detail("events", "5")` share one entry. Params (expand) append a
525
+ * normalized fifth element — see the module docs.
526
+ */
527
+ detail(e, t, n) {
528
+ const i = vn(n);
529
+ return Object.keys(i).length > 0 ? ["karni", e, "detail", String(t), pt(i)] : ["karni", e, "detail", String(t)];
530
+ }
531
+ }, wn = mn(null);
532
+ function ha(e) {
533
+ const { client: t, queryClient: n, children: i } = e, [o] = Zn(() => n ?? new In());
534
+ return /* @__PURE__ */ r(er, { client: n ?? o, children: /* @__PURE__ */ r(wn.Provider, { value: t, children: i }) });
535
+ }
536
+ function ge() {
537
+ const e = dn(wn);
538
+ if (e === null)
539
+ throw new Error(
540
+ "useKarniClient must be used within <KarniProvider>. Wrap your app in <KarniProvider client={createKarniClient({ baseUrl })}>."
541
+ );
542
+ return e;
543
+ }
544
+ function Nn(e, t, n) {
545
+ const i = ge();
546
+ return _e({
547
+ ...n,
548
+ queryKey: he.list(e, t),
549
+ queryFn: ({ signal: o }) => i.request(Je(e), { query: St(t), signal: o })
550
+ });
551
+ }
552
+ function bt(e) {
553
+ return typeof File < "u" && e instanceof File;
554
+ }
555
+ function Ar(e) {
556
+ return typeof Blob < "u" && e instanceof Blob;
557
+ }
558
+ function Rr(e) {
559
+ return Object.values(e).some(
560
+ (t) => bt(t) || Array.isArray(t) && t.some((n) => bt(n))
561
+ );
562
+ }
563
+ function Vt(e, t, n) {
564
+ if (n != null) {
565
+ if (bt(n) || Ar(n)) {
566
+ e.append(t, n);
567
+ return;
568
+ }
569
+ if (typeof n == "object") {
570
+ e.append(t, JSON.stringify(n));
571
+ return;
572
+ }
573
+ e.append(t, String(n));
574
+ }
575
+ }
576
+ function Tr(e) {
577
+ const t = new FormData();
578
+ for (const [n, i] of Object.entries(e))
579
+ if (i != null)
580
+ if (Array.isArray(i))
581
+ for (const o of i) Vt(t, n, o);
582
+ else
583
+ Vt(t, n, i);
584
+ return t;
585
+ }
586
+ function zt(e) {
587
+ return Rr(e) ? Tr(e) : e;
588
+ }
589
+ function Lr(e, t) {
590
+ const n = /* @__PURE__ */ new Set();
591
+ if (typeof e != "object" || e === null) return n;
592
+ const i = e.resources;
593
+ if (typeof i != "object" || i === null) return n;
594
+ const o = i[t];
595
+ if (typeof o != "object" || o === null) return n;
596
+ const a = o.fields;
597
+ if (!Array.isArray(a)) return n;
598
+ for (const s of a) {
599
+ if (typeof s != "object" || s === null) continue;
600
+ const { name: u, kind: l } = s;
601
+ typeof u == "string" && l === "file" && n.add(u);
602
+ }
603
+ return n;
604
+ }
605
+ function Er(e) {
606
+ return typeof e == "string" ? !0 : Array.isArray(e) && e.every((t) => typeof t == "string");
607
+ }
608
+ function Mr(e, t) {
609
+ if (t.size === 0) return e;
610
+ const n = {};
611
+ for (const [i, o] of Object.entries(e))
612
+ t.has(i) && Er(o) || (n[i] = o);
613
+ return n;
614
+ }
615
+ function Sn(e, t) {
616
+ const n = ge(), i = tt(), o = t == null ? void 0 : t.invalidateKeys, a = Gn(async () => {
617
+ await i.invalidateQueries({ queryKey: he.resource(e) }), o !== void 0 && await Promise.all(
618
+ o.map((c) => i.invalidateQueries({ queryKey: c }))
619
+ );
620
+ }, [i, e, o]), s = $e({
621
+ mutationFn: (c) => n.request(Je(e), { method: "POST", body: zt(c) }),
622
+ onSuccess: () => a()
623
+ }), u = $e({
624
+ mutationFn: ({ id: c, values: f }) => {
625
+ const g = Lr(i.getQueryData(he.schema()), e), x = Mr(f, g);
626
+ return n.request(Ie(e, c), {
627
+ method: "PATCH",
628
+ body: zt(x)
629
+ });
630
+ },
631
+ onSuccess: () => a()
632
+ }), l = $e({
633
+ mutationFn: async (c) => {
634
+ await n.request(Ie(e, c), { method: "DELETE" });
635
+ },
636
+ onSuccess: () => a()
637
+ });
638
+ return { create: s, update: u, remove: l };
639
+ }
640
+ function X(e) {
641
+ return typeof e == "object" && e !== null && !Array.isArray(e);
642
+ }
643
+ function kn(e) {
644
+ const t = e.replace(/[_-]+/g, " ").trim();
645
+ return t.length === 0 ? e : t.charAt(0).toUpperCase() + t.slice(1);
646
+ }
647
+ const Ut = "#/components/schemas/";
648
+ function jr(e, t) {
649
+ var n, i;
650
+ if (t.startsWith(Ut))
651
+ return (i = (n = e.components) == null ? void 0 : n.schemas) == null ? void 0 : i[t.slice(Ut.length)];
652
+ }
653
+ function le(e, t, n = []) {
654
+ if (t !== void 0) {
655
+ if (typeof t.$ref == "string") {
656
+ if (n.includes(t.$ref)) return {};
657
+ const i = jr(e, t.$ref);
658
+ if (i === void 0) return {};
659
+ const o = le(e, i, [...n, t.$ref]) ?? {}, a = { ...t };
660
+ return delete a.$ref, { ...o, ...a };
661
+ }
662
+ if (Array.isArray(t.allOf) && t.allOf.length === 1) {
663
+ const i = le(e, t.allOf[0], n) ?? {}, o = { ...t };
664
+ return delete o.allOf, { ...i, ...o };
665
+ }
666
+ return t;
667
+ }
668
+ }
669
+ function Cn(e) {
670
+ return Array.isArray(e.type) ? { type: e.type.filter((n) => n !== "null")[0], nullable: e.type.includes("null") || e.nullable === !0 } : {
671
+ type: typeof e.type == "string" ? e.type : void 0,
672
+ nullable: e.nullable === !0
673
+ };
674
+ }
675
+ function Dr(e) {
676
+ const t = e["x-karni-relation"];
677
+ if (X(t) && typeof t.resource == "string" && t.resource.length > 0)
678
+ return { resource: t.resource, many: t.many === !0 };
679
+ }
680
+ function ot(e) {
681
+ const { type: t } = Cn(e);
682
+ return t === "integer" || t === "number" ? "integer" : e.format === "uuid" ? "uuid" : "string";
683
+ }
684
+ function $r(e, t, n) {
685
+ const i = [];
686
+ let o = !1, a;
687
+ for (const s of t) {
688
+ const u = le(e, s, n);
689
+ if (u === void 0 || !Array.isArray(u.enum)) return;
690
+ a === void 0 && u.description !== void 0 && i.length === 0 && (a = u.description);
691
+ for (const l of u.enum)
692
+ l === null ? o = !0 : l !== "" && i.push(l);
693
+ }
694
+ return { values: i, nullable: o, description: a };
695
+ }
696
+ const Or = /^\* `(.+?)` - (.*)$/;
697
+ function Fr(e) {
698
+ if (e === void 0) return {};
699
+ const t = {}, n = [];
700
+ for (const o of e.split(`
701
+ `)) {
702
+ const a = Or.exec(o.trim());
703
+ a !== null && a[1] !== void 0 && a[2] !== void 0 ? t[a[1]] = a[2].trim() : n.push(o);
704
+ }
705
+ const i = n.join(`
706
+ `).trim();
707
+ return {
708
+ ...Object.keys(t).length > 0 ? { labels: t } : {},
709
+ ...i !== "" ? { rest: i } : {}
710
+ };
711
+ }
712
+ function Kt(e, t) {
713
+ const { labels: n, rest: i } = Fr(t);
714
+ n !== void 0 && (e.enumLabels = n), e.description = i;
715
+ }
716
+ function Pr(e) {
717
+ return e.type === void 0 && e.enum === void 0 && e.properties === void 0 && e.items === void 0 && e.oneOf === void 0 && e.anyOf === void 0 && e.allOf === void 0 && e.$ref === void 0;
718
+ }
719
+ function at(e, t) {
720
+ const n = le(e, t) ?? {}, i = Dr(n), { type: o, nullable: a } = Cn(n), s = {
721
+ kind: "unknown",
722
+ nullable: a,
723
+ format: n.format,
724
+ description: n.description,
725
+ title: n.title,
726
+ default: n.default,
727
+ readOnly: n.readOnly === !0,
728
+ writeOnly: n.writeOnly === !0,
729
+ maxLength: n.maxLength,
730
+ min: n.minimum,
731
+ max: n.maximum,
732
+ relation: i,
733
+ binary: !1
734
+ }, u = n.oneOf ?? n.anyOf;
735
+ if (Array.isArray(u)) {
736
+ const l = $r(e, u, []);
737
+ return l !== void 0 && (s.kind = "enum", s.enumValues = l.values, s.nullable = s.nullable || l.nullable, Kt(s, n.description ?? l.description)), s;
738
+ }
739
+ if (Array.isArray(n.enum))
740
+ return s.kind = "enum", s.nullable = s.nullable || n.enum.includes(null), s.enumValues = n.enum.filter(
741
+ (l) => l !== null && l !== ""
742
+ ), Kt(s, n.description), s;
743
+ if (i !== void 0 && !i.many)
744
+ return s.kind = "relation", s.relationValueType = ot(n), s;
745
+ switch (o) {
746
+ case "string":
747
+ return n.format === "binary" ? (s.kind = "file", s.binary = !0) : n.format === "date" ? s.kind = "date" : n.format === "date-time" ? s.kind = "datetime" : n.format === void 0 && n.maxLength === void 0 ? s.kind = "text" : s.kind = "string", s;
748
+ case "integer":
749
+ return s.kind = "integer", s;
750
+ case "number":
751
+ return s.kind = "number", s;
752
+ case "boolean":
753
+ return s.kind = "boolean", s;
754
+ case "array": {
755
+ if (i !== void 0) {
756
+ s.kind = "relation";
757
+ const l = le(e, n.items) ?? {};
758
+ s.relationValueType = ot(l);
759
+ } else
760
+ s.kind = "array";
761
+ return s;
762
+ }
763
+ case "object":
764
+ return s.kind = "json", s;
765
+ default:
766
+ return i !== void 0 ? (s.kind = "relation", s.relationValueType = ot(n)) : Pr(n) && (s.kind = "json"), s;
767
+ }
768
+ }
769
+ function Ht(e, t, n, i, o, a) {
770
+ let s;
771
+ (n == null ? void 0 : n.binary) === !0 ? s = "file" : n !== void 0 && n.kind !== "unknown" ? s = n.kind : t !== void 0 && t.kind !== "unknown" ? s = t.kind : s = "unknown";
772
+ const u = (n == null ? void 0 : n.relation) ?? (t == null ? void 0 : t.relation), l = (n == null ? void 0 : n.title) ?? (t == null ? void 0 : t.title), c = {
773
+ name: e,
774
+ label: l !== void 0 && l.length > 0 ? l : kn(e),
775
+ kind: s,
776
+ required: i.has(e),
777
+ readOnly: !o || (t == null ? void 0 : t.readOnly) === !0 || (n == null ? void 0 : n.readOnly) === !0 || o && t !== void 0 && n === void 0,
778
+ writeOnly: (n == null ? void 0 : n.writeOnly) === !0 || (t == null ? void 0 : t.writeOnly) === !0 || t === void 0 && n !== void 0,
779
+ // Write-facing: a file is a nullable URL on the way out and a plain upload
780
+ // on the way in, and only the request side says what a form may send.
781
+ nullable: n !== void 0 ? n.nullable : (t == null ? void 0 : t.nullable) ?? !1,
782
+ order: a
783
+ }, f = (n == null ? void 0 : n.enumValues) ?? (t == null ? void 0 : t.enumValues), g = (n == null ? void 0 : n.default) ?? (t == null ? void 0 : t.default);
784
+ g !== void 0 && (c.default = g), f !== void 0 && (c.enumValues = f);
785
+ const x = (n == null ? void 0 : n.enumLabels) ?? (t == null ? void 0 : t.enumLabels);
786
+ x !== void 0 && (c.enumLabels = x);
787
+ const L = (n == null ? void 0 : n.maxLength) ?? (t == null ? void 0 : t.maxLength);
788
+ L !== void 0 && (c.maxLength = L);
789
+ const T = (n == null ? void 0 : n.min) ?? (t == null ? void 0 : t.min);
790
+ T !== void 0 && (c.min = T);
791
+ const v = (n == null ? void 0 : n.max) ?? (t == null ? void 0 : t.max);
792
+ v !== void 0 && (c.max = v);
793
+ const k = (n == null ? void 0 : n.format) ?? (t == null ? void 0 : t.format);
794
+ k !== void 0 && (c.format = k);
795
+ const h = (t == null ? void 0 : t.description) ?? (n == null ? void 0 : n.description);
796
+ if (h !== void 0 && (c.description = h), u !== void 0) {
797
+ c.relation = u;
798
+ const w = (n == null ? void 0 : n.relationValueType) ?? (t == null ? void 0 : t.relationValueType);
799
+ w !== void 0 && (c.relationValueType = w);
800
+ }
801
+ return c;
802
+ }
803
+ function ke(e, t, n, i) {
804
+ const o = [];
805
+ let a;
806
+ for (const u of i.parameters ?? [])
807
+ if (!(!X(u) || u.in !== "query" || typeof u.name != "string") && (o.push(u.name), u.name === "expand")) {
808
+ const l = le(e, u.schema), c = le(e, l == null ? void 0 : l.items), f = (l == null ? void 0 : l.enum) ?? (c == null ? void 0 : c.enum);
809
+ Array.isArray(f) && (a = f.filter((g) => typeof g == "string"));
810
+ }
811
+ const s = {
812
+ path: t,
813
+ method: n,
814
+ queryParams: o,
815
+ hasSearch: o.includes("search")
816
+ };
817
+ return typeof i.operationId == "string" && (s.operationId = i.operationId), a !== void 0 && (s.expandEnum = a), s;
818
+ }
819
+ function Br(e, t) {
820
+ var s, u, l, c;
821
+ const n = ((s = t.responses) == null ? void 0 : s["200"]) ?? ((u = t.responses) == null ? void 0 : u["201"]) ?? Object.values(t.responses ?? {})[0], i = (l = n == null ? void 0 : n.content) == null ? void 0 : l["application/json"], o = le(e, i == null ? void 0 : i.schema);
822
+ if (o === void 0) return;
823
+ const a = le(e, (c = o.properties) == null ? void 0 : c.results);
824
+ return a !== void 0 && a.type === "array" ? le(e, a.items) : o.type === "array" ? le(e, o.items) : o;
825
+ }
826
+ function _r(e, t) {
827
+ var o;
828
+ const n = (o = t.requestBody) == null ? void 0 : o.content;
829
+ if (!X(n)) return;
830
+ const i = n["application/json"] ?? n["multipart/form-data"] ?? Object.values(n)[0];
831
+ return le(e, i == null ? void 0 : i.schema);
832
+ }
833
+ const Vr = ["get", "post", "put", "patch", "delete"];
834
+ function zr(e) {
835
+ const t = X(e) ? e : {}, n = X(t.paths) ? t.paths : {}, i = {}, o = t["x-karni-auth-mode"], a = o === "jwt" || o === "session" ? o : void 0, s = [];
836
+ for (const [l, c] of Object.entries(n)) {
837
+ if (!X(c)) continue;
838
+ const f = c.get;
839
+ X(f) && typeof f["x-karni-resource"] == "string" && s.push({ resource: f["x-karni-resource"], path: l, item: c });
840
+ }
841
+ for (const { resource: l, path: c, item: f } of s) {
842
+ const g = f.get;
843
+ if (!X(g)) continue;
844
+ const x = Object.entries(n).find(([N]) => {
845
+ if (!N.startsWith(c)) return !1;
846
+ const F = N.slice(c.length);
847
+ return /^\{[^/{}]+\}\/?$/.test(F);
848
+ }), L = x == null ? void 0 : x[0], T = x !== void 0 && X(x[1]) ? x[1] : void 0, v = {
849
+ list: ke(t, c, "get", g)
850
+ }, k = X(f.post) ? f.post : void 0;
851
+ k !== void 0 && (v.create = ke(t, c, "post", k));
852
+ const h = n[`${c}export/`], w = X(h) && X(h.get) ? h.get : void 0;
853
+ w !== void 0 && (v.export = ke(t, `${c}export/`, "get", w));
854
+ const S = n[`${c}import/`], j = X(S) && X(S.post) ? S.post : void 0;
855
+ if (j !== void 0 && (v.import = ke(t, `${c}import/`, "post", j)), L !== void 0 && T !== void 0)
856
+ for (const N of Vr) {
857
+ const F = T[N];
858
+ X(F) && (N === "get" ? v.detail = ke(t, L, "get", F) : N === "patch" ? v.update = ke(t, L, "patch", F) : N === "put" && v.update === void 0 ? v.update = ke(t, L, "put", F) : N === "delete" && (v.remove = ke(t, L, "delete", F)));
859
+ }
860
+ const B = Br(t, g), y = k !== void 0 ? _r(t, k) : void 0, C = y !== void 0, O = X(B == null ? void 0 : B.properties) ? B.properties : {}, V = X(y == null ? void 0 : y.properties) ? y.properties : {}, K = new Set(
861
+ Array.isArray(y == null ? void 0 : y.required) ? y.required : []
862
+ ), $ = [];
863
+ let E = 0;
864
+ for (const [N, F] of Object.entries(O)) {
865
+ const _ = at(t, F), P = V[N], J = P !== void 0 ? at(t, P) : void 0;
866
+ $.push(
867
+ Ht(N, _, J, K, C, E)
868
+ ), E += 1;
869
+ }
870
+ for (const [N, F] of Object.entries(V)) {
871
+ if (N in O) continue;
872
+ const _ = at(t, F);
873
+ $.push(Ht(N, void 0, _, K, C, E)), E += 1;
874
+ }
875
+ i[l] = { resource: l, operations: v, fields: $ };
876
+ }
877
+ const u = { resources: i };
878
+ return a !== void 0 && (u.authMode = a), u;
879
+ }
880
+ const Ur = ["karni", "$schema"];
881
+ function Kr() {
882
+ const e = ge();
883
+ return _e({
884
+ queryKey: Ur,
885
+ staleTime: 1 / 0,
886
+ queryFn: async () => zr(await e.request(e.schemaUrl))
887
+ });
888
+ }
889
+ function kt(e) {
890
+ const t = Kr();
891
+ if (t.data !== void 0) {
892
+ const n = t.data.resources[e];
893
+ if (n === void 0) {
894
+ const i = Object.keys(t.data.resources).sort();
895
+ throw new Error(
896
+ `Unknown resource "${e}". Known resources: ${i.length > 0 ? i.join(", ") : "(none — does the schema expose x-karni-resource?)"}.`
897
+ );
898
+ }
899
+ return { data: n, isLoading: !1, error: t.error };
900
+ }
901
+ return { data: void 0, isLoading: t.isPending, error: t.error };
902
+ }
903
+ ee("empty-state", "EmptyState");
904
+ const yt = m.forwardRef(
905
+ ({ icon: e, title: t, description: n, action: i, className: o, children: a, ...s }, u) => /* @__PURE__ */ d(
906
+ "div",
907
+ {
908
+ ref: u,
909
+ className: b(
910
+ "flex w-full flex-col items-center justify-center gap-2 rounded-lg border border-dashed border-border bg-background px-6 py-12 text-center",
911
+ o
912
+ ),
913
+ ...s,
914
+ children: [
915
+ e != null && /* @__PURE__ */ r("div", { "aria-hidden": "true", className: "mb-2 text-muted-foreground [&>svg]:h-10 [&>svg]:w-10", children: e }),
916
+ /* @__PURE__ */ r("h3", { className: "text-base font-semibold text-foreground", children: t }),
917
+ n != null && /* @__PURE__ */ r("p", { className: "max-w-sm text-sm text-muted-foreground", children: n }),
918
+ i != null && /* @__PURE__ */ r("div", { className: "mt-3 flex items-center gap-2", children: i }),
919
+ a
920
+ ]
921
+ }
922
+ )
923
+ );
924
+ yt.displayName = "EmptyState";
925
+ const xt = Object.freeze([
926
+ "id",
927
+ "created_at",
928
+ "updated_at",
929
+ "created_by",
930
+ "updated_by"
931
+ ]);
932
+ function Ct(e) {
933
+ return e.readOnly && xt.includes(e.name);
934
+ }
935
+ function At(e) {
936
+ const t = [], n = [];
937
+ for (const i of e)
938
+ (Ct(i) ? n : t).push(i);
939
+ return n.sort((i, o) => xt.indexOf(i.name) - xt.indexOf(o.name)), { domain: t, audit: n };
940
+ }
941
+ const Hr = ["name", "title", "label", "email", "str"];
942
+ function Oe(e) {
943
+ for (const n of Hr) {
944
+ const i = e[n];
945
+ if (typeof i == "string" && i.trim().length > 0) return i;
946
+ }
947
+ const t = e.id;
948
+ return t != null ? String(t) : "";
949
+ }
950
+ function Wr(e) {
951
+ const { selectedIds: t, bulkActions: n, onClear: i, className: o } = e;
952
+ return /* @__PURE__ */ d(
953
+ "div",
954
+ {
955
+ role: "toolbar",
956
+ "aria-label": "Bulk actions",
957
+ className: b(
958
+ "flex flex-wrap items-center gap-2 rounded-md border border-border bg-muted px-3 py-2",
959
+ o
960
+ ),
961
+ children: [
962
+ /* @__PURE__ */ d("p", { className: "text-sm font-medium text-foreground", children: [
963
+ t.length,
964
+ " selected"
965
+ ] }),
966
+ /* @__PURE__ */ r(Y, { variant: "ghost", size: "sm", onClick: i, children: "Clear" }),
967
+ /* @__PURE__ */ r("div", { className: "ml-auto flex flex-wrap items-center gap-2", children: n.map((a, s) => /* @__PURE__ */ r(
968
+ Y,
969
+ {
970
+ variant: a.destructive === !0 ? "destructive" : "outline",
971
+ size: "sm",
972
+ onClick: () => a.onClick([...t]),
973
+ children: a.label
974
+ },
975
+ s
976
+ )) })
977
+ ]
978
+ }
979
+ );
980
+ }
981
+ function Qr(e) {
982
+ if (e.length !== 0)
983
+ return e.map((t) => t.desc ? `-${t.id}` : t.id).join(",");
984
+ }
985
+ function Wt(e) {
986
+ return typeof e == "object" && e !== null && "status" in e && e.status === 404;
987
+ }
988
+ function Jr(e, t) {
989
+ return e === void 0 || e <= 0 || t <= 0 ? 1 : Math.max(1, Math.ceil(e / t));
990
+ }
991
+ function Ze(e) {
992
+ return typeof e == "object" && e !== null && !Array.isArray(e) ? e : {};
993
+ }
994
+ function Zr(e) {
995
+ if (typeof e == "object" && e !== null) {
996
+ const t = e.data;
997
+ if (typeof t == "object" && t !== null) {
998
+ const i = t.detail;
999
+ if (typeof i == "string" && i.length > 0) return i;
1000
+ }
1001
+ const n = e.message;
1002
+ if (typeof n == "string" && n.length > 0) return n;
1003
+ }
1004
+ return "Something went wrong while loading this table.";
1005
+ }
1006
+ function An(e, t) {
1007
+ const n = t == null ? void 0 : t[String(e)];
1008
+ if (n !== void 0) return n;
1009
+ if (typeof e == "number") return String(e);
1010
+ if (/^[A-Za-z0-9_ ]+$/.test(e) && (e === e.toUpperCase() || e === e.toLowerCase())) {
1011
+ const o = e.toLowerCase().replace(/_+/g, " ").trim();
1012
+ return o.length === 0 ? e : o.charAt(0).toUpperCase() + o.slice(1);
1013
+ }
1014
+ return e;
1015
+ }
1016
+ const Gr = /* @__PURE__ */ new Set(["json", "file", "unknown"]), Yr = /* @__PURE__ */ new Set([
1017
+ "relation",
1018
+ "json",
1019
+ "file",
1020
+ "array",
1021
+ "unknown"
1022
+ ]);
1023
+ function Be() {
1024
+ return /* @__PURE__ */ r("span", { "aria-hidden": "true", className: "text-muted-foreground", children: "–" });
1025
+ }
1026
+ function Xr({ value: e }) {
1027
+ return e ? /* @__PURE__ */ d("span", { className: "inline-flex items-center text-foreground", children: [
1028
+ /* @__PURE__ */ r(We, { className: "h-4 w-4" }),
1029
+ /* @__PURE__ */ r("span", { className: "sr-only", children: "Yes" })
1030
+ ] }) : /* @__PURE__ */ d("span", { className: "inline-flex items-center text-muted-foreground", children: [
1031
+ /* @__PURE__ */ r("span", { "aria-hidden": "true", children: "–" }),
1032
+ /* @__PURE__ */ r("span", { className: "sr-only", children: "No" })
1033
+ ] });
1034
+ }
1035
+ function qr({ value: e }) {
1036
+ return /* @__PURE__ */ r("code", { className: "rounded bg-muted px-1 py-0.5 text-xs", children: String(e) });
1037
+ }
1038
+ function Qt(e, t) {
1039
+ return e == null ? /* @__PURE__ */ r(Be, {}) : typeof e == "object" && !Array.isArray(e) ? t(Ze(e)) : /* @__PURE__ */ r(qr, { value: e });
1040
+ }
1041
+ function Ir({ value: e, label: t }) {
1042
+ return e == null ? /* @__PURE__ */ r(Be, {}) : Array.isArray(e) ? e.length === 0 ? /* @__PURE__ */ r(Be, {}) : /* @__PURE__ */ r("span", { className: "inline-flex flex-wrap items-center gap-x-2 gap-y-1", children: e.map((n, i) => /* @__PURE__ */ r(m.Fragment, { children: Qt(n, t) }, i)) }) : /* @__PURE__ */ r(Q, { children: Qt(e, t) });
1043
+ }
1044
+ function Jt(e, t) {
1045
+ const n = new Date(String(e));
1046
+ return Number.isNaN(n.getTime()) ? String(e) : t ? n.toLocaleString() : n.toLocaleDateString();
1047
+ }
1048
+ function ei({ value: e }) {
1049
+ if (typeof e == "string" && e.length > 0) {
1050
+ const t = e.split("/").filter(Boolean).pop() ?? e;
1051
+ return /* @__PURE__ */ r(
1052
+ "a",
1053
+ {
1054
+ href: e,
1055
+ target: "_blank",
1056
+ rel: "noreferrer",
1057
+ className: "text-primary underline underline-offset-4",
1058
+ onClick: (n) => n.stopPropagation(),
1059
+ children: t
1060
+ }
1061
+ );
1062
+ }
1063
+ return typeof File < "u" && e instanceof File ? /* @__PURE__ */ r(Q, { children: e.name }) : /* @__PURE__ */ r(Be, {});
1064
+ }
1065
+ function ti({ value: e }) {
1066
+ let t;
1067
+ try {
1068
+ t = JSON.stringify(e) ?? String(e);
1069
+ } catch {
1070
+ t = String(e);
1071
+ }
1072
+ const n = t.length > 80 ? `${t.slice(0, 80)}…` : t;
1073
+ return /* @__PURE__ */ r("code", { className: "rounded bg-muted px-1 py-0.5 text-xs", title: t, children: n });
1074
+ }
1075
+ function ni(e, t, n) {
1076
+ if (t == null) return /* @__PURE__ */ r(Be, {});
1077
+ switch (e.kind) {
1078
+ case "boolean":
1079
+ return /* @__PURE__ */ r(Xr, { value: t === !0 });
1080
+ case "date":
1081
+ return Jt(t, !1);
1082
+ case "datetime":
1083
+ return Jt(t, !0);
1084
+ case "enum":
1085
+ return typeof t == "string" || typeof t == "number" ? An(t, e.enumLabels) : String(t);
1086
+ case "relation":
1087
+ return /* @__PURE__ */ r(Ir, { value: t, label: n ?? Oe });
1088
+ case "number":
1089
+ case "integer":
1090
+ return /* @__PURE__ */ r("span", { className: "tabular-nums", children: typeof t == "number" ? t.toLocaleString() : String(t) });
1091
+ case "file":
1092
+ return /* @__PURE__ */ r(ei, { value: t });
1093
+ case "json":
1094
+ return /* @__PURE__ */ r(ti, { value: t });
1095
+ case "array":
1096
+ return Array.isArray(t) ? t.map((i) => String(i)).join(", ") : String(t);
1097
+ case "text":
1098
+ return /* @__PURE__ */ r("span", { className: "block max-w-xs truncate", title: String(t), children: String(t) });
1099
+ default:
1100
+ return String(t);
1101
+ }
1102
+ }
1103
+ function Rn(e) {
1104
+ return typeof e == "string" ? e : () => e;
1105
+ }
1106
+ function ri(e, t, n) {
1107
+ const i = t == null ? void 0 : t.cell;
1108
+ return {
1109
+ id: e.name,
1110
+ accessorFn: (o) => Ze(o)[e.name],
1111
+ header: Rn((t == null ? void 0 : t.header) ?? e.label),
1112
+ cell: i !== void 0 ? (o) => i(o.row.original) : (o) => ni(e, o.getValue(), n),
1113
+ enableSorting: (t == null ? void 0 : t.sortable) ?? !Yr.has(e.kind)
1114
+ };
1115
+ }
1116
+ function ii(e) {
1117
+ const t = new Map(
1118
+ (e.columns ?? []).map((a) => [a.field, a])
1119
+ ), n = [], { domain: i, audit: o } = At(e.fields);
1120
+ for (const a of [...i, ...o]) {
1121
+ const s = t.get(a.name);
1122
+ t.delete(a.name), (s == null ? void 0 : s.hidden) !== !0 && (s === void 0 && (a.writeOnly || Gr.has(a.kind) || e.showAuditFields !== !0 && Ct(a)) || n.push(ri(a, s, e.getRowLabel)));
1123
+ }
1124
+ for (const [a, s] of t) {
1125
+ if (s.hidden === !0) continue;
1126
+ const u = s.cell;
1127
+ n.push({
1128
+ id: a,
1129
+ accessorFn: (l) => Ze(l)[a],
1130
+ header: Rn(s.header ?? kn(a)),
1131
+ cell: u !== void 0 ? (l) => u(l.row.original) : (l) => {
1132
+ const c = l.getValue();
1133
+ return c == null ? /* @__PURE__ */ r(Be, {}) : String(c);
1134
+ },
1135
+ enableSorting: s.sortable ?? !1
1136
+ });
1137
+ }
1138
+ return n;
1139
+ }
1140
+ function Tn(e) {
1141
+ return [...he.resource(e), "import", "describe"];
1142
+ }
1143
+ function Ln(e, t) {
1144
+ return [...he.resource(e), "import", "job", t];
1145
+ }
1146
+ function Fe(e, t = "") {
1147
+ return `${Je(e)}import/${t}`;
1148
+ }
1149
+ const oi = /* @__PURE__ */ new Set(["previewing", "committing"]);
1150
+ function En(e) {
1151
+ return e !== void 0 && oi.has(e.status);
1152
+ }
1153
+ function Mn(e, t) {
1154
+ const n = e.headers.get("content-disposition") ?? "", i = /filename="?([^";]+)"?/i.exec(n);
1155
+ return (i == null ? void 0 : i[1]) ?? t;
1156
+ }
1157
+ async function ai(e, t, n, i = "csv") {
1158
+ const o = { ...St(n), format: i };
1159
+ delete o.page, delete o.page_size;
1160
+ const a = await e.requestRaw(`${Je(t)}export/`, { query: o }), s = await a.blob(), u = Mn(a, `${t}.${i}`);
1161
+ return jn(s, u), u;
1162
+ }
1163
+ function jn(e, t) {
1164
+ if (typeof document > "u" || typeof URL.createObjectURL != "function") return;
1165
+ const n = URL.createObjectURL(e), i = document.createElement("a");
1166
+ i.href = n, i.download = t, document.body.appendChild(i), i.click(), i.remove(), URL.revokeObjectURL(n);
1167
+ }
1168
+ async function si(e, t, n = "xlsx") {
1169
+ const i = await e.requestRaw(Fe(t, "template/"), {
1170
+ query: { format: n }
1171
+ }), o = await i.blob(), a = Mn(i, `${t}-template.${n}`);
1172
+ return jn(o, a), a;
1173
+ }
1174
+ function li(e, t) {
1175
+ const n = ge();
1176
+ return _e({
1177
+ ...t,
1178
+ queryKey: Tn(e),
1179
+ queryFn: ({ signal: i }) => n.request(Fe(e), { signal: i })
1180
+ });
1181
+ }
1182
+ function ci(e, t, n) {
1183
+ const i = ge(), o = (n == null ? void 0 : n.pollMs) ?? 1500;
1184
+ return _e({
1185
+ queryKey: Ln(e, t ?? ""),
1186
+ enabled: t !== void 0,
1187
+ queryFn: ({ signal: a }) => i.request(Fe(e, `${encodeURIComponent(t ?? "")}/`), {
1188
+ signal: a
1189
+ }),
1190
+ refetchInterval: (a) => En(a.state.data) ? o : !1
1191
+ });
1192
+ }
1193
+ function ui(e) {
1194
+ const t = ge(), n = tt(), i = (u) => (n.setQueryData(Ln(e, u.id), u), u), o = $e({
1195
+ mutationFn: async ({ file: u, mapping: l }) => {
1196
+ const c = new FormData();
1197
+ return c.append("file", u), l !== void 0 && c.append("mapping", JSON.stringify(l)), i(
1198
+ await t.request(Fe(e), { method: "POST", body: c })
1199
+ );
1200
+ }
1201
+ }), a = $e({
1202
+ mutationFn: async ({ jobId: u, mapping: l }) => i(
1203
+ await t.request(
1204
+ Fe(e, `${encodeURIComponent(u)}/preview/`),
1205
+ {
1206
+ method: "POST",
1207
+ body: { mapping: l }
1208
+ }
1209
+ )
1210
+ ),
1211
+ onSuccess: () => {
1212
+ n.invalidateQueries({ queryKey: Tn(e) });
1213
+ }
1214
+ }), s = $e({
1215
+ mutationFn: async (u) => i(
1216
+ await t.request(
1217
+ Fe(e, `${encodeURIComponent(u)}/commit/`),
1218
+ {
1219
+ method: "POST",
1220
+ body: {}
1221
+ }
1222
+ )
1223
+ ),
1224
+ onSuccess: (u) => {
1225
+ u.status === "done" && n.invalidateQueries({ queryKey: he.resource(e) });
1226
+ }
1227
+ });
1228
+ return { upload: o, preview: a, commit: s };
1229
+ }
1230
+ function di(e) {
1231
+ if (e instanceof Error) {
1232
+ const t = e.data;
1233
+ if (typeof t == "object" && t !== null && "detail" in t) {
1234
+ const n = t.detail;
1235
+ if (typeof n == "string") return n;
1236
+ }
1237
+ return e.message;
1238
+ }
1239
+ return "The export failed.";
1240
+ }
1241
+ function mi({
1242
+ resource: e,
1243
+ params: t,
1244
+ formats: n
1245
+ }) {
1246
+ const i = ge(), [o, a] = m.useState(null), [s, u] = m.useState(null), l = (c) => {
1247
+ a(c), u(null), ai(i, e, t, c).catch((f) => u(di(f))).finally(() => a(null));
1248
+ };
1249
+ return /* @__PURE__ */ d("div", { className: "flex items-center gap-2", "data-testid": "resource-table-export", children: [
1250
+ n.map((c) => /* @__PURE__ */ r(
1251
+ Y,
1252
+ {
1253
+ type: "button",
1254
+ variant: "outline",
1255
+ size: "sm",
1256
+ disabled: o !== null,
1257
+ onClick: () => l(c),
1258
+ "aria-label": `Export as ${c.toUpperCase()}`,
1259
+ children: o === c ? "Exporting…" : `Export ${c.toUpperCase()}`
1260
+ },
1261
+ c
1262
+ )),
1263
+ s !== null && /* @__PURE__ */ r("span", { role: "alert", className: "text-sm text-destructive", children: s })
1264
+ ] });
1265
+ }
1266
+ function Rt(e, t, n, i) {
1267
+ const o = ge();
1268
+ return _e({
1269
+ ...i,
1270
+ queryKey: he.detail(e, t, n),
1271
+ queryFn: ({ signal: a }) => o.request(Ie(e, t), { query: vn(n), signal: a })
1272
+ });
1273
+ }
1274
+ function fi(e, t) {
1275
+ const [n, i] = m.useState(e);
1276
+ return m.useEffect(() => {
1277
+ if (t <= 0) {
1278
+ i(e);
1279
+ return;
1280
+ }
1281
+ const o = setTimeout(() => i(e), t);
1282
+ return () => clearTimeout(o);
1283
+ }, [e, t]), n;
1284
+ }
1285
+ ee("async-select", "ResourceSelect");
1286
+ function st(e) {
1287
+ const t = e.id;
1288
+ return typeof t == "string" || typeof t == "number" ? t : String(t);
1289
+ }
1290
+ function Zt(e, t) {
1291
+ return `${e}-option-${t}`;
1292
+ }
1293
+ function Gt(e) {
1294
+ return /* @__PURE__ */ d(
1295
+ "svg",
1296
+ {
1297
+ viewBox: "0 0 24 24",
1298
+ fill: "none",
1299
+ stroke: "currentColor",
1300
+ strokeWidth: 2,
1301
+ strokeLinecap: "round",
1302
+ strokeLinejoin: "round",
1303
+ "aria-hidden": "true",
1304
+ focusable: !1,
1305
+ ...e,
1306
+ children: [
1307
+ /* @__PURE__ */ r("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
1308
+ /* @__PURE__ */ r("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
1309
+ ]
1310
+ }
1311
+ );
1312
+ }
1313
+ function Dn(e) {
1314
+ var Te;
1315
+ const {
1316
+ resource: t,
1317
+ value: n,
1318
+ onChange: i,
1319
+ multiple: o = !1,
1320
+ disabled: a = !1,
1321
+ placeholder: s,
1322
+ getOptionLabel: u,
1323
+ filter: l,
1324
+ id: c,
1325
+ className: f,
1326
+ pageSize: g,
1327
+ clearable: x = !0,
1328
+ searchDebounceMs: L = 300
1329
+ } = e, T = m.useId(), v = c ?? T, k = `${v}-listbox`, [h, w] = m.useState(!1), [S, j] = m.useState(""), [B, y] = m.useState(0), [C, O] = m.useState({}), V = m.useRef(null), K = m.useRef(null), $ = m.useRef(null), E = fi(S.trim(), L), N = m.useMemo(() => n == null ? [] : Array.isArray(n) ? n : [n], [n]), F = m.useMemo(() => {
1330
+ const p = { page: 1 };
1331
+ return g !== void 0 && (p.pageSize = g), E !== "" && (p.search = E), l !== void 0 && (p.filters = l), p;
1332
+ }, [g, E, l]), _ = Nn(t, F, { enabled: h && !a }), P = ((Te = _.data) == null ? void 0 : Te.results) ?? [];
1333
+ m.useEffect(() => {
1334
+ var R;
1335
+ const p = (R = _.data) == null ? void 0 : R.results;
1336
+ p === void 0 || p.length === 0 || O((U) => {
1337
+ let te = !1;
1338
+ const Le = { ...U };
1339
+ for (const xe of p) {
1340
+ const Ve = String(st(xe));
1341
+ Ve in Le || (Le[Ve] = xe, te = !0);
1342
+ }
1343
+ return te ? Le : U;
1344
+ });
1345
+ }, [_.data]);
1346
+ const J = N.find((p) => !(String(p) in C)), oe = Rt(t, J ?? "", void 0, {
1347
+ enabled: J !== void 0 && !a,
1348
+ retry: !1
1349
+ }), se = oe.data, Ce = oe.error;
1350
+ m.useEffect(() => {
1351
+ J !== void 0 && (se !== void 0 ? O((p) => ({ ...p, [String(J)]: se })) : Ce != null && O((p) => ({ ...p, [String(J)]: { id: J } })));
1352
+ }, [J, se, Ce]);
1353
+ const Me = m.useCallback(
1354
+ (p) => u !== void 0 ? u(p) : Oe(p),
1355
+ [u]
1356
+ ), Ae = m.useCallback(
1357
+ (p) => {
1358
+ const R = C[String(p)];
1359
+ if (R === void 0) return String(p);
1360
+ const U = u !== void 0 ? u(R) : Oe(R);
1361
+ return typeof U == "string" ? U : typeof U == "number" ? String(U) : Oe(R);
1362
+ },
1363
+ [C, u]
1364
+ ), pe = m.useCallback(() => {
1365
+ a || (j(""), y(0), w(!0));
1366
+ }, [a]), q = m.useCallback(() => {
1367
+ w(!1), j("");
1368
+ }, []), ye = m.useCallback(
1369
+ (p) => N.some((R) => String(R) === String(p)),
1370
+ [N]
1371
+ ), ce = (p) => {
1372
+ const R = st(p);
1373
+ if (O(
1374
+ (U) => String(R) in U ? U : { ...U, [String(R)]: p }
1375
+ ), o) {
1376
+ const U = ye(R) ? N.filter((te) => String(te) !== String(R)) : [...N, R];
1377
+ i([...U]);
1378
+ } else
1379
+ i(R), q();
1380
+ }, Ne = () => {
1381
+ var p;
1382
+ i(null), j(""), (p = $.current) == null || p.focus();
1383
+ }, A = !o && N.length > 0 ? Ae(N[0]) : "", D = h ? S : o ? "" : A, be = (p) => {
1384
+ const R = p.target.value;
1385
+ if (!h) {
1386
+ if (a) return;
1387
+ y(0), w(!0), j(
1388
+ A !== "" && R.startsWith(A) ? R.slice(A.length) : R
1389
+ );
1390
+ return;
1391
+ }
1392
+ y(0), j(R);
1393
+ }, W = (p) => {
1394
+ if (!a)
1395
+ switch (p.key) {
1396
+ case "ArrowDown":
1397
+ p.preventDefault(), h ? P.length > 0 && y((R) => (R + 1) % P.length) : pe();
1398
+ break;
1399
+ case "ArrowUp":
1400
+ p.preventDefault(), h ? P.length > 0 && y((R) => (R - 1 + P.length) % P.length) : pe();
1401
+ break;
1402
+ case "Enter":
1403
+ if (h) {
1404
+ p.preventDefault();
1405
+ const R = P[B];
1406
+ R !== void 0 && ce(R);
1407
+ }
1408
+ break;
1409
+ case "Escape":
1410
+ h && (p.preventDefault(), p.stopPropagation(), q());
1411
+ break;
1412
+ case "Backspace":
1413
+ o && S === "" && N.length > 0 && i([...N.slice(0, -1)]);
1414
+ break;
1415
+ case "Tab":
1416
+ h && q();
1417
+ break;
1418
+ }
1419
+ }, I = (p) => {
1420
+ var U, te;
1421
+ const R = p.relatedTarget;
1422
+ R !== null && (((U = V.current) == null ? void 0 : U.contains(R)) === !0 || ((te = K.current) == null ? void 0 : te.contains(R)) === !0) || h && q();
1423
+ }, Re = _.isLoading ? /* @__PURE__ */ r("div", { className: "px-2 py-1.5 text-sm text-muted-foreground", children: "Loading…" }) : _.error != null ? /* @__PURE__ */ r("div", { role: "alert", className: "px-2 py-1.5 text-sm text-destructive", children: "Failed to load options." }) : P.length === 0 ? /* @__PURE__ */ r("div", { className: "px-2 py-1.5 text-sm text-muted-foreground", children: "No results" }) : P.map((p, R) => {
1424
+ const U = st(p), te = ye(U);
1425
+ return /* @__PURE__ */ d(
1426
+ "div",
1427
+ {
1428
+ id: Zt(k, R),
1429
+ role: "option",
1430
+ "aria-selected": te,
1431
+ "data-highlighted": R === B ? "true" : void 0,
1432
+ className: "flex cursor-default select-none items-center justify-between gap-2 rounded-sm px-2 py-1.5 text-sm outline-none data-[highlighted=true]:bg-accent data-[highlighted=true]:text-accent-foreground",
1433
+ onMouseDown: (Le) => Le.preventDefault(),
1434
+ onMouseMove: () => y(R),
1435
+ onClick: () => ce(p),
1436
+ children: [
1437
+ /* @__PURE__ */ r("span", { className: "truncate", children: Me(p) }),
1438
+ te ? /* @__PURE__ */ r(We, { className: "h-4 w-4 shrink-0" }) : null
1439
+ ]
1440
+ },
1441
+ String(U)
1442
+ );
1443
+ });
1444
+ return /* @__PURE__ */ d(
1445
+ Ge.Root,
1446
+ {
1447
+ open: h,
1448
+ onOpenChange: (p) => {
1449
+ p || q();
1450
+ },
1451
+ modal: !1,
1452
+ children: [
1453
+ /* @__PURE__ */ r(Ge.Anchor, { asChild: !0, children: /* @__PURE__ */ d(
1454
+ "div",
1455
+ {
1456
+ ref: V,
1457
+ onClick: () => {
1458
+ var p;
1459
+ a || ((p = $.current) == null || p.focus(), h || pe());
1460
+ },
1461
+ className: b(
1462
+ "flex min-h-10 w-full flex-wrap items-center gap-1.5 rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
1463
+ a && "cursor-not-allowed opacity-50",
1464
+ f
1465
+ ),
1466
+ children: [
1467
+ o ? N.map((p) => {
1468
+ const R = Ae(p);
1469
+ return /* @__PURE__ */ d(
1470
+ "span",
1471
+ {
1472
+ className: "inline-flex items-center gap-1 rounded-sm bg-secondary px-1.5 py-0.5 text-xs text-secondary-foreground",
1473
+ children: [
1474
+ R,
1475
+ a ? null : /* @__PURE__ */ r(
1476
+ "button",
1477
+ {
1478
+ type: "button",
1479
+ "aria-label": `Remove ${R}`,
1480
+ className: "rounded-sm opacity-70 hover:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
1481
+ onClick: (U) => {
1482
+ U.stopPropagation(), i([...N.filter((te) => String(te) !== String(p))]);
1483
+ },
1484
+ children: /* @__PURE__ */ r(Gt, { className: "h-3 w-3" })
1485
+ }
1486
+ )
1487
+ ]
1488
+ },
1489
+ String(p)
1490
+ );
1491
+ }) : null,
1492
+ /* @__PURE__ */ r(
1493
+ "input",
1494
+ {
1495
+ ref: $,
1496
+ id: v,
1497
+ type: "text",
1498
+ role: "combobox",
1499
+ "aria-expanded": h,
1500
+ "aria-controls": k,
1501
+ "aria-autocomplete": "list",
1502
+ "aria-activedescendant": h && P.length > 0 ? Zt(k, B) : void 0,
1503
+ "aria-label": e["aria-label"],
1504
+ "aria-labelledby": e["aria-labelledby"],
1505
+ autoComplete: "off",
1506
+ disabled: a,
1507
+ placeholder: N.length === 0 ? s : void 0,
1508
+ value: D,
1509
+ onChange: be,
1510
+ onKeyDown: W,
1511
+ onClick: () => {
1512
+ h || pe();
1513
+ },
1514
+ onBlur: I,
1515
+ className: "min-w-16 flex-1 bg-transparent outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
1516
+ }
1517
+ ),
1518
+ x && N.length > 0 && !a ? /* @__PURE__ */ r(
1519
+ "button",
1520
+ {
1521
+ type: "button",
1522
+ "aria-label": "Clear selection",
1523
+ className: "rounded-sm p-0.5 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
1524
+ onMouseDown: (p) => p.preventDefault(),
1525
+ onClick: (p) => {
1526
+ p.stopPropagation(), Ne();
1527
+ },
1528
+ children: /* @__PURE__ */ r(Gt, { className: "h-4 w-4" })
1529
+ }
1530
+ ) : null,
1531
+ /* @__PURE__ */ r(nt, { className: "h-4 w-4 shrink-0 opacity-50" })
1532
+ ]
1533
+ }
1534
+ ) }),
1535
+ /* @__PURE__ */ r(Ge.Portal, { children: /* @__PURE__ */ r(
1536
+ Ge.Content,
1537
+ {
1538
+ ref: K,
1539
+ side: "bottom",
1540
+ align: "start",
1541
+ sideOffset: 4,
1542
+ onOpenAutoFocus: (p) => p.preventDefault(),
1543
+ onCloseAutoFocus: (p) => p.preventDefault(),
1544
+ onInteractOutside: (p) => {
1545
+ const R = p.target;
1546
+ V.current !== null && R instanceof Node && V.current.contains(R) && p.preventDefault();
1547
+ },
1548
+ className: "z-50 max-h-72 w-[var(--radix-popover-trigger-width)] min-w-[12rem] overflow-y-auto rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md",
1549
+ children: /* @__PURE__ */ r("div", { role: "listbox", id: k, "aria-multiselectable": o || void 0, children: Re })
1550
+ }
1551
+ ) })
1552
+ ]
1553
+ }
1554
+ );
1555
+ }
1556
+ function hi(e) {
1557
+ return e == null || typeof e == "object" ? null : String(e);
1558
+ }
1559
+ function gi(e) {
1560
+ return e == null || typeof e == "boolean" ? null : Array.isArray(e) ? e.filter(
1561
+ (t) => typeof t == "string" || typeof t == "number"
1562
+ ) : e;
1563
+ }
1564
+ function pi({
1565
+ field: e,
1566
+ value: t,
1567
+ onFilterChange: n
1568
+ }) {
1569
+ const i = (e.enumValues ?? []).map((o) => ({
1570
+ value: String(o),
1571
+ label: An(o, e.enumLabels)
1572
+ }));
1573
+ return /* @__PURE__ */ r(
1574
+ Qe,
1575
+ {
1576
+ "aria-label": e.label,
1577
+ className: "h-9 w-auto min-w-36",
1578
+ value: hi(t),
1579
+ options: i,
1580
+ placeholder: e.label,
1581
+ clearable: !0,
1582
+ clearLabel: "All",
1583
+ onValueChange: (o) => {
1584
+ if (o === null) {
1585
+ n(e, null);
1586
+ return;
1587
+ }
1588
+ const a = (e.enumValues ?? []).find((s) => String(s) === o);
1589
+ n(e, a ?? o);
1590
+ }
1591
+ }
1592
+ );
1593
+ }
1594
+ function bi({
1595
+ field: e,
1596
+ value: t,
1597
+ onFilterChange: n
1598
+ }) {
1599
+ return /* @__PURE__ */ r(
1600
+ Qe,
1601
+ {
1602
+ "aria-label": e.label,
1603
+ className: "h-9 w-auto min-w-36",
1604
+ value: typeof t == "boolean" ? String(t) : null,
1605
+ options: [
1606
+ { value: "true", label: "Yes" },
1607
+ { value: "false", label: "No" }
1608
+ ],
1609
+ placeholder: e.label,
1610
+ clearable: !0,
1611
+ clearLabel: "All",
1612
+ onValueChange: (i) => n(e, i === null ? null : i === "true")
1613
+ }
1614
+ );
1615
+ }
1616
+ function yi(e) {
1617
+ const {
1618
+ searchEnabled: t,
1619
+ searchValue: n,
1620
+ onSearchChange: i,
1621
+ searchPlaceholder: o = "Search…",
1622
+ filterFields: a,
1623
+ values: s,
1624
+ onFilterChange: u,
1625
+ className: l
1626
+ } = e;
1627
+ return /* @__PURE__ */ d("div", { className: b("flex flex-wrap items-center gap-2", l), children: [
1628
+ t && /* @__PURE__ */ r(
1629
+ we,
1630
+ {
1631
+ type: "search",
1632
+ "aria-label": "Search",
1633
+ placeholder: o,
1634
+ value: n,
1635
+ onChange: (c) => i(c.target.value),
1636
+ className: "h-9 w-full max-w-xs"
1637
+ }
1638
+ ),
1639
+ a.map((c) => {
1640
+ const f = s[c.name];
1641
+ return c.kind === "enum" ? /* @__PURE__ */ r(
1642
+ pi,
1643
+ {
1644
+ field: c,
1645
+ value: f,
1646
+ onFilterChange: u
1647
+ },
1648
+ c.name
1649
+ ) : c.kind === "boolean" ? /* @__PURE__ */ r(
1650
+ bi,
1651
+ {
1652
+ field: c,
1653
+ value: f,
1654
+ onFilterChange: u
1655
+ },
1656
+ c.name
1657
+ ) : c.kind === "relation" && c.relation !== void 0 ? /* @__PURE__ */ r("div", { className: "min-w-36", children: /* @__PURE__ */ r(
1658
+ Dn,
1659
+ {
1660
+ resource: c.relation.resource,
1661
+ multiple: c.relation.many,
1662
+ value: gi(f),
1663
+ placeholder: c.label,
1664
+ onChange: (g) => u(c, g)
1665
+ }
1666
+ ) }, c.name) : null;
1667
+ })
1668
+ ] });
1669
+ }
1670
+ function xi(e) {
1671
+ const { page: t, pageCount: n, totalCount: i, hasPrevious: o, hasNext: a, onPageChange: s, className: u } = e;
1672
+ return /* @__PURE__ */ d(
1673
+ "nav",
1674
+ {
1675
+ "aria-label": "Pagination",
1676
+ className: b("flex flex-wrap items-center justify-between gap-3", u),
1677
+ children: [
1678
+ /* @__PURE__ */ d("p", { className: "text-sm text-muted-foreground", children: [
1679
+ "Page ",
1680
+ t,
1681
+ " of ",
1682
+ n,
1683
+ " · ",
1684
+ i,
1685
+ " ",
1686
+ i === 1 ? "item" : "items"
1687
+ ] }),
1688
+ /* @__PURE__ */ d("div", { className: "flex items-center gap-2", children: [
1689
+ /* @__PURE__ */ r(
1690
+ Y,
1691
+ {
1692
+ variant: "outline",
1693
+ size: "sm",
1694
+ disabled: !o,
1695
+ onClick: () => s(Math.max(1, t - 1)),
1696
+ children: "Previous"
1697
+ }
1698
+ ),
1699
+ /* @__PURE__ */ r(
1700
+ Y,
1701
+ {
1702
+ variant: "outline",
1703
+ size: "sm",
1704
+ disabled: !a,
1705
+ onClick: () => s(t + 1),
1706
+ children: "Next"
1707
+ }
1708
+ )
1709
+ ] })
1710
+ ]
1711
+ }
1712
+ );
1713
+ }
1714
+ function vi(e, t) {
1715
+ const [n, i] = m.useState(e);
1716
+ return m.useEffect(() => {
1717
+ const o = setTimeout(() => i(e), t);
1718
+ return () => clearTimeout(o);
1719
+ }, [e, t]), n;
1720
+ }
1721
+ ee("data-table", "ResourceTable");
1722
+ const wi = 25, Ni = 300, Si = 4;
1723
+ function ki() {
1724
+ return {
1725
+ id: "__select__",
1726
+ enableSorting: !1,
1727
+ header: ({ table: e }) => /* @__PURE__ */ r(
1728
+ gt,
1729
+ {
1730
+ "aria-label": "Select all rows",
1731
+ checked: e.getIsAllPageRowsSelected() ? !0 : e.getIsSomePageRowsSelected() ? "indeterminate" : !1,
1732
+ onCheckedChange: (t) => e.toggleAllPageRowsSelected(t === !0)
1733
+ }
1734
+ ),
1735
+ cell: ({ row: e }) => /* @__PURE__ */ r("div", { className: "flex items-center", onClick: (t) => t.stopPropagation(), children: /* @__PURE__ */ r(
1736
+ gt,
1737
+ {
1738
+ "aria-label": "Select row",
1739
+ checked: e.getIsSelected(),
1740
+ onCheckedChange: (t) => e.toggleSelected(t === !0)
1741
+ }
1742
+ ) })
1743
+ };
1744
+ }
1745
+ function Ci(e) {
1746
+ const t = Sn(e.resource), n = (e.getRowLabel ?? Oe)(e.row);
1747
+ return /* @__PURE__ */ r(
1748
+ Y,
1749
+ {
1750
+ variant: "ghost",
1751
+ size: "sm",
1752
+ className: "text-destructive hover:text-destructive",
1753
+ disabled: t.remove.isPending,
1754
+ onClick: () => {
1755
+ const i = e.row.id;
1756
+ if (i == null) return;
1757
+ (typeof window > "u" || typeof window.confirm != "function" || window.confirm(`Delete "${n}"? This cannot be undone.`)) && t.remove.mutate(i);
1758
+ },
1759
+ children: "Delete"
1760
+ }
1761
+ );
1762
+ }
1763
+ function Ai(e) {
1764
+ const { resource: t, rowActions: n, onEdit: i, enableDelete: o, getRowLabel: a } = e;
1765
+ return {
1766
+ id: "__actions__",
1767
+ enableSorting: !1,
1768
+ header: () => /* @__PURE__ */ r("span", { className: "sr-only", children: "Actions" }),
1769
+ cell: ({ row: s }) => /* @__PURE__ */ d(
1770
+ "div",
1771
+ {
1772
+ className: "flex items-center justify-end gap-1",
1773
+ onClick: (u) => u.stopPropagation(),
1774
+ children: [
1775
+ i !== void 0 && /* @__PURE__ */ r(Y, { variant: "ghost", size: "sm", onClick: () => i(s.original), children: "Edit" }),
1776
+ n == null ? void 0 : n(s.original),
1777
+ o === !0 && /* @__PURE__ */ r(
1778
+ Ci,
1779
+ {
1780
+ resource: t,
1781
+ row: Ze(s.original),
1782
+ getRowLabel: a
1783
+ }
1784
+ )
1785
+ ]
1786
+ }
1787
+ )
1788
+ };
1789
+ }
1790
+ function Ri({ rows: e = 8 }) {
1791
+ return /* @__PURE__ */ d(
1792
+ "div",
1793
+ {
1794
+ role: "status",
1795
+ "aria-live": "polite",
1796
+ className: "flex w-full flex-col gap-3 rounded-md border border-border p-4",
1797
+ children: [
1798
+ /* @__PURE__ */ r("span", { className: "sr-only", children: "Loading…" }),
1799
+ /* @__PURE__ */ r(me, { className: "h-6 w-1/3" }),
1800
+ Array.from({ length: e }, (t, n) => /* @__PURE__ */ r(me, { className: "h-8 w-full" }, n))
1801
+ ]
1802
+ }
1803
+ );
1804
+ }
1805
+ function $n(e) {
1806
+ return /* @__PURE__ */ d(
1807
+ "div",
1808
+ {
1809
+ role: "alert",
1810
+ className: "flex w-full flex-col items-center gap-3 rounded-md border border-destructive/50 bg-destructive/10 px-6 py-8 text-center",
1811
+ children: [
1812
+ /* @__PURE__ */ r("p", { className: "text-sm font-medium text-destructive", children: Zr(e.error) }),
1813
+ e.onRetry !== void 0 && /* @__PURE__ */ r(Y, { variant: "outline", size: "sm", onClick: e.onRetry, children: "Retry" })
1814
+ ]
1815
+ }
1816
+ );
1817
+ }
1818
+ function Ti(e) {
1819
+ const t = tt();
1820
+ return /* @__PURE__ */ r(
1821
+ $n,
1822
+ {
1823
+ error: e.error,
1824
+ onRetry: () => {
1825
+ t.invalidateQueries({ queryKey: he.schema() });
1826
+ }
1827
+ }
1828
+ );
1829
+ }
1830
+ function ga(e) {
1831
+ var Et, Mt, jt, Dt, $t, Ot;
1832
+ const {
1833
+ resource: t,
1834
+ columns: n,
1835
+ showAuditFields: i,
1836
+ extraColumns: o,
1837
+ columnsOverride: a,
1838
+ rowActions: s,
1839
+ onEdit: u,
1840
+ enableDelete: l,
1841
+ bulkActions: c,
1842
+ onRowClick: f,
1843
+ expand: g,
1844
+ initialSorting: x,
1845
+ pageSize: L,
1846
+ filters: T,
1847
+ params: v,
1848
+ exportFormats: k,
1849
+ toolbar: h,
1850
+ empty: w,
1851
+ footer: S,
1852
+ getRowLabel: j,
1853
+ className: B
1854
+ } = e, y = kt(t), C = y.data, [O, V] = m.useState(x ?? []), [K, $] = m.useState({}), [E, N] = m.useState(1), [F, _] = m.useState(""), [P, J] = m.useState({}), oe = L ?? wi, se = vi(F, Ni), Ce = m.useRef(se);
1855
+ m.useEffect(() => {
1856
+ Ce.current !== se && (Ce.current = se, N(1));
1857
+ }, [se]);
1858
+ const Me = m.useCallback((M) => {
1859
+ V((H) => typeof M == "function" ? M(H) : M), N(1);
1860
+ }, []), Ae = m.useCallback((M, H) => {
1861
+ J((Z) => H == null || H === "" || Array.isArray(H) && H.length === 0 ? Object.fromEntries(Object.entries(Z).filter(([ne]) => ne !== M.name)) : { ...Z, [M.name]: H }), N(1);
1862
+ }, []), pe = m.useMemo(() => {
1863
+ var H;
1864
+ if (g !== void 0) return g;
1865
+ const M = (H = C == null ? void 0 : C.operations.list) == null ? void 0 : H.expandEnum;
1866
+ return C === void 0 || M === void 0 ? [] : C.fields.filter(
1867
+ (Z) => Z.kind === "relation" && Z.relation !== void 0 && !Z.relation.many && M.includes(Z.name)
1868
+ ).map((Z) => Z.name);
1869
+ }, [g, C]), q = m.useMemo(() => new Set(Object.keys(v ?? {})), [v]), ye = m.useMemo(() => {
1870
+ var ze;
1871
+ if (T === !1 || C === void 0) return [];
1872
+ if (T !== void 0) {
1873
+ const ne = new Map(C.fields.map((Se) => [Se.name, Se]));
1874
+ return T.filter((Se) => !q.has(Se)).map((Se) => ne.get(Se)).filter((Se) => Se !== void 0);
1875
+ }
1876
+ const M = new Set(((ze = C.operations.list) == null ? void 0 : ze.queryParams) ?? []), { domain: H, audit: Z } = At(C.fields);
1877
+ return [...H, ...Z].filter(
1878
+ (ne) => !ne.writeOnly && !q.has(ne.name) && (i === !0 || !Ct(ne)) && M.has(ne.name) && (ne.kind === "enum" || ne.kind === "boolean" || ne.kind === "relation" && ne.relation !== void 0)
1879
+ ).slice(0, Si);
1880
+ }, [T, q, C, i]), ce = ((Et = C == null ? void 0 : C.operations.list) == null ? void 0 : Et.hasSearch) === !0, Ne = se.trim(), A = m.useMemo(
1881
+ () => ({
1882
+ page: E,
1883
+ pageSize: oe,
1884
+ ordering: Qr(O),
1885
+ search: ce && Ne.length > 0 ? Ne : void 0,
1886
+ filters: Object.keys(P).length > 0 || v !== void 0 ? { ...P, ...v } : void 0,
1887
+ expand: pe.length > 0 ? pe : void 0
1888
+ }),
1889
+ [
1890
+ E,
1891
+ oe,
1892
+ O,
1893
+ ce,
1894
+ Ne,
1895
+ P,
1896
+ v,
1897
+ pe
1898
+ ]
1899
+ ), D = Nn(t, A, {
1900
+ enabled: C !== void 0,
1901
+ placeholderData: tr,
1902
+ // A 404 is the page-clamp signal (D5) — retrying it only delays the clamp.
1903
+ retry: (M, H) => !Wt(H) && M < 3
1904
+ }), be = Wt(D.error) && E > 1;
1905
+ m.useEffect(() => {
1906
+ be && N((M) => Math.max(1, M - 1));
1907
+ }, [be, E]);
1908
+ const W = c !== void 0 && c.length > 0, I = s !== void 0 || u !== void 0 || l === !0, Re = m.useMemo(() => {
1909
+ if (C === void 0) return [];
1910
+ let M = ii({ fields: C.fields, columns: n, getRowLabel: j, showAuditFields: i });
1911
+ o !== void 0 && (M = [...M, ...o]), a !== void 0 && (M = a(M));
1912
+ const H = W ? [ki()] : [], Z = I ? [Ai({ resource: t, rowActions: s, onEdit: u, enableDelete: l, getRowLabel: j })] : [];
1913
+ return [...H, ...M, ...Z];
1914
+ }, [
1915
+ C,
1916
+ n,
1917
+ j,
1918
+ i,
1919
+ o,
1920
+ a,
1921
+ W,
1922
+ I,
1923
+ t,
1924
+ s,
1925
+ u,
1926
+ l
1927
+ ]), Te = m.useMemo(() => {
1928
+ var M;
1929
+ return ((M = D.data) == null ? void 0 : M.results) ?? [];
1930
+ }, [D.data]), p = (Mt = D.data) == null ? void 0 : Mt.count, R = Jr(p, oe), U = sr({
1931
+ data: Te,
1932
+ columns: Re,
1933
+ state: { sorting: O, rowSelection: K },
1934
+ manualSorting: !0,
1935
+ manualPagination: !0,
1936
+ manualFiltering: !0,
1937
+ pageCount: R,
1938
+ enableRowSelection: W,
1939
+ onSortingChange: Me,
1940
+ onRowSelectionChange: $,
1941
+ // D5: selection is keyed by String(row.id) and persists across pages —
1942
+ // rows always carry `id`, even while its column is hidden.
1943
+ getRowId: (M) => String(Ze(M).id),
1944
+ getCoreRowModel: lr()
1945
+ }), te = m.useMemo(
1946
+ () => Object.keys(K).filter((M) => K[M]),
1947
+ [K]
1948
+ ), Le = Ne.length > 0 || Object.keys(P).length > 0;
1949
+ let xe;
1950
+ y.error !== null && y.error !== void 0 ? xe = /* @__PURE__ */ r(Ti, { error: y.error }) : y.isLoading || C === void 0 || D.isPending || be ? xe = /* @__PURE__ */ r(Ri, {}) : D.error !== null && D.error !== void 0 ? xe = /* @__PURE__ */ r(
1951
+ $n,
1952
+ {
1953
+ error: D.error,
1954
+ onRetry: () => {
1955
+ D.refetch();
1956
+ }
1957
+ }
1958
+ ) : Te.length === 0 ? xe = w ?? (Le ? /* @__PURE__ */ r(yt, { title: "No results", description: "Try adjusting your search or filters." }) : /* @__PURE__ */ r(yt, { title: "Nothing here yet", description: "Records will appear here once created." })) : xe = /* @__PURE__ */ d(Q, { children: [
1959
+ /* @__PURE__ */ r(
1960
+ "div",
1961
+ {
1962
+ className: b(
1963
+ "w-full overflow-x-auto rounded-md border border-border",
1964
+ D.isFetching && "opacity-60"
1965
+ ),
1966
+ children: /* @__PURE__ */ d("table", { className: "w-full caption-bottom text-sm", "aria-busy": D.isFetching, children: [
1967
+ /* @__PURE__ */ r("thead", { className: "border-b border-border bg-muted", children: /* @__PURE__ */ r("tr", { children: U.getFlatHeaders().map((M) => {
1968
+ const H = M.column.getCanSort(), Z = M.column.getIsSorted();
1969
+ return /* @__PURE__ */ r(
1970
+ "th",
1971
+ {
1972
+ scope: "col",
1973
+ "aria-sort": Z === "asc" ? "ascending" : Z === "desc" ? "descending" : void 0,
1974
+ className: "h-10 px-3 text-left align-middle text-xs font-medium text-muted-foreground",
1975
+ children: M.isPlaceholder ? null : H ? /* @__PURE__ */ d(
1976
+ "button",
1977
+ {
1978
+ type: "button",
1979
+ className: "inline-flex items-center gap-1 rounded-sm hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
1980
+ onClick: (ze) => {
1981
+ var ne;
1982
+ return (ne = M.column.getToggleSortingHandler()) == null ? void 0 : ne(ze);
1983
+ },
1984
+ children: [
1985
+ it(M.column.columnDef.header, M.getContext()),
1986
+ Z === "asc" ? /* @__PURE__ */ r(hn, { className: "h-3.5 w-3.5" }) : Z === "desc" ? /* @__PURE__ */ r(nt, { className: "h-3.5 w-3.5" }) : null
1987
+ ]
1988
+ }
1989
+ ) : it(M.column.columnDef.header, M.getContext())
1990
+ },
1991
+ M.id
1992
+ );
1993
+ }) }) }),
1994
+ /* @__PURE__ */ r("tbody", { children: U.getRowModel().rows.map((M) => /* @__PURE__ */ r(
1995
+ "tr",
1996
+ {
1997
+ "data-state": M.getIsSelected() ? "selected" : void 0,
1998
+ onClick: f !== void 0 ? () => f(M.original) : void 0,
1999
+ className: b(
2000
+ "border-b border-border transition-colors last:border-0 hover:bg-muted data-[state=selected]:bg-muted",
2001
+ f !== void 0 && "cursor-pointer"
2002
+ ),
2003
+ children: M.getVisibleCells().map((H) => /* @__PURE__ */ r("td", { className: "px-3 py-2 align-middle", children: it(H.column.columnDef.cell, H.getContext()) }, H.id))
2004
+ },
2005
+ M.id
2006
+ )) })
2007
+ ] })
2008
+ }
2009
+ ),
2010
+ p !== void 0 && p > 0 && /* @__PURE__ */ r(
2011
+ xi,
2012
+ {
2013
+ page: E,
2014
+ pageCount: R,
2015
+ totalCount: p,
2016
+ hasPrevious: ((jt = D.data) == null ? void 0 : jt.previous) !== null && ((Dt = D.data) == null ? void 0 : Dt.previous) !== void 0,
2017
+ hasNext: (($t = D.data) == null ? void 0 : $t.next) !== null && ((Ot = D.data) == null ? void 0 : Ot.next) !== void 0,
2018
+ onPageChange: N
2019
+ }
2020
+ )
2021
+ ] });
2022
+ const Ve = k === void 0 ? ["csv", "xlsx"] : k === !1 ? [] : k, rt = Ve.length > 0 && (C == null ? void 0 : C.operations.export) !== void 0, Kn = C !== void 0 && (ce || ye.length > 0 || h !== void 0 || rt);
2023
+ return /* @__PURE__ */ d("div", { className: b("flex w-full flex-col gap-3", B), children: [
2024
+ Kn && /* @__PURE__ */ d("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [
2025
+ /* @__PURE__ */ r(
2026
+ yi,
2027
+ {
2028
+ searchEnabled: ce,
2029
+ searchValue: F,
2030
+ onSearchChange: _,
2031
+ filterFields: ye,
2032
+ values: P,
2033
+ onFilterChange: Ae,
2034
+ className: "min-w-0 flex-1"
2035
+ }
2036
+ ),
2037
+ (h !== void 0 || rt) && /* @__PURE__ */ d("div", { className: "flex shrink-0 items-center gap-2", children: [
2038
+ rt && /* @__PURE__ */ r(mi, { resource: t, params: A, formats: Ve }),
2039
+ h
2040
+ ] })
2041
+ ] }),
2042
+ W && te.length > 0 && /* @__PURE__ */ r(
2043
+ Wr,
2044
+ {
2045
+ selectedIds: te,
2046
+ bulkActions: c,
2047
+ onClear: () => $({})
2048
+ }
2049
+ ),
2050
+ xe,
2051
+ S
2052
+ ] });
2053
+ }
2054
+ const Ee = "This field is required.", Li = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,6})?)?$/;
2055
+ function Ei(e) {
2056
+ if (!Li.test(e)) return e;
2057
+ const t = new Date(e);
2058
+ return Number.isNaN(t.getTime()) ? e : t.toISOString();
2059
+ }
2060
+ function Mi(e) {
2061
+ if (e.length === 0) return z.never();
2062
+ if (e.every((n) => typeof n == "string"))
2063
+ return z.enum(e);
2064
+ const t = e.map((n) => z.literal(n));
2065
+ return t.length === 1 ? t[0] : z.union(t);
2066
+ }
2067
+ function ji(e, t) {
2068
+ let n = z.string();
2069
+ return e.format === "email" ? n = n.email() : e.format === "uri" || e.format === "url" ? n = n.url() : e.format === "uuid" && (n = n.uuid()), e.maxLength !== void 0 && (n = n.max(e.maxLength)), t && (n = n.min(1, Ee)), n;
2070
+ }
2071
+ function Yt(e, t) {
2072
+ let n = z.coerce.number();
2073
+ return t && (n = n.int()), e.min !== void 0 && (n = n.min(e.min)), e.max !== void 0 && (n = n.max(e.max)), n;
2074
+ }
2075
+ function On(e, t) {
2076
+ switch (e.relationValueType) {
2077
+ case "uuid":
2078
+ return z.string({ required_error: Ee }).uuid();
2079
+ case "integer":
2080
+ return t ? z.coerce.number().int() : z.number({ required_error: Ee }).int();
2081
+ default:
2082
+ return z.string({ required_error: Ee }).min(1, Ee);
2083
+ }
2084
+ }
2085
+ function Di(e, t) {
2086
+ const n = On(e, !1);
2087
+ let i = e.nullable ? n.nullable() : n;
2088
+ return t || (i = i.optional()), z.preprocess((o) => {
2089
+ if (o === "" || o === null || o === void 0) return e.nullable ? null : void 0;
2090
+ if (e.relationValueType === "integer" && typeof o == "string" && o.trim() !== "") {
2091
+ const a = Number(o);
2092
+ return Number.isNaN(a) ? o : a;
2093
+ }
2094
+ return o;
2095
+ }, i);
2096
+ }
2097
+ function $i() {
2098
+ return typeof File > "u" ? z.string() : z.union([z.instanceof(File), z.string()]);
2099
+ }
2100
+ function Oi(e, t) {
2101
+ var n;
2102
+ switch (e.kind) {
2103
+ case "string":
2104
+ case "text":
2105
+ return ji(e, t);
2106
+ case "integer":
2107
+ return Yt(e, !0);
2108
+ case "number":
2109
+ return Yt(e, !1);
2110
+ case "boolean":
2111
+ return z.boolean();
2112
+ case "date": {
2113
+ const i = z.string();
2114
+ return t ? i.min(1, Ee) : i;
2115
+ }
2116
+ case "datetime":
2117
+ return (t ? z.string().min(1, Ee) : z.string()).transform(Ei);
2118
+ case "enum":
2119
+ return Mi(e.enumValues ?? []);
2120
+ case "relation":
2121
+ return ((n = e.relation) == null ? void 0 : n.many) === !0 ? z.array(On(e, !0)) : Di(e, t);
2122
+ case "file":
2123
+ return $i();
2124
+ case "json":
2125
+ return z.unknown();
2126
+ case "array":
2127
+ return z.array(z.unknown());
2128
+ case "unknown":
2129
+ return z.unknown();
2130
+ }
2131
+ }
2132
+ function Fi(e, t) {
2133
+ const n = {};
2134
+ for (const i of e.fields) {
2135
+ if (i.readOnly) continue;
2136
+ const o = i.required;
2137
+ let a = Oi(i, o);
2138
+ i.nullable && (a = a.nullable()), (t === "update" || !i.required) && (a = a.optional()), n[i.name] = a;
2139
+ }
2140
+ return z.object(n);
2141
+ }
2142
+ ee("file-upload", "FileUpload");
2143
+ function Pi(e, t) {
2144
+ if (t === void 0 || t.trim() === "") return !0;
2145
+ const n = t.split(",").map((a) => a.trim().toLowerCase()).filter((a) => a !== "");
2146
+ if (n.length === 0) return !0;
2147
+ const i = e.name.toLowerCase(), o = e.type.toLowerCase();
2148
+ return n.some((a) => a.startsWith(".") ? i.endsWith(a) : a.endsWith("/*") ? o.startsWith(a.slice(0, -1)) : o === a);
2149
+ }
2150
+ function Bi(e) {
2151
+ return e < 1024 ? `${e} B` : e < 1024 * 1024 ? `${Math.round(e / 1024)} KB` : `${(e / (1024 * 1024)).toFixed(1)} MB`;
2152
+ }
2153
+ function _i(e) {
2154
+ const n = (e.split(/[?#]/, 1)[0] ?? e).split("/").filter((i) => i !== "");
2155
+ return n[n.length - 1] ?? e;
2156
+ }
2157
+ function Vi(e) {
2158
+ return /* @__PURE__ */ d(
2159
+ "svg",
2160
+ {
2161
+ viewBox: "0 0 24 24",
2162
+ fill: "none",
2163
+ stroke: "currentColor",
2164
+ strokeWidth: 2,
2165
+ strokeLinecap: "round",
2166
+ strokeLinejoin: "round",
2167
+ "aria-hidden": "true",
2168
+ focusable: !1,
2169
+ ...e,
2170
+ children: [
2171
+ /* @__PURE__ */ r("path", { d: "M21 15v3a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-3" }),
2172
+ /* @__PURE__ */ r("polyline", { points: "7 8 12 3 17 8" }),
2173
+ /* @__PURE__ */ r("line", { x1: "12", y1: "3", x2: "12", y2: "15" })
2174
+ ]
2175
+ }
2176
+ );
2177
+ }
2178
+ function zi(e) {
2179
+ return /* @__PURE__ */ d(
2180
+ "svg",
2181
+ {
2182
+ viewBox: "0 0 24 24",
2183
+ fill: "none",
2184
+ stroke: "currentColor",
2185
+ strokeWidth: 2,
2186
+ strokeLinecap: "round",
2187
+ strokeLinejoin: "round",
2188
+ "aria-hidden": "true",
2189
+ focusable: !1,
2190
+ ...e,
2191
+ children: [
2192
+ /* @__PURE__ */ r("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
2193
+ /* @__PURE__ */ r("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
2194
+ ]
2195
+ }
2196
+ );
2197
+ }
2198
+ function Ui(e) {
2199
+ const {
2200
+ value: t = null,
2201
+ onChange: n,
2202
+ accept: i,
2203
+ multiple: o = !1,
2204
+ disabled: a = !1,
2205
+ maxSize: s,
2206
+ onReject: u,
2207
+ id: l,
2208
+ name: c,
2209
+ className: f,
2210
+ children: g,
2211
+ clearable: x = !0
2212
+ } = e, L = m.useRef(null), [T, v] = m.useState(!1), k = t == null ? [] : Array.isArray(t) ? t : [t], h = (y) => {
2213
+ if (a) return;
2214
+ const C = [];
2215
+ for (const O of Array.from(y)) {
2216
+ if (!Pi(O, i)) {
2217
+ u == null || u(O, "accept");
2218
+ continue;
2219
+ }
2220
+ if (s !== void 0 && O.size > s) {
2221
+ u == null || u(O, "size");
2222
+ continue;
2223
+ }
2224
+ C.push(O);
2225
+ }
2226
+ C.length !== 0 && (n == null || n(o ? C : C[0]));
2227
+ }, w = (y) => {
2228
+ y.target.files !== null && h(y.target.files), y.target.value = "";
2229
+ }, S = (y) => {
2230
+ y.preventDefault(), v(!1), !a && h(y.dataTransfer.files);
2231
+ }, j = (y) => {
2232
+ y.preventDefault(), a || v(!0);
2233
+ }, B = (y) => {
2234
+ if (n === void 0) return;
2235
+ const C = k.filter((V, K) => K !== y);
2236
+ if (C.length === 0) {
2237
+ n(null);
2238
+ return;
2239
+ }
2240
+ const O = C.filter((V) => typeof V != "string");
2241
+ n(o ? O : O[0] ?? null);
2242
+ };
2243
+ return /* @__PURE__ */ d("div", { className: b("space-y-2", f), children: [
2244
+ /* @__PURE__ */ r(
2245
+ "button",
2246
+ {
2247
+ type: "button",
2248
+ id: l,
2249
+ disabled: a,
2250
+ "aria-label": e["aria-label"],
2251
+ onClick: () => {
2252
+ var y;
2253
+ return (y = L.current) == null ? void 0 : y.click();
2254
+ },
2255
+ onDragOver: j,
2256
+ onDragEnter: j,
2257
+ onDragLeave: () => v(!1),
2258
+ onDrop: S,
2259
+ "data-dragging": T ? "true" : void 0,
2260
+ className: "flex w-full flex-col items-center justify-center gap-1 rounded-md border border-dashed border-input bg-background px-4 py-6 text-sm text-muted-foreground transition-colors hover:border-ring hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[dragging=true]:border-ring data-[dragging=true]:bg-accent data-[dragging=true]:text-accent-foreground",
2261
+ children: g ?? /* @__PURE__ */ d(Q, { children: [
2262
+ /* @__PURE__ */ r(Vi, { className: "h-5 w-5" }),
2263
+ /* @__PURE__ */ r("span", { children: o ? "Drag and drop files here, or click to browse" : "Drag and drop a file here, or click to browse" })
2264
+ ] })
2265
+ }
2266
+ ),
2267
+ /* @__PURE__ */ r(
2268
+ "input",
2269
+ {
2270
+ ref: L,
2271
+ type: "file",
2272
+ name: c,
2273
+ accept: i,
2274
+ multiple: o,
2275
+ disabled: a,
2276
+ onChange: w,
2277
+ tabIndex: -1,
2278
+ "aria-hidden": "true",
2279
+ className: "sr-only"
2280
+ }
2281
+ ),
2282
+ k.length > 0 ? /* @__PURE__ */ r("ul", { className: "space-y-1", children: k.map((y, C) => {
2283
+ const O = typeof y == "string" ? _i(y) : y.name;
2284
+ return /* @__PURE__ */ d(
2285
+ "li",
2286
+ {
2287
+ className: "flex items-center justify-between gap-2 rounded-md border border-border bg-muted/50 px-3 py-1.5 text-sm",
2288
+ children: [
2289
+ typeof y == "string" ? /* @__PURE__ */ r(
2290
+ "a",
2291
+ {
2292
+ href: y,
2293
+ target: "_blank",
2294
+ rel: "noreferrer",
2295
+ className: "truncate font-medium text-primary underline underline-offset-4",
2296
+ children: O
2297
+ }
2298
+ ) : /* @__PURE__ */ d("span", { className: "truncate", children: [
2299
+ y.name,
2300
+ /* @__PURE__ */ r("span", { className: "ml-2 text-xs text-muted-foreground", children: Bi(y.size) })
2301
+ ] }),
2302
+ x && !a ? /* @__PURE__ */ r(
2303
+ "button",
2304
+ {
2305
+ type: "button",
2306
+ "aria-label": `Remove ${O}`,
2307
+ onClick: () => B(C),
2308
+ className: "rounded-sm p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
2309
+ children: /* @__PURE__ */ r(zi, { className: "h-4 w-4" })
2310
+ }
2311
+ ) : null
2312
+ ]
2313
+ },
2314
+ typeof y == "string" ? `url-${y}` : `file-${y.name}-${C}`
2315
+ );
2316
+ }) }) : null
2317
+ ] });
2318
+ }
2319
+ function Fn(e) {
2320
+ const t = e.replace(/[_-]+/g, " ").trim();
2321
+ return t === "" ? e : t.charAt(0).toUpperCase() + t.slice(1);
2322
+ }
2323
+ function de(e) {
2324
+ return String(e).padStart(2, "0");
2325
+ }
2326
+ function Ki(e) {
2327
+ const t = new Date(e);
2328
+ return Number.isNaN(t.getTime()) ? e : `${t.getFullYear()}-${de(t.getMonth() + 1)}-${de(t.getDate())}T${de(
2329
+ t.getHours()
2330
+ )}:${de(t.getMinutes())}`;
2331
+ }
2332
+ const Hi = /(?:Z|[+-]\d{2}:?\d{2})$/i;
2333
+ function Wi(e) {
2334
+ if (Hi.test(e)) return e;
2335
+ const t = new Date(e);
2336
+ if (Number.isNaN(t.getTime())) return e;
2337
+ const n = -t.getTimezoneOffset(), i = n >= 0 ? "+" : "-", o = Math.abs(n), a = `${i}${de(Math.floor(o / 60))}:${de(o % 60)}`;
2338
+ return `${t.getFullYear()}-${de(t.getMonth() + 1)}-${de(t.getDate())}T${de(
2339
+ t.getHours()
2340
+ )}:${de(t.getMinutes())}:${de(t.getSeconds())}${a}`;
2341
+ }
2342
+ function vt(e) {
2343
+ return e === !0 ? !0 : Array.isArray(e) ? e.some(vt) : e !== null && typeof e == "object" ? Object.values(e).some(vt) : !1;
2344
+ }
2345
+ function He(e) {
2346
+ return e !== null && typeof e == "object" && !Array.isArray(e) && "id" in e ? e.id : e;
2347
+ }
2348
+ function Qi(e, t) {
2349
+ var n;
2350
+ switch (e.kind) {
2351
+ case "string":
2352
+ case "text":
2353
+ return t == null ? "" : String(t);
2354
+ case "number":
2355
+ case "integer":
2356
+ return t ?? "";
2357
+ case "boolean":
2358
+ return !!t;
2359
+ case "date":
2360
+ return t == null || t === "" ? "" : String(t).slice(0, 10);
2361
+ case "datetime":
2362
+ return t == null || t === "" ? "" : Ki(String(t));
2363
+ case "enum":
2364
+ return t ?? null;
2365
+ case "relation":
2366
+ return ((n = e.relation) == null ? void 0 : n.many) === !0 ? Array.isArray(t) ? t.map(He) : [] : t == null ? null : He(t);
2367
+ case "file":
2368
+ return t ?? null;
2369
+ case "json":
2370
+ return t == null ? "" : JSON.stringify(t, null, 2);
2371
+ default:
2372
+ return t;
2373
+ }
2374
+ }
2375
+ function Ji({ fields: e, item: t, defaultValues: n }) {
2376
+ const i = {};
2377
+ for (const o of e) {
2378
+ let a = n == null ? void 0 : n[o.name];
2379
+ a === void 0 && (a = o.default), t !== void 0 && o.name in t && (a = t[o.name]), i[o.name] = Qi(o, a);
2380
+ }
2381
+ if (n !== void 0)
2382
+ for (const [o, a] of Object.entries(n))
2383
+ o in i || (i[o] = a);
2384
+ return i;
2385
+ }
2386
+ function re(e) {
2387
+ return { kind: "value", value: e };
2388
+ }
2389
+ const Pn = { kind: "omit" };
2390
+ function ue(e) {
2391
+ return e.nullable ? re(null) : Pn;
2392
+ }
2393
+ function Zi(e, t) {
2394
+ var n;
2395
+ switch (e.kind) {
2396
+ case "string":
2397
+ case "text": {
2398
+ if (t == null) return ue(e);
2399
+ const i = String(t);
2400
+ return i === "" && e.nullable ? re(null) : re(i);
2401
+ }
2402
+ case "number":
2403
+ case "integer": {
2404
+ if (t == null || t === "") return ue(e);
2405
+ const i = typeof t == "number" ? t : Number(t);
2406
+ return Number.isFinite(i) ? re(i) : ue(e);
2407
+ }
2408
+ case "boolean":
2409
+ return t == null ? ue(e) : re(!!t);
2410
+ case "date":
2411
+ return t == null || t === "" ? ue(e) : re(String(t).slice(0, 10));
2412
+ case "datetime":
2413
+ return t == null || t === "" ? ue(e) : re(Wi(String(t)));
2414
+ case "enum": {
2415
+ if (t == null || t === "") return ue(e);
2416
+ const i = (e.enumValues ?? []).find(
2417
+ (o) => String(o) === String(t)
2418
+ );
2419
+ return re(i ?? t);
2420
+ }
2421
+ case "relation":
2422
+ return ((n = e.relation) == null ? void 0 : n.many) === !0 ? t == null ? re([]) : re(Array.isArray(t) ? t.map(He) : [He(t)]) : t == null || t === "" ? ue(e) : re(He(t));
2423
+ case "file":
2424
+ return t == null ? ue(e) : typeof t == "string" ? Pn : re(t);
2425
+ case "json": {
2426
+ if (typeof t != "string")
2427
+ return t == null ? ue(e) : re(t);
2428
+ if (t.trim() === "") return ue(e);
2429
+ try {
2430
+ return re(JSON.parse(t));
2431
+ } catch {
2432
+ return { kind: "error", message: "Enter valid JSON." };
2433
+ }
2434
+ }
2435
+ default:
2436
+ return re(t);
2437
+ }
2438
+ }
2439
+ function Gi({
2440
+ fields: e,
2441
+ raw: t,
2442
+ mode: n,
2443
+ dirtyFields: i
2444
+ }) {
2445
+ const o = new Map(e.map((u) => [u.name, u])), a = {}, s = [];
2446
+ for (const [u, l] of Object.entries(t)) {
2447
+ if (n === "update" && !vt(i == null ? void 0 : i[u])) continue;
2448
+ const c = o.get(u);
2449
+ if (c === void 0) {
2450
+ l !== void 0 && (a[u] = l);
2451
+ continue;
2452
+ }
2453
+ const f = Zi(c, l);
2454
+ f.kind === "error" ? s.push({ name: u, message: f.message }) : f.kind === "value" && f.value !== void 0 && (a[u] = f.value);
2455
+ }
2456
+ return { values: a, jsonErrors: s };
2457
+ }
2458
+ function Yi(e) {
2459
+ switch (e.format) {
2460
+ case "email":
2461
+ return "email";
2462
+ case "uri":
2463
+ case "url":
2464
+ return "url";
2465
+ case "password":
2466
+ return "password";
2467
+ default:
2468
+ return "text";
2469
+ }
2470
+ }
2471
+ function Xi({
2472
+ field: e,
2473
+ control: t,
2474
+ inputId: n,
2475
+ describedBy: i,
2476
+ invalid: o,
2477
+ disabled: a,
2478
+ inputProps: s
2479
+ }) {
2480
+ const u = {
2481
+ "aria-invalid": o || void 0,
2482
+ "aria-describedby": i
2483
+ };
2484
+ return /* @__PURE__ */ r(
2485
+ ir,
2486
+ {
2487
+ control: t,
2488
+ name: e.name,
2489
+ render: ({ field: l }) => {
2490
+ switch (e.kind) {
2491
+ case "text":
2492
+ return /* @__PURE__ */ r(
2493
+ ft,
2494
+ {
2495
+ id: n,
2496
+ rows: 4,
2497
+ maxLength: e.maxLength,
2498
+ disabled: a,
2499
+ value: l.value == null ? "" : String(l.value),
2500
+ onChange: (c) => l.onChange(c.target.value),
2501
+ onBlur: l.onBlur,
2502
+ ...u,
2503
+ ...s
2504
+ }
2505
+ );
2506
+ case "number":
2507
+ case "integer":
2508
+ return /* @__PURE__ */ r(
2509
+ we,
2510
+ {
2511
+ id: n,
2512
+ type: "number",
2513
+ inputMode: e.kind === "integer" ? "numeric" : "decimal",
2514
+ step: e.kind === "integer" ? 1 : "any",
2515
+ min: e.min,
2516
+ max: e.max,
2517
+ disabled: a,
2518
+ value: l.value == null ? "" : l.value,
2519
+ onChange: (c) => l.onChange(c.target.value),
2520
+ onBlur: l.onBlur,
2521
+ ...u,
2522
+ ...s
2523
+ }
2524
+ );
2525
+ case "boolean":
2526
+ return /* @__PURE__ */ r(
2527
+ xn,
2528
+ {
2529
+ id: n,
2530
+ disabled: a,
2531
+ checked: !!l.value,
2532
+ onCheckedChange: (c) => l.onChange(c),
2533
+ onBlur: l.onBlur,
2534
+ ...u,
2535
+ ...s
2536
+ }
2537
+ );
2538
+ case "date":
2539
+ return /* @__PURE__ */ r(
2540
+ we,
2541
+ {
2542
+ id: n,
2543
+ type: "date",
2544
+ disabled: a,
2545
+ value: l.value == null ? "" : String(l.value),
2546
+ onChange: (c) => l.onChange(c.target.value),
2547
+ onBlur: l.onBlur,
2548
+ ...u,
2549
+ ...s
2550
+ }
2551
+ );
2552
+ case "datetime":
2553
+ return /* @__PURE__ */ r(
2554
+ we,
2555
+ {
2556
+ id: n,
2557
+ type: "datetime-local",
2558
+ disabled: a,
2559
+ value: l.value == null ? "" : String(l.value),
2560
+ onChange: (c) => l.onChange(c.target.value),
2561
+ onBlur: l.onBlur,
2562
+ ...u,
2563
+ ...s
2564
+ }
2565
+ );
2566
+ case "enum": {
2567
+ const c = e.enumValues ?? [], f = c.map((g) => {
2568
+ var x;
2569
+ return {
2570
+ value: String(g),
2571
+ label: ((x = e.enumLabels) == null ? void 0 : x[String(g)]) ?? Fn(String(g))
2572
+ };
2573
+ });
2574
+ return /* @__PURE__ */ r(
2575
+ Qe,
2576
+ {
2577
+ id: n,
2578
+ disabled: a,
2579
+ value: l.value == null ? null : String(l.value),
2580
+ options: f,
2581
+ clearable: e.nullable,
2582
+ placeholder: "Select…",
2583
+ onValueChange: (g) => {
2584
+ if (g === null) {
2585
+ l.onChange(null);
2586
+ return;
2587
+ }
2588
+ const x = c.find((L) => String(L) === g);
2589
+ l.onChange(x ?? g);
2590
+ },
2591
+ ...s
2592
+ }
2593
+ );
2594
+ }
2595
+ case "relation": {
2596
+ const c = e.relation;
2597
+ return c === void 0 ? /* @__PURE__ */ r(
2598
+ we,
2599
+ {
2600
+ id: n,
2601
+ type: "text",
2602
+ disabled: a,
2603
+ value: l.value == null ? "" : String(l.value),
2604
+ onChange: (f) => l.onChange(f.target.value),
2605
+ onBlur: l.onBlur,
2606
+ ...u,
2607
+ ...s
2608
+ }
2609
+ ) : /* @__PURE__ */ r(
2610
+ Dn,
2611
+ {
2612
+ id: n,
2613
+ resource: c.resource,
2614
+ multiple: c.many,
2615
+ disabled: a,
2616
+ value: l.value ?? null,
2617
+ onChange: (f) => l.onChange(f),
2618
+ ...s
2619
+ }
2620
+ );
2621
+ }
2622
+ case "file":
2623
+ return /* @__PURE__ */ r(
2624
+ Ui,
2625
+ {
2626
+ id: n,
2627
+ disabled: a,
2628
+ value: l.value ?? null,
2629
+ onChange: (c) => l.onChange(c),
2630
+ ...s
2631
+ }
2632
+ );
2633
+ case "json":
2634
+ return /* @__PURE__ */ r(
2635
+ ft,
2636
+ {
2637
+ id: n,
2638
+ rows: 5,
2639
+ disabled: a,
2640
+ className: "font-mono",
2641
+ value: typeof l.value == "string" ? l.value : l.value == null ? "" : JSON.stringify(l.value, null, 2),
2642
+ onChange: (c) => l.onChange(c.target.value),
2643
+ onBlur: l.onBlur,
2644
+ ...u,
2645
+ ...s
2646
+ }
2647
+ );
2648
+ default:
2649
+ return /* @__PURE__ */ r(
2650
+ we,
2651
+ {
2652
+ id: n,
2653
+ type: Yi(e),
2654
+ maxLength: e.maxLength,
2655
+ disabled: a,
2656
+ value: l.value == null ? "" : String(l.value),
2657
+ onChange: (c) => l.onChange(c.target.value),
2658
+ onBlur: l.onBlur,
2659
+ ...u,
2660
+ ...s
2661
+ }
2662
+ );
2663
+ }
2664
+ }
2665
+ }
2666
+ );
2667
+ }
2668
+ ee("resource-form", "ResourceForm");
2669
+ const qi = /* @__PURE__ */ new Set([
2670
+ "string",
2671
+ "text",
2672
+ "number",
2673
+ "integer",
2674
+ "boolean",
2675
+ "date",
2676
+ "datetime",
2677
+ "enum",
2678
+ "relation",
2679
+ "file",
2680
+ "json"
2681
+ ]);
2682
+ function Ii(e) {
2683
+ return e instanceof Error ? e.message : String(e);
2684
+ }
2685
+ function eo({ className: e }) {
2686
+ return /* @__PURE__ */ d("div", { role: "status", "aria-label": "Loading form", className: b("space-y-5", e), children: [
2687
+ [0, 1, 2].map((t) => /* @__PURE__ */ d("div", { className: "space-y-2", children: [
2688
+ /* @__PURE__ */ r(me, { className: "h-4 w-24" }),
2689
+ /* @__PURE__ */ r(me, { className: "h-10 w-full" })
2690
+ ] }, t)),
2691
+ /* @__PURE__ */ r(me, { className: "h-10 w-28" })
2692
+ ] });
2693
+ }
2694
+ function Xt({
2695
+ error: e,
2696
+ className: t
2697
+ }) {
2698
+ return /* @__PURE__ */ r(
2699
+ "div",
2700
+ {
2701
+ role: "alert",
2702
+ className: b(
2703
+ "rounded-md border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",
2704
+ t
2705
+ ),
2706
+ children: Ii(e)
2707
+ }
2708
+ );
2709
+ }
2710
+ function to(e, t, n) {
2711
+ if (typeof e != "object" || e === null) return;
2712
+ const i = e;
2713
+ if (i.status !== 400) return;
2714
+ const o = i.data;
2715
+ if (Array.isArray(o)) {
2716
+ n.setError("root.server", { type: "server", message: o.map(String).join(" ") });
2717
+ return;
2718
+ }
2719
+ if (typeof o != "object" || o === null) return;
2720
+ const a = [];
2721
+ for (const [s, u] of Object.entries(o)) {
2722
+ const l = Array.isArray(u) ? u.map(String).join(" ") : String(u);
2723
+ s === "non_field_errors" || s === "detail" ? a.push(l) : t.has(s) ? n.setError(s, { type: "server", message: l }) : a.push(`${s}: ${l}`);
2724
+ }
2725
+ a.length > 0 && n.setError("root.server", { type: "server", message: a.join(" ") });
2726
+ }
2727
+ function no({
2728
+ field: e,
2729
+ override: t,
2730
+ control: n,
2731
+ error: i,
2732
+ disabled: o
2733
+ }) {
2734
+ const a = m.useId(), s = (t == null ? void 0 : t.label) ?? e.label;
2735
+ if ((t == null ? void 0 : t.component) !== void 0) {
2736
+ const f = t.component;
2737
+ return /* @__PURE__ */ r(
2738
+ f,
2739
+ {
2740
+ field: e,
2741
+ name: e.name,
2742
+ label: s,
2743
+ required: e.required,
2744
+ control: n,
2745
+ error: i,
2746
+ disabled: o,
2747
+ props: t.props
2748
+ }
2749
+ );
2750
+ }
2751
+ const u = `${a}-error`, l = `${a}-description`, c = [e.description !== void 0 ? l : null, i !== void 0 ? u : null].filter((f) => f !== null).join(" ") || void 0;
2752
+ return /* @__PURE__ */ d("div", { className: "space-y-2", children: [
2753
+ /* @__PURE__ */ d(qe, { htmlFor: a, children: [
2754
+ s,
2755
+ e.required ? /* @__PURE__ */ r("span", { "aria-hidden": "true", className: "text-destructive", children: " *" }) : null
2756
+ ] }),
2757
+ /* @__PURE__ */ r(
2758
+ Xi,
2759
+ {
2760
+ field: e,
2761
+ control: n,
2762
+ inputId: a,
2763
+ describedBy: c,
2764
+ invalid: i !== void 0,
2765
+ disabled: o,
2766
+ inputProps: t == null ? void 0 : t.props
2767
+ }
2768
+ ),
2769
+ e.description !== void 0 ? /* @__PURE__ */ r("p", { id: l, className: "text-sm text-muted-foreground", children: e.description }) : null,
2770
+ i !== void 0 ? /* @__PURE__ */ r("p", { id: u, className: "text-sm font-medium text-destructive", children: i }) : null
2771
+ ] });
2772
+ }
2773
+ function ro(e) {
2774
+ var O, V, K;
2775
+ const {
2776
+ resource: t,
2777
+ id: n,
2778
+ defaultValues: i,
2779
+ onSuccess: o,
2780
+ onError: a,
2781
+ fields: s,
2782
+ extraFields: u,
2783
+ transformSubmit: l,
2784
+ actions: c,
2785
+ className: f,
2786
+ schema: g,
2787
+ item: x
2788
+ } = e, L = n === void 0 ? "create" : "update", T = Sn(t), v = m.useMemo(
2789
+ () => g.fields.filter(
2790
+ ($) => {
2791
+ var E;
2792
+ return !$.readOnly && (qi.has($.kind) || ((E = s == null ? void 0 : s[$.name]) == null ? void 0 : E.component) !== void 0);
2793
+ }
2794
+ ),
2795
+ [g, s]
2796
+ ), k = m.useMemo(
2797
+ () => Ji({ fields: v, item: x, defaultValues: i }),
2798
+ [v, x, i]
2799
+ ), h = m.useMemo(() => {
2800
+ const $ = rr(Fi(g, L)), E = new Set(
2801
+ g.fields.filter(
2802
+ (N) => {
2803
+ var F;
2804
+ return !N.required && !N.nullable && !(N.kind === "relation" && ((F = N.relation) == null ? void 0 : F.many) === !0);
2805
+ }
2806
+ ).map((N) => N.name)
2807
+ );
2808
+ return (N, F, _) => {
2809
+ const P = Object.fromEntries(
2810
+ Object.entries(N).filter(([J, oe]) => !(oe === null && E.has(J)))
2811
+ );
2812
+ return $(P, F, _);
2813
+ };
2814
+ }, [g, L]), w = or({
2815
+ resolver: h,
2816
+ values: k,
2817
+ resetOptions: { keepDirtyValues: !0 }
2818
+ }), { formState: S } = w, j = S.isSubmitting || T.create.isPending || T.update.isPending, B = w.handleSubmit(async ($) => {
2819
+ w.clearErrors("root.server");
2820
+ const { values: E, jsonErrors: N } = Gi({
2821
+ fields: v,
2822
+ raw: $,
2823
+ mode: L,
2824
+ dirtyFields: w.formState.dirtyFields
2825
+ });
2826
+ if (N.length > 0) {
2827
+ for (const _ of N)
2828
+ w.setError(_.name, { type: "validate", message: _.message });
2829
+ return;
2830
+ }
2831
+ const F = l !== void 0 ? l(E) : E;
2832
+ try {
2833
+ const _ = n === void 0 ? await T.create.mutateAsync(F) : await T.update.mutateAsync({ id: n, values: F });
2834
+ n === void 0 ? w.reset() : w.reset(void 0, { keepValues: !0 }), o == null || o(_);
2835
+ } catch (_) {
2836
+ const P = /* @__PURE__ */ new Set([...v.map((J) => J.name), ...Object.keys($)]);
2837
+ to(_, P, w), a == null || a(_);
2838
+ }
2839
+ }), y = ((V = (O = S.errors.root) == null ? void 0 : O.server) == null ? void 0 : V.message) ?? ((K = S.errors.root) == null ? void 0 : K.message), C = ($) => {
2840
+ const E = S.errors[$];
2841
+ return typeof (E == null ? void 0 : E.message) == "string" ? E.message : void 0;
2842
+ };
2843
+ return /* @__PURE__ */ r(ar, { ...w, children: /* @__PURE__ */ d(
2844
+ "form",
2845
+ {
2846
+ onSubmit: ($) => {
2847
+ B($);
2848
+ },
2849
+ noValidate: !0,
2850
+ "aria-busy": j || void 0,
2851
+ className: b("space-y-5", f),
2852
+ children: [
2853
+ typeof y == "string" ? /* @__PURE__ */ r(
2854
+ "div",
2855
+ {
2856
+ role: "alert",
2857
+ className: "rounded-md border border-destructive/50 bg-destructive/10 px-3 py-2 text-sm text-destructive",
2858
+ children: y
2859
+ }
2860
+ ) : null,
2861
+ v.map(($) => {
2862
+ const E = s == null ? void 0 : s[$.name];
2863
+ return (E == null ? void 0 : E.hidden) === !0 ? null : /* @__PURE__ */ r(
2864
+ no,
2865
+ {
2866
+ field: $,
2867
+ override: E,
2868
+ control: w.control,
2869
+ error: C($.name),
2870
+ disabled: j
2871
+ },
2872
+ $.name
2873
+ );
2874
+ }),
2875
+ u,
2876
+ c !== void 0 ? c : /* @__PURE__ */ r("div", { className: "flex items-center justify-end gap-3 pt-2", children: /* @__PURE__ */ r(Y, { type: "submit", disabled: j, children: n === void 0 ? "Create" : "Save changes" }) })
2877
+ ]
2878
+ }
2879
+ ) });
2880
+ }
2881
+ function pa(e) {
2882
+ const { resource: t, id: n } = e, i = kt(t), o = n !== void 0, a = Rt(t, n ?? "", void 0, { enabled: o });
2883
+ return i.error != null ? /* @__PURE__ */ r(Xt, { error: i.error, className: e.className }) : o && a.error != null ? /* @__PURE__ */ r(Xt, { error: a.error, className: e.className }) : i.data === void 0 || o && a.data === void 0 ? /* @__PURE__ */ r(eo, { className: e.className }) : /* @__PURE__ */ r(
2884
+ ro,
2885
+ {
2886
+ ...e,
2887
+ schema: i.data,
2888
+ item: o ? a.data : void 0
2889
+ }
2890
+ );
2891
+ }
2892
+ ee("detail-view", "ResourceDetail");
2893
+ function io(e) {
2894
+ const n = (e.split(/[?#]/, 1)[0] ?? e).split("/").filter((i) => i !== "");
2895
+ return n[n.length - 1] ?? e;
2896
+ }
2897
+ function oo(e) {
2898
+ const t = /^(\d{4})-(\d{2})-(\d{2})/.exec(e);
2899
+ if (t !== null)
2900
+ return new Date(Number(t[1]), Number(t[2]) - 1, Number(t[3])).toLocaleDateString();
2901
+ const n = new Date(e);
2902
+ return Number.isNaN(n.getTime()) ? e : n.toLocaleDateString();
2903
+ }
2904
+ function ao(e) {
2905
+ const t = new Date(e);
2906
+ return Number.isNaN(t.getTime()) ? e : t.toLocaleString();
2907
+ }
2908
+ function qt({ value: e }) {
2909
+ return e !== null && typeof e == "object" ? /* @__PURE__ */ r(Q, { children: Oe(e) }) : /* @__PURE__ */ r("code", { className: "rounded bg-muted px-1 py-0.5 font-mono text-xs", children: String(e) });
2910
+ }
2911
+ function so({ value: e }) {
2912
+ return Array.isArray(e) ? e.length === 0 ? /* @__PURE__ */ r(Bn, {}) : /* @__PURE__ */ r("span", { className: "flex flex-wrap gap-1.5", children: e.map((t, n) => /* @__PURE__ */ r(
2913
+ "span",
2914
+ {
2915
+ className: "inline-flex items-center rounded-sm bg-secondary px-1.5 py-0.5 text-xs text-secondary-foreground",
2916
+ children: /* @__PURE__ */ r(qt, { value: t })
2917
+ },
2918
+ n
2919
+ )) }) : /* @__PURE__ */ r(qt, { value: e });
2920
+ }
2921
+ function Bn() {
2922
+ return /* @__PURE__ */ r("span", { className: "text-muted-foreground", children: "—" });
2923
+ }
2924
+ function lo({ field: e, value: t }) {
2925
+ var n;
2926
+ if (t == null || t === "") return /* @__PURE__ */ r(Bn, {});
2927
+ switch (e.kind) {
2928
+ case "boolean":
2929
+ return /* @__PURE__ */ r(Q, { children: t ? "Yes" : "No" });
2930
+ case "date":
2931
+ return /* @__PURE__ */ r(Q, { children: oo(String(t)) });
2932
+ case "datetime":
2933
+ return /* @__PURE__ */ r(Q, { children: ao(String(t)) });
2934
+ case "enum":
2935
+ return /* @__PURE__ */ r(Q, { children: ((n = e.enumLabels) == null ? void 0 : n[String(t)]) ?? Fn(String(t)) });
2936
+ case "relation":
2937
+ return /* @__PURE__ */ r(so, { value: t });
2938
+ case "file":
2939
+ return /* @__PURE__ */ r(
2940
+ "a",
2941
+ {
2942
+ href: String(t),
2943
+ target: "_blank",
2944
+ rel: "noreferrer",
2945
+ className: "font-medium text-primary underline underline-offset-4",
2946
+ children: io(String(t))
2947
+ }
2948
+ );
2949
+ case "json":
2950
+ return /* @__PURE__ */ r("pre", { className: "overflow-x-auto rounded-md bg-muted p-3 text-xs", children: JSON.stringify(t, null, 2) });
2951
+ case "number":
2952
+ case "integer":
2953
+ return /* @__PURE__ */ r(Q, { children: typeof t == "number" ? t.toLocaleString() : String(t) });
2954
+ case "array":
2955
+ return /* @__PURE__ */ r(Q, { children: Array.isArray(t) ? t.map(String).join(", ") : String(t) });
2956
+ default:
2957
+ return /* @__PURE__ */ r(Q, { children: String(t) });
2958
+ }
2959
+ }
2960
+ function co({ className: e }) {
2961
+ return /* @__PURE__ */ r("div", { role: "status", "aria-label": "Loading details", className: b("space-y-4", e), children: [0, 1, 2, 3].map((t) => /* @__PURE__ */ d("div", { className: "grid grid-cols-1 gap-2 sm:grid-cols-3 sm:gap-4", children: [
2962
+ /* @__PURE__ */ r(me, { className: "h-4 w-24" }),
2963
+ /* @__PURE__ */ r(me, { className: "h-4 w-48 sm:col-span-2" })
2964
+ ] }, t)) });
2965
+ }
2966
+ function uo({
2967
+ error: e,
2968
+ onRetry: t,
2969
+ className: n
2970
+ }) {
2971
+ return /* @__PURE__ */ d(
2972
+ "div",
2973
+ {
2974
+ role: "alert",
2975
+ className: b(
2976
+ "space-y-3 rounded-md border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",
2977
+ n
2978
+ ),
2979
+ children: [
2980
+ /* @__PURE__ */ r("p", { children: e instanceof Error ? e.message : String(e) }),
2981
+ /* @__PURE__ */ r(Y, { variant: "outline", size: "sm", onClick: t, children: "Retry" })
2982
+ ]
2983
+ }
2984
+ );
2985
+ }
2986
+ function It(e) {
2987
+ const { field: t, item: n, override: i, muted: o } = e, a = n[t.name];
2988
+ return /* @__PURE__ */ d(
2989
+ "div",
2990
+ {
2991
+ className: b(
2992
+ "grid grid-cols-1 gap-1 sm:grid-cols-3 sm:gap-4",
2993
+ o ? "py-2 text-xs" : "py-3 text-sm"
2994
+ ),
2995
+ children: [
2996
+ /* @__PURE__ */ r("dt", { className: "font-medium text-muted-foreground", children: (i == null ? void 0 : i.label) ?? t.label }),
2997
+ /* @__PURE__ */ r("dd", { className: b("sm:col-span-2", o ? "text-muted-foreground" : "text-foreground"), children: (i == null ? void 0 : i.render) !== void 0 ? i.render(a, n) : /* @__PURE__ */ r(lo, { field: t, value: a }) })
2998
+ ]
2999
+ }
3000
+ );
3001
+ }
3002
+ function ba(e) {
3003
+ const { resource: t, id: n, fields: i, sections: o, expand: a, title: s, actions: u, className: l } = e, c = m.useId(), f = kt(t), g = m.useMemo(
3004
+ () => a !== void 0 && a.length > 0 ? { expand: a } : void 0,
3005
+ [a]
3006
+ ), x = Rt(t, n, g), L = f.error ?? x.error;
3007
+ if (L != null)
3008
+ return /* @__PURE__ */ r(
3009
+ uo,
3010
+ {
3011
+ error: L,
3012
+ onRetry: () => {
3013
+ x.refetch();
3014
+ },
3015
+ className: l
3016
+ }
3017
+ );
3018
+ if (f.data === void 0 || x.data === void 0)
3019
+ return /* @__PURE__ */ r(co, { className: l });
3020
+ const T = x.data, v = f.data.fields.filter(
3021
+ (w) => {
3022
+ var S;
3023
+ return !w.writeOnly && w.kind !== "unknown" && ((S = i == null ? void 0 : i[w.name]) == null ? void 0 : S.hidden) !== !0;
3024
+ }
3025
+ ), { domain: k, audit: h } = At(v);
3026
+ return /* @__PURE__ */ d("div", { className: b("space-y-6", l), children: [
3027
+ s !== void 0 || u !== void 0 ? /* @__PURE__ */ d("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [
3028
+ s !== void 0 ? /* @__PURE__ */ r("h2", { className: "text-lg font-semibold tracking-tight", children: s }) : /* @__PURE__ */ r("div", {}),
3029
+ u !== void 0 ? /* @__PURE__ */ r("div", { className: "flex items-center gap-2", children: u }) : null
3030
+ ] }) : null,
3031
+ /* @__PURE__ */ r("dl", { className: "divide-y divide-border", children: k.map((w) => /* @__PURE__ */ r(
3032
+ It,
3033
+ {
3034
+ field: w,
3035
+ item: T,
3036
+ override: i == null ? void 0 : i[w.name],
3037
+ muted: !1
3038
+ },
3039
+ w.name
3040
+ )) }),
3041
+ h.length > 0 ? /* @__PURE__ */ d(
3042
+ "section",
3043
+ {
3044
+ "aria-labelledby": c,
3045
+ className: "rounded-md border border-border bg-muted/40 px-4 py-2",
3046
+ children: [
3047
+ /* @__PURE__ */ r(
3048
+ "h3",
3049
+ {
3050
+ id: c,
3051
+ className: "py-1 text-xs font-medium uppercase tracking-wide text-muted-foreground",
3052
+ children: "Record"
3053
+ }
3054
+ ),
3055
+ /* @__PURE__ */ r("dl", { className: "divide-y divide-border", children: h.map((w) => /* @__PURE__ */ r(
3056
+ It,
3057
+ {
3058
+ field: w,
3059
+ item: T,
3060
+ override: i == null ? void 0 : i[w.name],
3061
+ muted: !0
3062
+ },
3063
+ w.name
3064
+ )) })
3065
+ ]
3066
+ }
3067
+ ) : null,
3068
+ o !== void 0 && o.length > 0 ? /* @__PURE__ */ r("div", { className: "space-y-6", children: o.map((w, S) => /* @__PURE__ */ r("div", { children: w }, S)) }) : null
3069
+ ] });
3070
+ }
3071
+ function mo(e, t, n) {
3072
+ return [...he.resource(e), "history", String(t), n ?? {}];
3073
+ }
3074
+ function fo(e, t, n, i) {
3075
+ const o = ge();
3076
+ return _e({
3077
+ ...i,
3078
+ queryKey: mo(e, t, n),
3079
+ queryFn: ({ signal: a }) => o.request(`${Ie(e, t)}history/`, {
3080
+ query: { page_size: n == null ? void 0 : n.pageSize, page: n == null ? void 0 : n.page },
3081
+ signal: a
3082
+ })
3083
+ });
3084
+ }
3085
+ ee("change-history", "ChangeHistory");
3086
+ const ho = {
3087
+ create: "Created",
3088
+ update: "Updated",
3089
+ delete: "Deleted",
3090
+ restore: "Restored"
3091
+ };
3092
+ function go(e) {
3093
+ const t = new Date(e);
3094
+ return Number.isNaN(t.getTime()) ? e : t.toLocaleString();
3095
+ }
3096
+ function en({ value: e }) {
3097
+ if (e == null || e === "")
3098
+ return /* @__PURE__ */ r("span", { className: "text-muted-foreground", children: "—" });
3099
+ if (e === "[redacted]")
3100
+ return /* @__PURE__ */ r("span", { className: "italic text-muted-foreground", children: "redacted" });
3101
+ const t = typeof e == "object" ? JSON.stringify(e) : String(e);
3102
+ return /* @__PURE__ */ r("span", { className: "break-words", children: t });
3103
+ }
3104
+ function po({ entry: e }) {
3105
+ var n;
3106
+ const t = Object.entries(e.diff);
3107
+ return /* @__PURE__ */ d("li", { className: "rounded-md border bg-card p-3 text-sm", "data-action": e.action, children: [
3108
+ /* @__PURE__ */ d("div", { className: "flex flex-wrap items-baseline gap-x-3 gap-y-1", children: [
3109
+ /* @__PURE__ */ r("span", { className: "font-medium", children: ho[e.action] ?? e.action }),
3110
+ /* @__PURE__ */ r("time", { dateTime: e.timestamp, className: "text-muted-foreground", children: go(e.timestamp) }),
3111
+ /* @__PURE__ */ r("span", { className: "text-muted-foreground", children: ((n = e.actor) == null ? void 0 : n.email) ?? "—" })
3112
+ ] }),
3113
+ t.length > 0 ? /* @__PURE__ */ r("dl", { className: "mt-2 grid grid-cols-[max-content_1fr] gap-x-3 gap-y-1", children: t.map(([i, [o, a]]) => /* @__PURE__ */ d(m.Fragment, { children: [
3114
+ /* @__PURE__ */ r("dt", { className: "font-mono text-xs text-muted-foreground", children: i }),
3115
+ /* @__PURE__ */ d("dd", { className: "flex flex-wrap items-center gap-2", children: [
3116
+ /* @__PURE__ */ r(en, { value: o }),
3117
+ /* @__PURE__ */ r("span", { "aria-hidden": "true", className: "text-muted-foreground", children: "→" }),
3118
+ /* @__PURE__ */ r(en, { value: a })
3119
+ ] })
3120
+ ] }, i)) }) : /* @__PURE__ */ r("p", { className: "mt-2 text-muted-foreground", children: "No visible field changed." })
3121
+ ] });
3122
+ }
3123
+ function ya({
3124
+ resource: e,
3125
+ id: t,
3126
+ pageSize: n,
3127
+ title: i = "History",
3128
+ empty: o = "No changes recorded.",
3129
+ className: a
3130
+ }) {
3131
+ const s = fo(e, t, n !== void 0 ? { pageSize: n } : void 0);
3132
+ return /* @__PURE__ */ d("section", { className: b("space-y-3", a), "aria-label": "Change history", children: [
3133
+ i !== null ? /* @__PURE__ */ r("h3", { className: "text-base font-semibold", children: i }) : null,
3134
+ s.isPending ? /* @__PURE__ */ d("div", { className: "space-y-2", "data-testid": "change-history-loading", children: [
3135
+ /* @__PURE__ */ r(me, { className: "h-16 w-full" }),
3136
+ /* @__PURE__ */ r(me, { className: "h-16 w-full" })
3137
+ ] }) : s.error ? /* @__PURE__ */ r("p", { role: "alert", className: "text-sm text-destructive", children: s.error instanceof Error ? s.error.message : "History could not be loaded." }) : s.data.results.length === 0 ? /* @__PURE__ */ r("p", { className: "text-sm text-muted-foreground", children: o }) : /* @__PURE__ */ r("ol", { className: "space-y-2", children: s.data.results.map((u) => /* @__PURE__ */ r(po, { entry: u }, u.id)) })
3138
+ ] });
3139
+ }
3140
+ ee("resource-import", "ResourceImport");
3141
+ function lt(e) {
3142
+ if (e instanceof Error) {
3143
+ const t = e.data;
3144
+ if (typeof t == "object" && t !== null && "detail" in t) {
3145
+ const n = t.detail;
3146
+ if (typeof n == "string") return n;
3147
+ }
3148
+ return e.message;
3149
+ }
3150
+ return "Something went wrong.";
3151
+ }
3152
+ function bo({ job: e }) {
3153
+ if (e.result === null) return null;
3154
+ const { created: t, updated: n, skipped: i, unchanged: o, errors: a } = e.result;
3155
+ return /* @__PURE__ */ d("dl", { className: "flex flex-wrap gap-6", "data-testid": "import-stats", children: [
3156
+ /* @__PURE__ */ d("div", { children: [
3157
+ /* @__PURE__ */ r("dt", { className: "text-xs uppercase text-muted-foreground", children: "Created" }),
3158
+ /* @__PURE__ */ r("dd", { className: "text-2xl font-semibold", children: t })
3159
+ ] }),
3160
+ /* @__PURE__ */ d("div", { children: [
3161
+ /* @__PURE__ */ r("dt", { className: "text-xs uppercase text-muted-foreground", children: "Updated" }),
3162
+ /* @__PURE__ */ r("dd", { className: "text-2xl font-semibold", children: n })
3163
+ ] }),
3164
+ /* @__PURE__ */ d("div", { children: [
3165
+ /* @__PURE__ */ r("dt", { className: "text-xs uppercase text-muted-foreground", children: "Skipped" }),
3166
+ /* @__PURE__ */ d("dd", { className: "text-2xl font-semibold", children: [
3167
+ i,
3168
+ " ",
3169
+ /* @__PURE__ */ d("span", { className: "text-sm font-normal text-muted-foreground", children: [
3170
+ "(",
3171
+ o,
3172
+ " unchanged, ",
3173
+ a,
3174
+ " with errors)"
3175
+ ] })
3176
+ ] })
3177
+ ] })
3178
+ ] });
3179
+ }
3180
+ function yo({ job: e }) {
3181
+ return e.problems.length === 0 ? null : /* @__PURE__ */ r("div", { className: "overflow-x-auto rounded-md border border-border", children: /* @__PURE__ */ d("table", { className: "w-full text-sm", "aria-label": "Rows with errors", children: [
3182
+ /* @__PURE__ */ r("thead", { className: "bg-muted text-left text-xs uppercase text-muted-foreground", children: /* @__PURE__ */ d("tr", { children: [
3183
+ /* @__PURE__ */ r("th", { className: "px-3 py-2", children: "Row" }),
3184
+ /* @__PURE__ */ r("th", { className: "px-3 py-2", children: "Field" }),
3185
+ /* @__PURE__ */ r("th", { className: "px-3 py-2", children: "Problem" })
3186
+ ] }) }),
3187
+ /* @__PURE__ */ r("tbody", { children: e.problems.map((t, n) => /* @__PURE__ */ d("tr", { className: "border-t border-border", children: [
3188
+ /* @__PURE__ */ r("td", { className: "px-3 py-2 tabular-nums", children: t.row }),
3189
+ /* @__PURE__ */ r("td", { className: "px-3 py-2 font-mono text-xs", children: t.field || "—" }),
3190
+ /* @__PURE__ */ r("td", { className: "px-3 py-2 text-destructive", children: t.message })
3191
+ ] }, `${t.row}-${t.field}-${n}`)) })
3192
+ ] }) });
3193
+ }
3194
+ function xo({ job: e }) {
3195
+ const t = e.rows_total > 0 ? Math.round(e.rows_done * 100 / e.rows_total) : 0;
3196
+ return /* @__PURE__ */ d("div", { className: "space-y-2", role: "status", "aria-live": "polite", children: [
3197
+ /* @__PURE__ */ d("p", { className: "text-sm", children: [
3198
+ e.status === "previewing" ? "Previewing" : "Committing",
3199
+ "… ",
3200
+ e.rows_done,
3201
+ " /",
3202
+ " ",
3203
+ e.rows_total,
3204
+ " rows"
3205
+ ] }),
3206
+ /* @__PURE__ */ r("div", { className: "h-2 w-full overflow-hidden rounded bg-muted", children: /* @__PURE__ */ r("div", { className: "h-full bg-primary transition-all", style: { width: `${t}%` } }) })
3207
+ ] });
3208
+ }
3209
+ function vo(e) {
3210
+ const { job: t, fields: n, mapping: i, onChange: o } = e, a = n.map((s) => ({
3211
+ value: s.name,
3212
+ label: `${s.name}${s.required ? " *" : ""}${s.key ? " (key)" : ""}`
3213
+ }));
3214
+ return /* @__PURE__ */ r("div", { className: "overflow-x-auto rounded-md border border-border", children: /* @__PURE__ */ d("table", { className: "w-full text-sm", "aria-label": "Column mapping", children: [
3215
+ /* @__PURE__ */ r("thead", { className: "bg-muted text-left text-xs uppercase text-muted-foreground", children: /* @__PURE__ */ d("tr", { children: [
3216
+ /* @__PURE__ */ r("th", { className: "px-3 py-2", children: "Column in the file" }),
3217
+ /* @__PURE__ */ r("th", { className: "px-3 py-2", children: "Field" })
3218
+ ] }) }),
3219
+ /* @__PURE__ */ r("tbody", { children: t.columns.map((s) => /* @__PURE__ */ d("tr", { className: "border-t border-border", children: [
3220
+ /* @__PURE__ */ r("td", { className: "px-3 py-2", children: s }),
3221
+ /* @__PURE__ */ r("td", { className: "px-3 py-2", children: /* @__PURE__ */ r(
3222
+ Qe,
3223
+ {
3224
+ "aria-label": `Field for ${s}`,
3225
+ className: "h-9 w-auto min-w-48",
3226
+ value: i[s] ?? "",
3227
+ options: a,
3228
+ clearable: !0,
3229
+ clearLabel: "— ignore —",
3230
+ onValueChange: (u) => o(s, u ?? "")
3231
+ }
3232
+ ) })
3233
+ ] }, s)) })
3234
+ ] }) });
3235
+ }
3236
+ function xa({
3237
+ resource: e,
3238
+ title: t = "Import",
3239
+ onDone: n,
3240
+ className: i
3241
+ }) {
3242
+ var K;
3243
+ const o = ge(), a = li(e), s = ui(e), [u, l] = m.useState(void 0), [c, f] = m.useState({}), [g, x] = m.useState(!1), [L, T] = m.useState(null), v = m.useRef(null), k = ci(e, u), h = k.data, w = m.useRef(void 0);
3244
+ m.useEffect(() => {
3245
+ h !== void 0 && w.current !== h.id && (w.current = h.id, f(h.mapping));
3246
+ }, [h]), m.useEffect(() => {
3247
+ (h == null ? void 0 : h.status) === "done" && (n == null || n(h));
3248
+ }, [h == null ? void 0 : h.status, h == null ? void 0 : h.id]);
3249
+ const S = (h == null ? void 0 : h.fields) ?? ((K = a.data) == null ? void 0 : K.fields) ?? [], j = s.upload.isPending || s.preview.isPending || s.commit.isPending, B = s.upload.error ?? s.preview.error ?? s.commit.error, y = ($) => {
3250
+ var N, F;
3251
+ $.preventDefault();
3252
+ const E = (F = (N = v.current) == null ? void 0 : N.files) == null ? void 0 : F[0];
3253
+ E !== void 0 && (x(!1), s.upload.mutate({ file: E }, { onSuccess: (_) => l(_.id) }));
3254
+ }, C = () => {
3255
+ h !== void 0 && (x(!1), s.preview.mutate({ jobId: h.id, mapping: c }));
3256
+ }, O = ($) => {
3257
+ T(null), si(o, e, $).catch(
3258
+ (E) => T(lt(E))
3259
+ );
3260
+ };
3261
+ let V;
3262
+ return a.isPending ? V = /* @__PURE__ */ r(me, { className: "h-24 w-full", "data-testid": "resource-import-loading" }) : h === void 0 || u !== void 0 && k.isPending ? V = /* @__PURE__ */ d("form", { onSubmit: y, className: "flex flex-wrap items-end gap-3", children: [
3263
+ /* @__PURE__ */ d("label", { className: "flex flex-col gap-1 text-sm", children: [
3264
+ /* @__PURE__ */ r("span", { children: "CSV or XLSX file" }),
3265
+ /* @__PURE__ */ r(
3266
+ "input",
3267
+ {
3268
+ ref: v,
3269
+ type: "file",
3270
+ name: "file",
3271
+ accept: ".csv,.xlsx",
3272
+ required: !0,
3273
+ className: "text-sm",
3274
+ "aria-label": "File to import"
3275
+ }
3276
+ )
3277
+ ] }),
3278
+ /* @__PURE__ */ r(Y, { type: "submit", disabled: j, children: "Upload" })
3279
+ ] }) : En(h) ? V = /* @__PURE__ */ r(xo, { job: h }) : h.status === "uploaded" || h.status === "failed" || g ? V = /* @__PURE__ */ d("div", { className: "space-y-3", children: [
3280
+ h.error !== null && /* @__PURE__ */ r("p", { role: "alert", className: "text-sm text-destructive", children: h.error }),
3281
+ /* @__PURE__ */ d("p", { className: "text-sm text-muted-foreground", children: [
3282
+ h.file_name,
3283
+ " — ",
3284
+ h.rows_total,
3285
+ " rows. Map each column to a field; blank cells leave a field unchanged."
3286
+ ] }),
3287
+ /* @__PURE__ */ r(
3288
+ vo,
3289
+ {
3290
+ job: h,
3291
+ fields: S,
3292
+ mapping: c,
3293
+ onChange: ($, E) => f((N) => ({ ...N, [$]: E }))
3294
+ }
3295
+ ),
3296
+ /* @__PURE__ */ d("div", { className: "flex flex-wrap gap-2", children: [
3297
+ /* @__PURE__ */ r(Y, { onClick: C, disabled: j, children: "Preview" }),
3298
+ /* @__PURE__ */ r(Y, { variant: "outline", onClick: () => l(void 0), disabled: j, children: "Upload another file" })
3299
+ ] })
3300
+ ] }) : V = /* @__PURE__ */ d("div", { className: "space-y-3", children: [
3301
+ /* @__PURE__ */ d("p", { className: "text-sm text-muted-foreground", children: [
3302
+ h.file_name,
3303
+ " — ",
3304
+ h.rows_total,
3305
+ " rows,",
3306
+ " ",
3307
+ h.status === "done" ? "imported." : "previewed; nothing is saved yet."
3308
+ ] }),
3309
+ /* @__PURE__ */ r(bo, { job: h }),
3310
+ /* @__PURE__ */ r(yo, { job: h }),
3311
+ /* @__PURE__ */ r("div", { className: "flex flex-wrap gap-2", children: h.status === "previewed" ? /* @__PURE__ */ d(Q, { children: [
3312
+ /* @__PURE__ */ r(Y, { onClick: () => s.commit.mutate(h.id), disabled: j, children: "Commit" }),
3313
+ /* @__PURE__ */ r(Y, { variant: "outline", onClick: () => x(!0), disabled: j, children: "Change the mapping" })
3314
+ ] }) : /* @__PURE__ */ r(Y, { variant: "outline", onClick: () => l(void 0), children: "Import another file" }) })
3315
+ ] }), /* @__PURE__ */ d("section", { className: b("space-y-3", i), "aria-label": "Import", children: [
3316
+ /* @__PURE__ */ d("div", { className: "flex flex-wrap items-baseline justify-between gap-2", children: [
3317
+ t !== null ? /* @__PURE__ */ r("h3", { className: "text-base font-semibold", children: t }) : null,
3318
+ /* @__PURE__ */ d("div", { className: "flex gap-2 text-sm", children: [
3319
+ /* @__PURE__ */ r(
3320
+ "button",
3321
+ {
3322
+ type: "button",
3323
+ className: "text-primary underline-offset-4 hover:underline",
3324
+ onClick: () => O("xlsx"),
3325
+ children: "Download template (XLSX)"
3326
+ }
3327
+ ),
3328
+ /* @__PURE__ */ r(
3329
+ "button",
3330
+ {
3331
+ type: "button",
3332
+ className: "text-primary underline-offset-4 hover:underline",
3333
+ onClick: () => O("csv"),
3334
+ children: "CSV"
3335
+ }
3336
+ )
3337
+ ] })
3338
+ ] }),
3339
+ a.error !== null && a.error !== void 0 ? /* @__PURE__ */ r("p", { role: "alert", className: "text-sm text-destructive", children: lt(a.error) }) : null,
3340
+ B != null ? /* @__PURE__ */ r("p", { role: "alert", className: "text-sm text-destructive", children: lt(B) }) : null,
3341
+ L !== null ? /* @__PURE__ */ r("p", { role: "alert", className: "text-sm text-destructive", children: L }) : null,
3342
+ V
3343
+ ] });
3344
+ }
3345
+ function wo(e) {
3346
+ return typeof e == "object" && e !== null && !Array.isArray(e);
3347
+ }
3348
+ function No(e, t) {
3349
+ return wo(t) && typeof t.detail == "string" ? t.detail : `Karni API request failed with status ${e}`;
3350
+ }
3351
+ class tn extends Error {
3352
+ constructor(n, i, o) {
3353
+ super(o ?? No(n, i));
3354
+ G(this, "status");
3355
+ /** Parsed body when JSON (field errors, detail, non_field_errors), else text. */
3356
+ G(this, "data");
3357
+ this.name = "KarniApiError", this.status = n, this.data = i;
3358
+ }
3359
+ }
3360
+ function So(e) {
3361
+ const t = /^(https?:\/\/[^/]+)(\/.*)?$/.exec(e);
3362
+ return t !== null ? { origin: t[1] ?? "", basePath: (t[2] ?? "").replace(/\/+$/, "") } : { origin: "", basePath: e.replace(/\/+$/, "") };
3363
+ }
3364
+ function ko(e, t) {
3365
+ if (/^https?:\/\//.test(t)) return t;
3366
+ const { origin: n, basePath: i } = So(e), o = t.startsWith("/") ? t : `/${t}`;
3367
+ return i !== "" && (o === i || o.startsWith(`${i}/`)) ? n + o : n + i + o;
3368
+ }
3369
+ function Co(e, t) {
3370
+ if (t === void 0) return e;
3371
+ const n = new URLSearchParams();
3372
+ for (const [o, a] of Object.entries(t))
3373
+ if (a != null)
3374
+ if (Array.isArray(a))
3375
+ for (const s of a) n.append(o, String(s));
3376
+ else
3377
+ n.append(o, String(a));
3378
+ const i = n.toString();
3379
+ return i === "" ? e : e.includes("?") ? `${e}&${i}` : `${e}?${i}`;
3380
+ }
3381
+ async function ct(e) {
3382
+ if (e.status === 204 || e.status === 205) return;
3383
+ const t = await e.text();
3384
+ if (t === "") return;
3385
+ if ((e.headers.get("content-type") ?? "").includes("json"))
3386
+ try {
3387
+ return JSON.parse(t);
3388
+ } catch {
3389
+ return t;
3390
+ }
3391
+ return t;
3392
+ }
3393
+ function va(e) {
3394
+ const { baseUrl: t, schemaUrl: n = "/api/schema/", fetch: i } = e;
3395
+ let o = {};
3396
+ e.getAccessToken !== void 0 && (o = { getAccessToken: e.getAccessToken });
3397
+ async function a(u, l) {
3398
+ var v, k;
3399
+ const c = new Headers({ accept: "application/json" }), f = (v = o.getHeaders) == null ? void 0 : v.call(o);
3400
+ if (f !== void 0)
3401
+ for (const [h, w] of Object.entries(f)) c.set(h, w);
3402
+ if (l.headers !== void 0)
3403
+ for (const [h, w] of Object.entries(l.headers))
3404
+ c.set(h, w);
3405
+ const g = ((k = o.getAccessToken) == null ? void 0 : k.call(o)) ?? null;
3406
+ g !== null && g !== "" && c.set("authorization", `Bearer ${g}`);
3407
+ let x;
3408
+ typeof FormData < "u" && l.body instanceof FormData ? x = l.body : l.body !== void 0 && (x = JSON.stringify(l.body), c.has("content-type") || c.set("content-type", "application/json"));
3409
+ const L = { method: l.method ?? "GET", headers: c };
3410
+ return x !== void 0 && (L.body = x), l.signal !== void 0 && (L.signal = l.signal), o.credentials !== void 0 && (L.credentials = o.credentials), (i ?? globalThis.fetch)(u, L);
3411
+ }
3412
+ async function s(u, l = {}) {
3413
+ const c = Co(ko(t, u), l.query);
3414
+ let f = await a(c, l);
3415
+ if (f.ok) return f;
3416
+ const g = new tn(f.status, await ct(f));
3417
+ if (f.status === 401 && o.onUnauthorized !== void 0 && l.skipAuthRefresh !== !0 && await o.onUnauthorized(g)) {
3418
+ if (f = await a(c, l), f.ok) return f;
3419
+ throw new tn(f.status, await ct(f));
3420
+ }
3421
+ throw g;
3422
+ }
3423
+ return {
3424
+ baseUrl: t,
3425
+ schemaUrl: n,
3426
+ async request(u, l = {}) {
3427
+ const c = await s(u, l);
3428
+ return await ct(c);
3429
+ },
3430
+ requestRaw: s,
3431
+ setAuthHooks(u) {
3432
+ o = { ...o, ...u };
3433
+ }
3434
+ };
3435
+ }
3436
+ function nn(e) {
3437
+ if (typeof e != "object" || e === null) return;
3438
+ const t = e, n = t.authMode ?? t["x-karni-auth-mode"];
3439
+ return n === "jwt" || n === "session" ? n : void 0;
3440
+ }
3441
+ function Ye(e) {
3442
+ if (typeof e != "object" || e === null) return null;
3443
+ const t = e, { id: n, email: i } = t;
3444
+ if (typeof n != "string" && typeof n != "number" || typeof i != "string") return null;
3445
+ const o = Array.isArray(t.roles) ? t.roles.filter((a) => typeof a == "string") : [];
3446
+ return { ...t, id: n, email: i, roles: o };
3447
+ }
3448
+ function ut(e) {
3449
+ if (typeof document > "u") return null;
3450
+ try {
3451
+ for (const t of document.cookie.split(";")) {
3452
+ const n = t.trim(), i = n.indexOf("=");
3453
+ if (i !== -1 && n.slice(0, i) === e)
3454
+ return decodeURIComponent(n.slice(i + 1));
3455
+ }
3456
+ } catch {
3457
+ }
3458
+ return null;
3459
+ }
3460
+ function dt(e) {
3461
+ if (typeof e != "object" || e === null) return `a ${typeof e}`;
3462
+ const t = Object.keys(e);
3463
+ return t.length === 0 ? "an empty object" : `an object with keys [${t.join(", ")}]`;
3464
+ }
3465
+ function rn(e) {
3466
+ if (typeof e != "object" || e === null) return null;
3467
+ const t = e;
3468
+ return t.requires_2fa !== !0 ? null : typeof t.ephemeral_token == "string" ? { ephemeralToken: t.ephemeral_token } : null;
3469
+ }
3470
+ class Ao {
3471
+ constructor(t) {
3472
+ G(this, "client");
3473
+ G(this, "tokenStorage");
3474
+ G(this, "modeOverride");
3475
+ G(this, "csrfCookieName");
3476
+ G(this, "csrfHeaderName");
3477
+ G(this, "authBasePath");
3478
+ G(this, "readCachedSchema");
3479
+ G(this, "mode");
3480
+ G(this, "accessToken", null);
3481
+ G(this, "refreshPromise", null);
3482
+ G(this, "initPromise", null);
3483
+ G(this, "listeners", /* @__PURE__ */ new Set());
3484
+ G(this, "state");
3485
+ // --- state mirroring (consumed by <AuthProvider> via useSyncExternalStore)
3486
+ G(this, "subscribe", (t) => (this.listeners.add(t), () => {
3487
+ this.listeners.delete(t);
3488
+ }));
3489
+ G(this, "getSnapshot", () => this.state);
3490
+ this.client = t.client, this.tokenStorage = t.tokenStorage, this.modeOverride = t.modeOverride, this.csrfCookieName = t.csrfCookieName ?? "csrftoken", this.csrfHeaderName = t.csrfHeaderName ?? "X-CSRFToken", this.authBasePath = (t.authBasePath ?? "/auth").replace(/\/+$/, ""), this.readCachedSchema = t.readCachedSchema, this.mode = t.modeOverride ?? null, this.state = { status: "loading", user: null, mode: this.mode }, this.attach();
3491
+ }
3492
+ // client hook registration
3493
+ /** Registers the D6 hook points on the client. Idempotent. */
3494
+ attach() {
3495
+ this.client.setAuthHooks({
3496
+ getAccessToken: () => this.accessToken,
3497
+ onUnauthorized: () => this.handleUnauthorized(),
3498
+ getHeaders: () => this.csrfHeaders(),
3499
+ ...this.mode === "session" ? { credentials: "include" } : {}
3500
+ });
3501
+ }
3502
+ /**
3503
+ * Clears every hook this engine registered (including a `getAccessToken`
3504
+ * the app passed to createKarniClient — an unmounted AuthProvider leaves
3505
+ * the client fully unauthenticated by design).
3506
+ */
3507
+ detach() {
3508
+ this.client.setAuthHooks({
3509
+ getAccessToken: void 0,
3510
+ onUnauthorized: void 0,
3511
+ getHeaders: void 0,
3512
+ credentials: void 0
3513
+ });
3514
+ }
3515
+ csrfHeaders() {
3516
+ if (this.mode !== "session") return {};
3517
+ const t = ut(this.csrfCookieName);
3518
+ return t === null ? {} : { [this.csrfHeaderName]: t };
3519
+ }
3520
+ /**
3521
+ * The client calls this at most once per 401-ing request (D6). Returning
3522
+ * true makes the client retry that request exactly once with
3523
+ * freshly-injected credentials; the retry's outcome is always surfaced.
3524
+ */
3525
+ async handleUnauthorized() {
3526
+ return await this.ensureInitialized(), this.mode !== "jwt" ? (this.state.status === "authenticated" && this.setState("anonymous", null), !1) : this.tokenStorage.get() === null ? !1 : this.ensureRefresh();
3527
+ }
3528
+ setState(t, n) {
3529
+ this.state = { status: t, user: n, mode: this.mode };
3530
+ for (const i of this.listeners) i();
3531
+ }
3532
+ // bootstrap
3533
+ /** Idempotent: the first call kicks off mode resolution + session restore. */
3534
+ ensureInitialized() {
3535
+ return this.initPromise ?? (this.initPromise = this.initialize()), this.initPromise;
3536
+ }
3537
+ async initialize() {
3538
+ var t;
3539
+ try {
3540
+ if (this.mode = this.modeOverride ?? nn((t = this.readCachedSchema) == null ? void 0 : t.call(this)) ?? await this.fetchSchemaAuthMode() ?? "jwt", this.mode === "session") {
3541
+ this.client.setAuthHooks({ credentials: "include" }), await this.ensureCsrfToken(), await this.syncUser();
3542
+ return;
3543
+ }
3544
+ if (this.tokenStorage.get() === null) {
3545
+ this.setState("anonymous", null);
3546
+ return;
3547
+ }
3548
+ if (!await this.ensureRefresh()) return;
3549
+ await this.syncUser();
3550
+ } catch {
3551
+ this.setState("anonymous", null);
3552
+ }
3553
+ }
3554
+ async fetchSchemaAuthMode() {
3555
+ try {
3556
+ const t = await this.client.request(this.client.schemaUrl, {
3557
+ skipAuthRefresh: !0
3558
+ });
3559
+ return nn(t);
3560
+ } catch {
3561
+ return;
3562
+ }
3563
+ }
3564
+ /** Fetches `/me/` and mirrors the result; any failure means anonymous. */
3565
+ async syncUser() {
3566
+ try {
3567
+ const t = await this.client.request(`${this.authBasePath}/me/`, {
3568
+ skipAuthRefresh: !0
3569
+ }), n = Ye(t);
3570
+ n === null ? this.setState("anonymous", null) : this.setState("authenticated", n);
3571
+ } catch {
3572
+ this.setState("anonymous", null);
3573
+ }
3574
+ }
3575
+ /**
3576
+ * Reads the CSRF cookie, bootstrapping it via `GET <authBasePath>/csrf/`
3577
+ * when absent (A4). Returns null when the cookie stays unreadable (e.g.
3578
+ * CSRF_COOKIE_HTTPONLY) — requests then go out without the header and the
3579
+ * backend's 403 surfaces, which is the honest failure mode.
3580
+ */
3581
+ async ensureCsrfToken() {
3582
+ let t = ut(this.csrfCookieName);
3583
+ if (t === null) {
3584
+ try {
3585
+ await this.client.request(`${this.authBasePath}/csrf/`, {
3586
+ method: "GET",
3587
+ skipAuthRefresh: !0
3588
+ });
3589
+ } catch {
3590
+ }
3591
+ t = ut(this.csrfCookieName);
3592
+ }
3593
+ return t;
3594
+ }
3595
+ // refresh (D6)
3596
+ /** ONE shared in-flight refresh; resolves true on success. */
3597
+ ensureRefresh() {
3598
+ return this.refreshPromise === null && (this.refreshPromise = this.performRefresh().finally(() => {
3599
+ this.refreshPromise = null;
3600
+ })), this.refreshPromise;
3601
+ }
3602
+ async performRefresh() {
3603
+ const t = this.tokenStorage.get();
3604
+ if (t === null)
3605
+ return this.accessToken = null, this.setState("anonymous", null), !1;
3606
+ this.accessToken = null;
3607
+ try {
3608
+ const n = await this.client.request(`${this.authBasePath}/refresh/`, {
3609
+ method: "POST",
3610
+ body: { refresh: t },
3611
+ skipAuthRefresh: !0
3612
+ // a 401 here can never recurse (D6)
3613
+ }), i = typeof n == "object" && n !== null ? n : {}, o = i.access;
3614
+ if (typeof o != "string" || o === "")
3615
+ throw new Error(
3616
+ `Karni auth: ${this.authBasePath}/refresh/ returned ${dt(n)} instead of { access, refresh? }.`
3617
+ );
3618
+ const a = i.refresh;
3619
+ return typeof a == "string" && a !== "" && this.tokenStorage.set(a), this.accessToken = o, !0;
3620
+ } catch {
3621
+ return this.tokenStorage.clear(), this.accessToken = null, this.setState("anonymous", null), !1;
3622
+ }
3623
+ }
3624
+ // public auth actions
3625
+ async login(t, n) {
3626
+ await this.ensureInitialized();
3627
+ const i = `${this.authBasePath}/login/`;
3628
+ if (this.mode === "session") {
3629
+ await this.ensureCsrfToken();
3630
+ const f = await this.client.request(i, {
3631
+ method: "POST",
3632
+ body: { email: t, password: n },
3633
+ skipAuthRefresh: !0
3634
+ }), g = rn(f);
3635
+ if (g !== null)
3636
+ return { requires2fa: !0, ephemeralToken: g.ephemeralToken };
3637
+ const x = Ye(f) ?? await this.fetchMe(i);
3638
+ return this.setState("authenticated", x), { ok: !0, user: x };
3639
+ }
3640
+ const o = await this.client.request(i, {
3641
+ method: "POST",
3642
+ body: { email: t, password: n },
3643
+ skipAuthRefresh: !0
3644
+ }), a = rn(o);
3645
+ if (a !== null)
3646
+ return { requires2fa: !0, ephemeralToken: a.ephemeralToken };
3647
+ const s = typeof o == "object" && o !== null ? o : {}, { access: u, refresh: l } = s;
3648
+ if (typeof u != "string" || typeof l != "string")
3649
+ throw new Error(
3650
+ `Karni auth: unexpected response from POST ${i} — expected { access, refresh } (JWT mode) or { requires_2fa, ephemeral_token }, got ${dt(o)}. Check the backend's KARNI_AUTH_MODE and the AuthProvider "mode" prop.`
3651
+ );
3652
+ this.tokenStorage.set(l), this.accessToken = u;
3653
+ const c = Ye(s.user) ?? await this.fetchMe(i);
3654
+ return this.setState("authenticated", c), { ok: !0, user: c };
3655
+ }
3656
+ async fetchMe(t) {
3657
+ const n = await this.client.request(`${this.authBasePath}/me/`, {
3658
+ skipAuthRefresh: !0
3659
+ }), i = Ye(n);
3660
+ if (i === null)
3661
+ throw new Error(
3662
+ `Karni auth: POST ${t} succeeded but ${this.authBasePath}/me/ returned ${dt(n)} instead of a user object with id and email.`
3663
+ );
3664
+ return i;
3665
+ }
3666
+ /** Best-effort server logout, then always clears local state (anonymous). */
3667
+ async logout() {
3668
+ await this.ensureInitialized();
3669
+ try {
3670
+ if (this.mode === "session")
3671
+ await this.ensureCsrfToken(), await this.client.request(`${this.authBasePath}/logout/`, {
3672
+ method: "POST",
3673
+ skipAuthRefresh: !0
3674
+ });
3675
+ else {
3676
+ const t = this.tokenStorage.get();
3677
+ t !== null && await this.client.request(`${this.authBasePath}/logout/`, {
3678
+ method: "POST",
3679
+ body: { refresh: t },
3680
+ skipAuthRefresh: !0
3681
+ });
3682
+ }
3683
+ } catch {
3684
+ }
3685
+ this.accessToken = null, this.tokenStorage.clear(), this.setState("anonymous", null);
3686
+ }
3687
+ /**
3688
+ * Adopts tokens issued out of band — what `@karni/impersonation-ui` does
3689
+ * when a support user starts or stops impersonating (the backend answers
3690
+ * with tokens for the other identity). JWT mode only; in session mode the
3691
+ * server-side session already changed, so this just re-syncs `/me/`.
3692
+ */
3693
+ async adoptTokens(t, n) {
3694
+ await this.ensureInitialized(), this.mode === "jwt" && (typeof n == "string" && n !== "" && this.tokenStorage.set(n), typeof t == "string" && t !== "" && (this.accessToken = t)), await this.syncUser();
3695
+ }
3696
+ /**
3697
+ * Re-syncs the session: rotates the tokens in JWT mode (A3: /refresh/ is
3698
+ * 405 in session mode, so session mode only re-fetches /me/).
3699
+ */
3700
+ async refresh() {
3701
+ await this.ensureInitialized(), !(this.mode === "jwt" && !await this.ensureRefresh()) && await this.syncUser();
3702
+ }
3703
+ }
3704
+ function Ro(e = "karni.refreshToken") {
3705
+ return {
3706
+ get() {
3707
+ try {
3708
+ return globalThis.localStorage.getItem(e);
3709
+ } catch {
3710
+ return null;
3711
+ }
3712
+ },
3713
+ set(t) {
3714
+ try {
3715
+ globalThis.localStorage.setItem(e, t);
3716
+ } catch {
3717
+ }
3718
+ },
3719
+ clear() {
3720
+ try {
3721
+ globalThis.localStorage.removeItem(e);
3722
+ } catch {
3723
+ }
3724
+ }
3725
+ };
3726
+ }
3727
+ function wa() {
3728
+ let e = null;
3729
+ return {
3730
+ get: () => e,
3731
+ set: (t) => {
3732
+ e = t;
3733
+ },
3734
+ clear: () => {
3735
+ e = null;
3736
+ }
3737
+ };
3738
+ }
3739
+ const _n = mn(null);
3740
+ function Na({
3741
+ mode: e,
3742
+ tokenStorage: t,
3743
+ csrfCookieName: n,
3744
+ csrfHeaderName: i,
3745
+ authBasePath: o,
3746
+ children: a
3747
+ }) {
3748
+ var T;
3749
+ const s = ge(), u = tt(), l = Xe(() => t ?? Ro(), [t]), c = Xe(
3750
+ () => new Ao({
3751
+ client: s,
3752
+ tokenStorage: l,
3753
+ ...e !== void 0 ? { modeOverride: e } : {},
3754
+ ...n !== void 0 ? { csrfCookieName: n } : {},
3755
+ ...i !== void 0 ? { csrfHeaderName: i } : {},
3756
+ ...o !== void 0 ? { authBasePath: o } : {},
3757
+ readCachedSchema: () => u.getQueryData(he.schema())
3758
+ }),
3759
+ [s, u, l, e, n, i, o]
3760
+ );
3761
+ Ft(() => (c.attach(), c.ensureInitialized(), () => {
3762
+ c.detach();
3763
+ }), [c]);
3764
+ const f = Yn(c.subscribe, c.getSnapshot, c.getSnapshot), g = ((T = f.user) == null ? void 0 : T.id) ?? null, x = Xn(g);
3765
+ Ft(() => {
3766
+ x.current !== g && (x.current = g, u.invalidateQueries({ queryKey: he.schema() }));
3767
+ }, [g, u]);
3768
+ const L = Xe(
3769
+ () => {
3770
+ var v;
3771
+ return {
3772
+ user: f.user,
3773
+ roles: ((v = f.user) == null ? void 0 : v.roles) ?? [],
3774
+ status: f.status,
3775
+ login: (k, h) => c.login(k, h),
3776
+ logout: () => c.logout(),
3777
+ refresh: () => c.refresh(),
3778
+ adoptTokens: (k, h) => c.adoptTokens(k, h)
3779
+ };
3780
+ },
3781
+ [c, f]
3782
+ );
3783
+ return /* @__PURE__ */ r(_n.Provider, { value: L, children: a });
3784
+ }
3785
+ function Tt() {
3786
+ const e = dn(_n);
3787
+ if (e === null)
3788
+ throw new Error(
3789
+ "useAuth must be used within an <AuthProvider> (itself inside <KarniProvider>). Wrap your tree: <KarniProvider client={...}><AuthProvider>...</AuthProvider></KarniProvider>."
3790
+ );
3791
+ return e;
3792
+ }
3793
+ ee("auth-guard", "AuthGuard");
3794
+ function Sa({
3795
+ roles: e,
3796
+ fallback: t = null,
3797
+ loading: n = null,
3798
+ children: i
3799
+ }) {
3800
+ const { status: o, user: a } = Tt();
3801
+ return o === "loading" ? /* @__PURE__ */ r(Q, { children: n }) : o !== "authenticated" || a === null ? /* @__PURE__ */ r(Q, { children: t }) : e !== void 0 && e.length > 0 && !e.some((s) => a.roles.includes(s)) ? /* @__PURE__ */ r(Q, { children: t }) : /* @__PURE__ */ r(Q, { children: i });
3802
+ }
3803
+ ee("login-form", "LoginForm");
3804
+ function ka({
3805
+ onSuccess: e,
3806
+ on2FA: t,
3807
+ title: n = "Sign in",
3808
+ description: i,
3809
+ submitLabel: o = "Sign in",
3810
+ disabled: a = !1,
3811
+ className: s
3812
+ }) {
3813
+ const { login: u } = Tt(), l = m.useId(), [c, f] = m.useState(!1), [g, x] = m.useState(null);
3814
+ async function L(T) {
3815
+ T.preventDefault();
3816
+ const v = new FormData(T.currentTarget);
3817
+ f(!0), x(null);
3818
+ try {
3819
+ const k = await u(
3820
+ String(v.get("email") ?? ""),
3821
+ String(v.get("password") ?? "")
3822
+ );
3823
+ "ok" in k ? e == null || e(k.user) : t !== void 0 ? t(k.ephemeralToken) : x("This account needs a two-factor code; the app has not enabled that step.");
3824
+ } catch {
3825
+ x("That email and password do not match.");
3826
+ } finally {
3827
+ f(!1);
3828
+ }
3829
+ }
3830
+ return /* @__PURE__ */ d(
3831
+ "form",
3832
+ {
3833
+ className: b("space-y-4", s),
3834
+ onSubmit: (T) => void L(T),
3835
+ "aria-busy": c,
3836
+ noValidate: !1,
3837
+ children: [
3838
+ n !== null ? /* @__PURE__ */ r("h2", { className: "text-lg font-semibold", children: n }) : null,
3839
+ i !== void 0 ? /* @__PURE__ */ r("p", { className: "text-sm text-muted-foreground", children: i }) : null,
3840
+ /* @__PURE__ */ d("div", { className: "space-y-1", children: [
3841
+ /* @__PURE__ */ r(qe, { htmlFor: `${l}-email`, children: "Email" }),
3842
+ /* @__PURE__ */ r(
3843
+ we,
3844
+ {
3845
+ id: `${l}-email`,
3846
+ name: "email",
3847
+ type: "email",
3848
+ autoComplete: "email",
3849
+ required: !0,
3850
+ disabled: a || c
3851
+ }
3852
+ )
3853
+ ] }),
3854
+ /* @__PURE__ */ d("div", { className: "space-y-1", children: [
3855
+ /* @__PURE__ */ r(qe, { htmlFor: `${l}-password`, children: "Password" }),
3856
+ /* @__PURE__ */ r(
3857
+ we,
3858
+ {
3859
+ id: `${l}-password`,
3860
+ name: "password",
3861
+ type: "password",
3862
+ autoComplete: "current-password",
3863
+ required: !0,
3864
+ disabled: a || c
3865
+ }
3866
+ )
3867
+ ] }),
3868
+ g !== null ? /* @__PURE__ */ r("p", { role: "alert", className: "text-sm text-destructive", children: g }) : null,
3869
+ /* @__PURE__ */ r(Y, { type: "submit", disabled: a || c, children: o })
3870
+ ]
3871
+ }
3872
+ );
3873
+ }
3874
+ function Ca() {
3875
+ const { roles: e, status: t } = Tt();
3876
+ return Xe(
3877
+ () => ({
3878
+ isAuthenticated: t === "authenticated",
3879
+ hasRole: (...n) => t === "authenticated" && n.some((i) => e.includes(i))
3880
+ }),
3881
+ [e, t]
3882
+ );
3883
+ }
3884
+ ee("page-shell", "Page");
3885
+ const To = m.forwardRef(
3886
+ ({
3887
+ title: e,
3888
+ description: t,
3889
+ actions: n,
3890
+ header: i,
3891
+ headerClassName: o,
3892
+ contentClassName: a,
3893
+ className: s,
3894
+ children: u,
3895
+ ...l
3896
+ }, c) => /* @__PURE__ */ d("section", { ref: c, className: b("flex w-full flex-col gap-6", s), ...l, children: [
3897
+ i ?? /* @__PURE__ */ d("header", { className: b("flex flex-wrap items-start justify-between gap-4", o), children: [
3898
+ /* @__PURE__ */ d("div", { className: "grid gap-1", children: [
3899
+ /* @__PURE__ */ r("h1", { className: "text-2xl font-semibold tracking-tight text-foreground", children: e }),
3900
+ t != null && /* @__PURE__ */ r("p", { className: "text-sm text-muted-foreground", children: t })
3901
+ ] }),
3902
+ n != null && /* @__PURE__ */ r("div", { className: "flex shrink-0 items-center gap-2", children: n })
3903
+ ] }),
3904
+ /* @__PURE__ */ r("div", { className: b("flex flex-col gap-4", a), children: u })
3905
+ ] })
3906
+ );
3907
+ To.displayName = "Page";
3908
+ const Lo = "0 0 1000 1000", Eo = [
3909
+ {
3910
+ fill: "#000000",
3911
+ d: "M495.8 884.4C366.3 877.9 255.3 816.3 182.4 710.5C128.6 632.2 103.2 521.3 115 415.5C128.3 296.3 188.2 205.8 290.9 150.2C389.1 97 470.1 78.3 564.8 87C689.6 98.4 790.1 167.2 844.3 278.1C896.3 384.6 901.7 498.4 860.4 619.6C833.4 698.7 806.7 746.3 766.3 787.1C699.4 854.6 601.9 889.7 495.8 884.4Z"
3912
+ },
3913
+ {
3914
+ fill: "#FB5D08",
3915
+ d: "M355.6 514.1C355.6 509.2 355.7 507.3 355.8 509.8C355.9 512.3 355.9 516.3 355.8 518.7C355.7 521 355.6 519 355.6 514.1ZM677.1 423C637.3 415.7 624.1 366.4 654.9 340.2C672.8 325 696 324.3 713.7 338.5C741 360.3 735.8 403.2 704.1 418.6C696.1 422.4 684.6 424.3 677.1 423ZM330.5 421.6C299.1 415 283.8 379.9 300.6 352.7C317.1 325.8 352.4 320.7 373.7 342.2C398.9 367.6 387.2 410.3 352.3 420.8C347.4 422.3 335.7 422.7 330.5 421.6ZM504.5 399.6C466.4 392.2 453.2 345.4 481.5 318.2C509.6 291.1 556 308.2 560.5 347.3C564.1 377.9 534.5 405.5 504.5 399.6ZM349.4 395.9C367.2 387.1 367.7 363.1 350.2 354.5C329.3 344.3 308.5 369.4 321.8 388.6C327.9 397.5 339.8 400.7 349.4 395.9ZM694 395.9C716 385.1 709 352 684.8 352C665.4 352 654.8 375.3 667.3 390.4C673.5 397.8 685.2 400.2 694 395.9ZM522.4 373.7C534.6 368 539.9 353.6 534.2 341.9C525.3 323.9 501.3 323.8 492.5 341.8C482.8 361.3 503 382.8 522.4 373.7Z"
3916
+ },
3917
+ {
3918
+ fill: "#FFFFFF",
3919
+ d: "M363 677.8C348.7 675.4 341.3 657.2 334.1 606.9C326.6 554.4 325.7 485.2 332.2 459.2C336.3 442.9 349.3 435.9 362.9 442.6C374.7 448.4 394.4 475.1 427.1 529.5C428.9 532.4 430.5 534.9 430.8 534.9C431 534.9 433.5 530.7 436.3 525.6C486 435.8 497.3 419.9 512.2 419.2C523.9 418.6 531.9 426.3 550 455.6C555.3 464.3 582.5 513.2 591.4 530.3C592.7 532.8 594 534.9 594.2 534.9C594.4 534.9 595.9 532.7 597.5 530C621.8 490.2 643.6 458.3 652.7 449.5C668.6 434.2 686.9 437.8 692.6 457.4C703.9 496.4 693.7 637.6 677.5 666.3C673 674.5 663.4 679.5 655.8 677.8C642.6 674.9 633.9 663.4 598.7 602.7C592.7 592.3 593.3 593.1 592.3 594.4C590.8 596.2 572.8 626.4 560.2 648.2C546.9 671 546 672.4 541.7 674.3C531.2 679.1 519.1 669.5 522.1 658.7C523.4 654.4 551 607 571.8 573.6C575 568.5 577.6 564.2 577.6 564C577.6 563.7 560.8 532.5 547.2 507.4C527.8 471.7 514.9 450.1 513.1 450.1C512.4 450.1 510.6 452.9 504.3 463.4C492.7 482.5 447.9 562.5 447.9 564C447.9 564.3 449.8 567.6 452.1 571.4C475.2 609.2 501.1 653.4 502.6 657.5C506.1 667.6 496.6 677.8 485.8 675.3C479.8 673.9 479.1 673.1 468.6 655.1C464.9 648.8 456 633.6 448.7 621.3C441.5 608.9 434.9 597.8 434.2 596.5C432.8 594 431.8 593 431.5 593.9C431.3 594.5 427.1 601.6 414 623.8C386.6 670 377.1 680.1 363 677.8ZM373.8 636.7C376.1 632.9 382.1 622.9 387.1 614.4C408.9 577.2 413.5 569.4 414.6 567.2L415.7 564.9L411.3 557.5C374 495.9 359.9 473.9 357.6 473.9C355.5 473.9 355.1 527.7 357.1 556.7C359.2 587.2 364.9 630.4 368.5 642.5C369 644.1 369.4 643.7 373.8 636.7ZM658.1 639.2C666.8 598 672.3 509 668.1 476.6C667.7 473.1 667.4 473.2 663.8 478C657.6 486.3 651.5 495.7 631.2 529C626.9 536.1 622.1 543.9 620.5 546.5C618.9 549.1 615.7 554.3 613.4 558.1L609.1 565L610.6 567.5C611.4 568.9 616.6 577.6 622.1 586.9C627.5 596.2 634.1 607.5 636.7 611.9C649.4 633.6 655.7 643.4 656.8 643.4C657 643.4 657.6 641.5 658.1 639.2Z"
3920
+ }
3921
+ ], Mo = `<path fill="#000000" d="M495.8 884.4C291.9 874.2 135.4 724 114.7 518.5C97.9 351.3 160.2 221 290.9 150.2C372.3 106.1 439.7 86.4 513.6 85.2C686 82.3 812.9 171.5 867 333.5C903.9 444 890.2 573.8 828.6 698.6C766.8 823.4 644.3 891.8 495.8 884.4Z"/>
3922
+ <circle cx="340" cy="300" r="44" fill="#FB5D08"/>
3923
+ <circle cx="500" cy="276" r="44" fill="#FB5D08"/>
3924
+ <circle cx="660" cy="300" r="44" fill="#FB5D08"/>
3925
+ <path fill="none" stroke="#FFFFFF" stroke-width="58" stroke-linecap="round" stroke-linejoin="round"
3926
+ d="M318 420v280l182-250 182 250V420M500 450 410 700M500 450l90 250"/>`, Vn = m.forwardRef(
3927
+ ({ size: e = 28, variant: t = "auto", title: n = "Karni", className: i, ...o }, a) => {
3928
+ const s = t === "simple" || t === "auto" && e <= 32, u = n !== "";
3929
+ return /* @__PURE__ */ r(
3930
+ "svg",
3931
+ {
3932
+ ref: a,
3933
+ viewBox: Lo,
3934
+ width: e,
3935
+ height: e,
3936
+ role: u ? "img" : void 0,
3937
+ "aria-hidden": u ? void 0 : !0,
3938
+ "aria-label": u ? n : void 0,
3939
+ className: b("shrink-0", i),
3940
+ ...o,
3941
+ ...s ? { dangerouslySetInnerHTML: { __html: Mo } } : {},
3942
+ children: s ? null : Eo.map((l) => /* @__PURE__ */ r("path", { fill: l.fill, d: l.d }, l.fill + l.d.length))
3943
+ }
3944
+ );
3945
+ }
3946
+ );
3947
+ Vn.displayName = "KarniMark";
3948
+ ee("layout-shell", "Layout");
3949
+ function jo(e) {
3950
+ return /* @__PURE__ */ d(
3951
+ "svg",
3952
+ {
3953
+ viewBox: "0 0 24 24",
3954
+ fill: "none",
3955
+ stroke: "currentColor",
3956
+ strokeWidth: 2,
3957
+ strokeLinecap: "round",
3958
+ strokeLinejoin: "round",
3959
+ "aria-hidden": "true",
3960
+ focusable: !1,
3961
+ ...e,
3962
+ children: [
3963
+ /* @__PURE__ */ r("line", { x1: "4", y1: "6", x2: "20", y2: "6" }),
3964
+ /* @__PURE__ */ r("line", { x1: "4", y1: "12", x2: "20", y2: "12" }),
3965
+ /* @__PURE__ */ r("line", { x1: "4", y1: "18", x2: "20", y2: "18" })
3966
+ ]
3967
+ }
3968
+ );
3969
+ }
3970
+ function Do(e) {
3971
+ return /* @__PURE__ */ d(
3972
+ "svg",
3973
+ {
3974
+ viewBox: "0 0 24 24",
3975
+ fill: "none",
3976
+ stroke: "currentColor",
3977
+ strokeWidth: 2,
3978
+ strokeLinecap: "round",
3979
+ strokeLinejoin: "round",
3980
+ "aria-hidden": "true",
3981
+ focusable: !1,
3982
+ ...e,
3983
+ children: [
3984
+ /* @__PURE__ */ r("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
3985
+ /* @__PURE__ */ r("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
3986
+ ]
3987
+ }
3988
+ );
3989
+ }
3990
+ const $o = "flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground [&_svg]:h-4 [&_svg]:w-4", Oo = "bg-accent text-accent-foreground", on = "karni-layout-sidebar", Fo = m.forwardRef(
3991
+ ({
3992
+ navItems: e = [],
3993
+ renderNavItem: t,
3994
+ sidebar: n,
3995
+ sidebarHeader: i = /* @__PURE__ */ r(Vn, { className: "mx-3" }),
3996
+ sidebarFooter: o,
3997
+ header: a,
3998
+ navLabel: s = "Main",
3999
+ sidebarClassName: u,
4000
+ headerClassName: l,
4001
+ contentClassName: c,
4002
+ className: f,
4003
+ children: g,
4004
+ ...x
4005
+ }, L) => {
4006
+ const [T, v] = m.useState(!1), k = m.useCallback(() => {
4007
+ v(!1);
4008
+ }, []);
4009
+ m.useEffect(() => {
4010
+ if (!T)
4011
+ return;
4012
+ const S = (j) => {
4013
+ j.key === "Escape" && v(!1);
4014
+ };
4015
+ return document.addEventListener("keydown", S), () => {
4016
+ document.removeEventListener("keydown", S);
4017
+ };
4018
+ }, [T]);
4019
+ const h = n ?? /* @__PURE__ */ r("nav", { "aria-label": s, className: "grid gap-1", children: e.map((S) => {
4020
+ const j = b(
4021
+ $o,
4022
+ S.active === !0 && Oo
4023
+ ), B = /* @__PURE__ */ d(
4024
+ "a",
4025
+ {
4026
+ href: S.href,
4027
+ "aria-current": S.active === !0 ? "page" : void 0,
4028
+ className: j,
4029
+ onClick: k,
4030
+ children: [
4031
+ S.icon != null && /* @__PURE__ */ r("span", { "aria-hidden": "true", children: S.icon }),
4032
+ S.label
4033
+ ]
4034
+ }
4035
+ );
4036
+ return /* @__PURE__ */ r(m.Fragment, { children: t ? t(S, { defaultNode: B, defaultClassName: j }) : B }, S.key ?? S.href);
4037
+ }) }), w = /* @__PURE__ */ d(Q, { children: [
4038
+ i != null && /* @__PURE__ */ r("div", { className: "mb-4", children: i }),
4039
+ /* @__PURE__ */ r("div", { className: "flex-1 overflow-y-auto", children: h }),
4040
+ o != null && /* @__PURE__ */ r("div", { className: "mt-4", children: o })
4041
+ ] });
4042
+ return /* @__PURE__ */ d(
4043
+ "div",
4044
+ {
4045
+ ref: L,
4046
+ className: b("flex min-h-screen w-full bg-background text-foreground", f),
4047
+ ...x,
4048
+ children: [
4049
+ /* @__PURE__ */ r(
4050
+ "aside",
4051
+ {
4052
+ className: b(
4053
+ "hidden w-64 shrink-0 flex-col border-r border-border bg-card p-4 md:flex",
4054
+ u
4055
+ ),
4056
+ children: w
4057
+ }
4058
+ ),
4059
+ T && /* @__PURE__ */ d("div", { className: "fixed inset-0 z-40 md:hidden", children: [
4060
+ /* @__PURE__ */ r(
4061
+ "div",
4062
+ {
4063
+ "data-testid": "karni-layout-backdrop",
4064
+ "aria-hidden": "true",
4065
+ className: "absolute inset-0 bg-foreground/40",
4066
+ onClick: k
4067
+ }
4068
+ ),
4069
+ /* @__PURE__ */ d(
4070
+ "aside",
4071
+ {
4072
+ id: on,
4073
+ className: b(
4074
+ "absolute inset-y-0 left-0 flex w-64 flex-col border-r border-border bg-card p-4 shadow-lg",
4075
+ u
4076
+ ),
4077
+ children: [
4078
+ /* @__PURE__ */ r("div", { className: "mb-2 flex justify-end", children: /* @__PURE__ */ d(
4079
+ "button",
4080
+ {
4081
+ type: "button",
4082
+ onClick: k,
4083
+ className: "inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
4084
+ children: [
4085
+ /* @__PURE__ */ r(Do, { className: "h-4 w-4" }),
4086
+ /* @__PURE__ */ r("span", { className: "sr-only", children: "Close navigation" })
4087
+ ]
4088
+ }
4089
+ ) }),
4090
+ w
4091
+ ]
4092
+ }
4093
+ )
4094
+ ] }),
4095
+ /* @__PURE__ */ d("div", { className: "flex min-w-0 flex-1 flex-col", children: [
4096
+ /* @__PURE__ */ d(
4097
+ "header",
4098
+ {
4099
+ className: b(
4100
+ "flex h-14 shrink-0 items-center gap-3 border-b border-border px-4",
4101
+ l
4102
+ ),
4103
+ children: [
4104
+ /* @__PURE__ */ d(
4105
+ "button",
4106
+ {
4107
+ type: "button",
4108
+ "aria-expanded": T,
4109
+ "aria-controls": on,
4110
+ onClick: () => {
4111
+ v((S) => !S);
4112
+ },
4113
+ className: "inline-flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring md:hidden",
4114
+ children: [
4115
+ /* @__PURE__ */ r(jo, { className: "h-5 w-5" }),
4116
+ /* @__PURE__ */ r("span", { className: "sr-only", children: "Open navigation" })
4117
+ ]
4118
+ }
4119
+ ),
4120
+ a != null && /* @__PURE__ */ r("div", { className: "flex min-w-0 flex-1 items-center gap-3", children: a })
4121
+ ]
4122
+ }
4123
+ ),
4124
+ /* @__PURE__ */ r("main", { className: b("flex-1 p-6", c), children: g })
4125
+ ] })
4126
+ ]
4127
+ }
4128
+ );
4129
+ }
4130
+ );
4131
+ Fo.displayName = "Layout";
4132
+ ee("modal", "Modal");
4133
+ function Po(e) {
4134
+ return /* @__PURE__ */ d(
4135
+ "svg",
4136
+ {
4137
+ viewBox: "0 0 24 24",
4138
+ fill: "none",
4139
+ stroke: "currentColor",
4140
+ strokeWidth: 2,
4141
+ strokeLinecap: "round",
4142
+ strokeLinejoin: "round",
4143
+ "aria-hidden": "true",
4144
+ focusable: !1,
4145
+ ...e,
4146
+ children: [
4147
+ /* @__PURE__ */ r("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
4148
+ /* @__PURE__ */ r("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
4149
+ ]
4150
+ }
4151
+ );
4152
+ }
4153
+ const Aa = ve.Close;
4154
+ function Ra({
4155
+ title: e,
4156
+ description: t,
4157
+ children: n,
4158
+ footer: i,
4159
+ trigger: o,
4160
+ open: a,
4161
+ defaultOpen: s,
4162
+ onOpenChange: u,
4163
+ hideCloseButton: l = !1,
4164
+ className: c,
4165
+ contentProps: f
4166
+ }) {
4167
+ const g = t == null && (f == null ? void 0 : f["aria-describedby"]) === void 0 ? { "aria-describedby": void 0 } : {};
4168
+ return /* @__PURE__ */ d(ve.Root, { open: a, defaultOpen: s, onOpenChange: u, children: [
4169
+ o != null && /* @__PURE__ */ r(ve.Trigger, { asChild: !0, children: o }),
4170
+ /* @__PURE__ */ d(ve.Portal, { children: [
4171
+ /* @__PURE__ */ r(ve.Overlay, { className: "fixed inset-0 z-50 bg-foreground/40" }),
4172
+ /* @__PURE__ */ d(
4173
+ ve.Content,
4174
+ {
4175
+ ...f,
4176
+ ...g,
4177
+ className: b(
4178
+ "fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border border-border bg-background p-6 text-foreground shadow-lg",
4179
+ c
4180
+ ),
4181
+ children: [
4182
+ /* @__PURE__ */ d("div", { className: "grid gap-1.5", children: [
4183
+ /* @__PURE__ */ r(ve.Title, { className: "text-lg font-semibold leading-none tracking-tight", children: e }),
4184
+ t != null && /* @__PURE__ */ r(ve.Description, { className: "text-sm text-muted-foreground", children: t })
4185
+ ] }),
4186
+ n,
4187
+ i != null && /* @__PURE__ */ r("div", { className: "flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", children: i }),
4188
+ !l && /* @__PURE__ */ d(ve.Close, { className: "absolute right-4 top-4 rounded-sm text-muted-foreground opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none", children: [
4189
+ /* @__PURE__ */ r(Po, { className: "h-4 w-4" }),
4190
+ /* @__PURE__ */ r("span", { className: "sr-only", children: "Close" })
4191
+ ] })
4192
+ ]
4193
+ }
4194
+ )
4195
+ ] })
4196
+ ] });
4197
+ }
4198
+ let Pe = [];
4199
+ const wt = /* @__PURE__ */ new Set();
4200
+ let an = 0;
4201
+ function zn() {
4202
+ for (const e of wt)
4203
+ e();
4204
+ }
4205
+ function Bo(e) {
4206
+ return wt.add(e), () => {
4207
+ wt.delete(e);
4208
+ };
4209
+ }
4210
+ function sn() {
4211
+ return Pe;
4212
+ }
4213
+ function Lt(e) {
4214
+ const t = e === void 0 ? [] : Pe.filter((n) => n.id !== e);
4215
+ t.length !== Pe.length && (Pe = t, zn());
4216
+ }
4217
+ function Un(e) {
4218
+ an += 1;
4219
+ const t = e.id ?? `karni-toast-${String(an)}`, n = {
4220
+ ...e,
4221
+ id: t,
4222
+ variant: e.variant ?? "default"
4223
+ };
4224
+ return Pe = [...Pe.filter((i) => i.id !== t), n].slice(-5), zn(), {
4225
+ id: t,
4226
+ dismiss: () => {
4227
+ Lt(t);
4228
+ }
4229
+ };
4230
+ }
4231
+ function mt(e) {
4232
+ return (t, n) => Un({ ...n, title: t, variant: e });
4233
+ }
4234
+ const _o = {
4235
+ toast: Un,
4236
+ success: mt("success"),
4237
+ error: mt("error"),
4238
+ info: mt("info"),
4239
+ dismiss: Lt
4240
+ };
4241
+ function Vo() {
4242
+ const e = m.useSyncExternalStore(Bo, sn, sn);
4243
+ return m.useMemo(() => ({ toasts: e, ..._o }), [e]);
4244
+ }
4245
+ ee("toast", "Toaster");
4246
+ function zo(e) {
4247
+ return /* @__PURE__ */ d(
4248
+ "svg",
4249
+ {
4250
+ viewBox: "0 0 24 24",
4251
+ fill: "none",
4252
+ stroke: "currentColor",
4253
+ strokeWidth: 2,
4254
+ strokeLinecap: "round",
4255
+ strokeLinejoin: "round",
4256
+ "aria-hidden": "true",
4257
+ focusable: !1,
4258
+ ...e,
4259
+ children: [
4260
+ /* @__PURE__ */ r("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
4261
+ /* @__PURE__ */ r("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
4262
+ ]
4263
+ }
4264
+ );
4265
+ }
4266
+ const Uo = fn({
4267
+ base: "pointer-events-auto relative flex w-full items-start gap-3 overflow-hidden rounded-md border p-4 pr-8 shadow-lg",
4268
+ variants: {
4269
+ variant: {
4270
+ default: "border-border bg-background text-foreground",
4271
+ success: "border-primary bg-background text-foreground",
4272
+ error: "border-destructive bg-destructive text-destructive-foreground",
4273
+ info: "border-border bg-muted text-foreground"
4274
+ }
4275
+ },
4276
+ defaultVariants: {
4277
+ variant: "default"
4278
+ }
4279
+ });
4280
+ function Ta({
4281
+ duration: e = 5e3,
4282
+ swipeDirection: t = "right",
4283
+ label: n = "Notification",
4284
+ viewportClassName: i,
4285
+ toastClassName: o
4286
+ }) {
4287
+ const { toasts: a } = Vo();
4288
+ return /* @__PURE__ */ d(je.Provider, { duration: e, swipeDirection: t, label: n, children: [
4289
+ a.map((s) => /* @__PURE__ */ d(
4290
+ je.Root,
4291
+ {
4292
+ duration: s.duration,
4293
+ "data-variant": s.variant,
4294
+ onOpenChange: (u) => {
4295
+ u || Lt(s.id);
4296
+ },
4297
+ className: Uo({ variant: s.variant, className: o }),
4298
+ children: [
4299
+ /* @__PURE__ */ d("div", { className: "grid flex-1 gap-1", children: [
4300
+ s.title != null && /* @__PURE__ */ r(je.Title, { className: "text-sm font-semibold", children: s.title }),
4301
+ s.description != null && /* @__PURE__ */ r(je.Description, { className: "text-sm opacity-90", children: s.description })
4302
+ ] }),
4303
+ s.action != null && /* @__PURE__ */ r("div", { className: "flex shrink-0 items-center", children: s.action }),
4304
+ /* @__PURE__ */ r(
4305
+ je.Close,
4306
+ {
4307
+ "aria-label": "Dismiss",
4308
+ className: "absolute right-2 top-2 rounded-md p-1 opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
4309
+ children: /* @__PURE__ */ r(zo, { className: "h-4 w-4" })
4310
+ }
4311
+ )
4312
+ ]
4313
+ },
4314
+ s.id
4315
+ )),
4316
+ /* @__PURE__ */ r(
4317
+ je.Viewport,
4318
+ {
4319
+ className: b(
4320
+ "fixed bottom-0 right-0 z-[100] flex w-full max-w-sm flex-col gap-2 p-4 outline-none",
4321
+ i
4322
+ )
4323
+ }
4324
+ )
4325
+ ] });
4326
+ }
4327
+ ee("stat", "Stat");
4328
+ function Ko(e) {
4329
+ return /* @__PURE__ */ d(
4330
+ "svg",
4331
+ {
4332
+ viewBox: "0 0 24 24",
4333
+ fill: "none",
4334
+ stroke: "currentColor",
4335
+ strokeWidth: 2,
4336
+ strokeLinecap: "round",
4337
+ strokeLinejoin: "round",
4338
+ "aria-hidden": "true",
4339
+ focusable: !1,
4340
+ ...e,
4341
+ children: [
4342
+ /* @__PURE__ */ r("line", { x1: "12", y1: "19", x2: "12", y2: "5" }),
4343
+ /* @__PURE__ */ r("polyline", { points: "5 12 12 5 19 12" })
4344
+ ]
4345
+ }
4346
+ );
4347
+ }
4348
+ function Ho(e) {
4349
+ return /* @__PURE__ */ d(
4350
+ "svg",
4351
+ {
4352
+ viewBox: "0 0 24 24",
4353
+ fill: "none",
4354
+ stroke: "currentColor",
4355
+ strokeWidth: 2,
4356
+ strokeLinecap: "round",
4357
+ strokeLinejoin: "round",
4358
+ "aria-hidden": "true",
4359
+ focusable: !1,
4360
+ ...e,
4361
+ children: [
4362
+ /* @__PURE__ */ r("line", { x1: "12", y1: "5", x2: "12", y2: "19" }),
4363
+ /* @__PURE__ */ r("polyline", { points: "19 12 12 19 5 12" })
4364
+ ]
4365
+ }
4366
+ );
4367
+ }
4368
+ function Wo(e) {
4369
+ const t = Math.abs(e).toLocaleString();
4370
+ return e >= 0 ? `+${t}` : `-${t}`;
4371
+ }
4372
+ const Qo = m.forwardRef(
4373
+ ({ label: e, value: t, delta: n, formatDelta: i = Wo, icon: o, className: a, ...s }, u) => {
4374
+ let l = null;
4375
+ if (typeof n == "number" && Number.isFinite(n)) {
4376
+ const c = n < 0;
4377
+ l = /* @__PURE__ */ d(
4378
+ "p",
4379
+ {
4380
+ className: b(
4381
+ "flex items-center gap-1 text-sm font-medium",
4382
+ c ? "text-destructive" : "text-muted-foreground"
4383
+ ),
4384
+ children: [
4385
+ c ? /* @__PURE__ */ r(Ho, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ r(Ko, { className: "h-3.5 w-3.5" }),
4386
+ /* @__PURE__ */ d("span", { className: "sr-only", children: [
4387
+ c ? "Decreased by" : "Increased by",
4388
+ " "
4389
+ ] }),
4390
+ i(n)
4391
+ ]
4392
+ }
4393
+ );
4394
+ } else n != null && (l = /* @__PURE__ */ r("div", { className: "text-sm text-muted-foreground", children: n }));
4395
+ return /* @__PURE__ */ d(
4396
+ "div",
4397
+ {
4398
+ ref: u,
4399
+ className: b(
4400
+ "flex flex-col gap-1 rounded-lg border border-border bg-card p-4 text-card-foreground",
4401
+ a
4402
+ ),
4403
+ ...s,
4404
+ children: [
4405
+ /* @__PURE__ */ d("div", { className: "flex items-start justify-between gap-2", children: [
4406
+ /* @__PURE__ */ r("p", { className: "text-sm font-medium text-muted-foreground", children: e }),
4407
+ o != null && /* @__PURE__ */ r("span", { "aria-hidden": "true", className: "text-muted-foreground [&>svg]:h-4 [&>svg]:w-4", children: o })
4408
+ ] }),
4409
+ /* @__PURE__ */ r("p", { className: "text-2xl font-semibold tracking-tight", children: t }),
4410
+ l
4411
+ ]
4412
+ }
4413
+ );
4414
+ }
4415
+ );
4416
+ Qo.displayName = "Stat";
4417
+ ee("chart", "DataChart");
4418
+ const Jo = [
4419
+ "stroke-chart-1",
4420
+ "stroke-chart-2",
4421
+ "stroke-chart-3",
4422
+ "stroke-chart-4",
4423
+ "stroke-chart-5"
4424
+ ], ln = [
4425
+ "fill-chart-1",
4426
+ "fill-chart-2",
4427
+ "fill-chart-3",
4428
+ "fill-chart-4",
4429
+ "fill-chart-5"
4430
+ ], cn = [
4431
+ "bg-chart-1",
4432
+ "bg-chart-2",
4433
+ "bg-chart-3",
4434
+ "bg-chart-4",
4435
+ "bg-chart-5"
4436
+ ];
4437
+ function Ke(e, t) {
4438
+ return e[t % e.length] ?? e[0] ?? "";
4439
+ }
4440
+ const ae = { top: 8, right: 12, bottom: 28, left: 48 };
4441
+ function un(e, t) {
4442
+ const n = Math.floor(Math.log10(e)), i = e / 10 ** n;
4443
+ let o;
4444
+ return t ? o = i < 1.5 ? 1 : i < 3 ? 2 : i < 7 ? 5 : 10 : o = i <= 1 ? 1 : i <= 2 ? 2 : i <= 5 ? 5 : 10, o * 10 ** n;
4445
+ }
4446
+ function Zo(e, t, n) {
4447
+ const i = t > e ? t - e : 1, o = un(un(i, !1) / Math.max(1, n), !0), a = Math.floor(e / o) * o, s = Math.ceil(t / o) * o, u = [];
4448
+ for (let l = a; l <= s + o / 2; l += o)
4449
+ u.push(Number(l.toFixed(10)));
4450
+ return u;
4451
+ }
4452
+ function Go(e, t) {
4453
+ const n = t ?? (e !== void 0 ? [{ name: "Value", data: e }] : []), i = [], o = /* @__PURE__ */ new Set();
4454
+ for (const s of n)
4455
+ for (const u of s.data)
4456
+ o.has(u.label) || (o.add(u.label), i.push(u.label));
4457
+ const a = n.map((s) => {
4458
+ const u = /* @__PURE__ */ new Map();
4459
+ for (const l of s.data)
4460
+ Number.isFinite(l.value) && u.set(l.label, l.value);
4461
+ return i.map((l) => u.get(l) ?? null);
4462
+ });
4463
+ return { categories: i, seriesNames: n.map((s) => s.name), matrix: a };
4464
+ }
4465
+ function Yo(e) {
4466
+ return e.toLocaleString();
4467
+ }
4468
+ function La({
4469
+ kind: e,
4470
+ data: t,
4471
+ series: n,
4472
+ title: i,
4473
+ description: o,
4474
+ valueFormatter: a = Yo,
4475
+ xTickFormatter: s,
4476
+ renderTooltip: u,
4477
+ width: l = 640,
4478
+ height: c = 240,
4479
+ yTickCount: f = 4,
4480
+ showLegend: g,
4481
+ showTooltip: x = !0,
4482
+ categoryHeader: L = "Label",
4483
+ emptyLabel: T = "No data",
4484
+ className: v
4485
+ }) {
4486
+ const k = m.useId(), h = m.useId(), [w, S] = m.useState(null), { categories: j, seriesNames: B, matrix: y } = m.useMemo(
4487
+ () => Go(t, n),
4488
+ [t, n]
4489
+ ), C = y.flat().filter((A) => A !== null);
4490
+ if (j.length === 0 || C.length === 0)
4491
+ return /* @__PURE__ */ r(
4492
+ "div",
4493
+ {
4494
+ className: b(
4495
+ "flex w-full items-center justify-center rounded-lg border border-dashed border-border px-6 py-10 text-sm text-muted-foreground",
4496
+ v
4497
+ ),
4498
+ children: T
4499
+ }
4500
+ );
4501
+ const O = Math.min(0, ...C), V = Math.max(0, ...C), K = Zo(O, V, f), $ = K[0] ?? O, E = K[K.length - 1] ?? V, N = E - $ || 1, F = l - ae.left - ae.right, _ = c - ae.top - ae.bottom, P = (A) => ae.top + (E - A) / N * _, J = F / j.length, oe = (A) => ae.left + (A + 0.5) * J, se = P(Math.max($, Math.min(E, 0))), Ce = Math.max(1, y.length), Me = J * 0.7, Ae = Me / Ce, pe = y.map((A, D) => {
4502
+ if (e === "bar")
4503
+ return /* @__PURE__ */ r("g", { className: Ke(ln, D), children: A.map((W, I) => {
4504
+ if (W === null)
4505
+ return null;
4506
+ const Re = oe(I) - Me / 2 + D * Ae, Te = Math.min(P(W), se), p = Math.abs(P(W) - se);
4507
+ return /* @__PURE__ */ r(
4508
+ "rect",
4509
+ {
4510
+ x: Re,
4511
+ y: Te,
4512
+ width: Math.max(1, Ae - 2),
4513
+ height: p,
4514
+ rx: 2
4515
+ },
4516
+ I
4517
+ );
4518
+ }) }, D);
4519
+ const be = A.map(
4520
+ (W, I) => W === null ? null : [oe(I), P(W)]
4521
+ ).filter((W) => W !== null);
4522
+ return /* @__PURE__ */ d("g", { children: [
4523
+ /* @__PURE__ */ r(
4524
+ "polyline",
4525
+ {
4526
+ className: Ke(Jo, D),
4527
+ fill: "none",
4528
+ strokeWidth: 2,
4529
+ strokeLinecap: "round",
4530
+ strokeLinejoin: "round",
4531
+ points: be.map(([W, I]) => `${String(W)},${String(I)}`).join(" ")
4532
+ }
4533
+ ),
4534
+ be.map(([W, I], Re) => /* @__PURE__ */ r(
4535
+ "circle",
4536
+ {
4537
+ className: Ke(ln, D),
4538
+ cx: W,
4539
+ cy: I,
4540
+ r: 3
4541
+ },
4542
+ Re
4543
+ ))
4544
+ ] }, D);
4545
+ }), q = (A, D) => `${String(A / D * 100)}%`, ye = w === null ? [] : y.map((A, D) => ({
4546
+ seriesName: B[D] ?? "",
4547
+ value: A[w] ?? null,
4548
+ swatchClassName: Ke(cn, D)
4549
+ })).filter(
4550
+ (A) => A.value !== null
4551
+ ), ce = w === null ? void 0 : j[w], Ne = B.length > 1;
4552
+ return /* @__PURE__ */ d("div", { className: b("w-full", v), children: [
4553
+ /* @__PURE__ */ d("div", { className: "relative w-full", children: [
4554
+ /* @__PURE__ */ d(
4555
+ "svg",
4556
+ {
4557
+ role: "img",
4558
+ "aria-label": i,
4559
+ "aria-labelledby": k,
4560
+ "aria-describedby": o !== void 0 ? h : void 0,
4561
+ viewBox: `0 0 ${String(l)} ${String(c)}`,
4562
+ className: "block h-auto w-full text-muted-foreground",
4563
+ children: [
4564
+ /* @__PURE__ */ r("title", { id: k, children: i }),
4565
+ o !== void 0 && /* @__PURE__ */ r("desc", { id: h, children: o }),
4566
+ K.map((A) => /* @__PURE__ */ d("g", { children: [
4567
+ /* @__PURE__ */ r(
4568
+ "line",
4569
+ {
4570
+ x1: ae.left,
4571
+ x2: l - ae.right,
4572
+ y1: P(A),
4573
+ y2: P(A),
4574
+ stroke: "currentColor",
4575
+ strokeOpacity: A === 0 ? 0.6 : 0.2
4576
+ }
4577
+ ),
4578
+ /* @__PURE__ */ r(
4579
+ "text",
4580
+ {
4581
+ x: ae.left - 6,
4582
+ y: P(A),
4583
+ textAnchor: "end",
4584
+ dominantBaseline: "middle",
4585
+ fontSize: 10,
4586
+ fill: "currentColor",
4587
+ children: a(A)
4588
+ }
4589
+ )
4590
+ ] }, A)),
4591
+ j.map((A, D) => /* @__PURE__ */ r(
4592
+ "text",
4593
+ {
4594
+ x: oe(D),
4595
+ y: c - ae.bottom + 14,
4596
+ textAnchor: "middle",
4597
+ fontSize: 10,
4598
+ fill: "currentColor",
4599
+ children: s ? s(A) : A
4600
+ },
4601
+ A
4602
+ )),
4603
+ pe
4604
+ ]
4605
+ }
4606
+ ),
4607
+ x && /* @__PURE__ */ d("div", { "aria-hidden": "true", className: "absolute inset-0", children: [
4608
+ /* @__PURE__ */ r(
4609
+ "div",
4610
+ {
4611
+ className: "absolute flex",
4612
+ style: {
4613
+ left: q(ae.left, l),
4614
+ width: q(F, l),
4615
+ top: q(ae.top, c),
4616
+ height: q(_, c)
4617
+ },
4618
+ onMouseLeave: () => {
4619
+ S(null);
4620
+ },
4621
+ children: j.map((A, D) => /* @__PURE__ */ r(
4622
+ "div",
4623
+ {
4624
+ "data-karni-chart-hit": D,
4625
+ className: "h-full flex-1",
4626
+ onMouseEnter: () => {
4627
+ S(D);
4628
+ }
4629
+ },
4630
+ A
4631
+ ))
4632
+ }
4633
+ ),
4634
+ w !== null && ce !== void 0 && ye.length > 0 && /* @__PURE__ */ r(
4635
+ "div",
4636
+ {
4637
+ "data-karni-chart-tooltip": "",
4638
+ className: "pointer-events-none absolute z-10 min-w-24 -translate-x-1/2 rounded-md border border-border bg-popover px-2.5 py-1.5 text-xs text-popover-foreground shadow-md",
4639
+ style: {
4640
+ left: q(oe(w), l),
4641
+ top: q(ae.top, c)
4642
+ },
4643
+ children: u ? u({ label: ce, points: ye }) : /* @__PURE__ */ d(Q, { children: [
4644
+ /* @__PURE__ */ r("p", { className: "mb-1 font-medium", children: ce }),
4645
+ ye.map((A) => /* @__PURE__ */ d("p", { className: "flex items-center gap-1.5", children: [
4646
+ /* @__PURE__ */ r(
4647
+ "span",
4648
+ {
4649
+ className: b("h-2 w-2 shrink-0 rounded-full", A.swatchClassName)
4650
+ }
4651
+ ),
4652
+ /* @__PURE__ */ r("span", { className: "text-muted-foreground", children: A.seriesName }),
4653
+ /* @__PURE__ */ r("span", { className: "ml-auto font-medium", children: a(A.value) })
4654
+ ] }, A.seriesName))
4655
+ ] })
4656
+ }
4657
+ )
4658
+ ] })
4659
+ ] }),
4660
+ (g ?? Ne) && /* @__PURE__ */ r("div", { "aria-hidden": "true", className: "mt-2 flex flex-wrap items-center gap-x-4 gap-y-1", children: B.map((A, D) => /* @__PURE__ */ d("span", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
4661
+ /* @__PURE__ */ r("span", { className: b("h-2 w-2 rounded-full", Ke(cn, D)) }),
4662
+ A
4663
+ ] }, A)) }),
4664
+ /* @__PURE__ */ r(nr.Root, { asChild: !0, children: /* @__PURE__ */ r("div", { children: /* @__PURE__ */ d("table", { children: [
4665
+ /* @__PURE__ */ r("caption", { children: i }),
4666
+ /* @__PURE__ */ r("thead", { children: /* @__PURE__ */ d("tr", { children: [
4667
+ /* @__PURE__ */ r("th", { scope: "col", children: L }),
4668
+ B.map((A) => /* @__PURE__ */ r("th", { scope: "col", children: A }, A))
4669
+ ] }) }),
4670
+ /* @__PURE__ */ r("tbody", { children: j.map((A, D) => /* @__PURE__ */ d("tr", { children: [
4671
+ /* @__PURE__ */ r("th", { scope: "row", children: A }),
4672
+ y.map((be, W) => {
4673
+ const I = be[D] ?? null;
4674
+ return /* @__PURE__ */ r("td", { children: I === null ? "—" : a(I) }, W);
4675
+ })
4676
+ ] }, A)) })
4677
+ ] }) }) })
4678
+ ] });
4679
+ }
4680
+ export {
4681
+ xt as AUDIT_FIELDS,
4682
+ Sa as AuthGuard,
4683
+ Na as AuthProvider,
4684
+ Y as Button,
4685
+ ya as ChangeHistory,
4686
+ gt as Checkbox,
4687
+ La as DataChart,
4688
+ ua as DropdownMenu,
4689
+ wr as DropdownMenuCheckboxItem,
4690
+ xr as DropdownMenuContent,
4691
+ ma as DropdownMenuGroup,
4692
+ vr as DropdownMenuItem,
4693
+ Nr as DropdownMenuLabel,
4694
+ fa as DropdownMenuPortal,
4695
+ Sr as DropdownMenuSeparator,
4696
+ da as DropdownMenuTrigger,
4697
+ yt as EmptyState,
4698
+ Ui as FileUpload,
4699
+ we as Input,
4700
+ Ue as KARNI_SELECT_EMPTY,
4701
+ tn as KarniApiError,
4702
+ Vn as KarniMark,
4703
+ ha as KarniProvider,
4704
+ qe as Label,
4705
+ Fo as Layout,
4706
+ ka as LoginForm,
4707
+ Ra as Modal,
4708
+ Aa as ModalClose,
4709
+ To as Page,
4710
+ ba as ResourceDetail,
4711
+ pa as ResourceForm,
4712
+ xa as ResourceImport,
4713
+ Dn as ResourceSelect,
4714
+ ga as ResourceTable,
4715
+ Qe as Select,
4716
+ yn as SelectContent,
4717
+ la as SelectGroup,
4718
+ ht as SelectItem,
4719
+ hr as SelectLabel,
4720
+ mr as SelectRoot,
4721
+ gr as SelectSeparator,
4722
+ gn as SelectTrigger,
4723
+ fr as SelectValue,
4724
+ me as Skeleton,
4725
+ Qo as Stat,
4726
+ xn as Switch,
4727
+ ca as Tabs,
4728
+ yr as TabsContent,
4729
+ pr as TabsList,
4730
+ br as TabsTrigger,
4731
+ ft as Textarea,
4732
+ Ta as Toaster,
4733
+ dr as buttonVariants,
4734
+ mo as changeHistoryKey,
4735
+ b as cn,
4736
+ va as createKarniClient,
4737
+ Ro as createLocalStorageTokenStorage,
4738
+ wa as createMemoryTokenStorage,
4739
+ Oe as displayLabel,
4740
+ si as downloadImportTemplate,
4741
+ ai as downloadResourceExport,
4742
+ sa as getRoleRegistry,
4743
+ Tn as importDescribeKey,
4744
+ Ln as importJobKey,
4745
+ En as isImportInFlight,
4746
+ he as karniKeys,
4747
+ ee as registerComponentRole,
4748
+ Uo as toastVariants,
4749
+ Tt as useAuth,
4750
+ fo as useChangeHistory,
4751
+ ui as useImportActions,
4752
+ li as useImportDescribe,
4753
+ ci as useImportJob,
4754
+ ge as useKarniClient,
4755
+ Ca as usePermission,
4756
+ Rt as useResourceItem,
4757
+ Nn as useResourceList,
4758
+ Sn as useResourceMutations,
4759
+ kt as useSchema,
4760
+ Vo as useToast,
4761
+ fn as variants,
4762
+ Fi as zodFor
4763
+ };
4764
+ //# sourceMappingURL=index.js.map