@bebopdev/admin 0.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,1749 @@
1
+ import * as e from "react";
2
+ import { createContext as t, useCallback as n, useEffect as r, useMemo as i, useRef as a, useState as o } from "react";
3
+ import { useAll as s, useDb as c, useOne as l } from "jazz-tools/react";
4
+ import { Controller as u, useForm as d } from "react-hook-form";
5
+ import { ArrowDown as f, ArrowLeft as ee, ArrowUp as p, ArrowUpDown as m, CheckIcon as h, ChevronDown as g, ChevronDownIcon as _, ChevronLeft as te, ChevronRight as v, ChevronUp as y, ChevronUpIcon as b, CircleCheckIcon as x, InfoIcon as S, Loader2Icon as C, LogOut as ne, Menu as w, OctagonXIcon as T, Plus as re, Search as E, Trash2 as D, TriangleAlertIcon as O, XIcon as k } from "lucide-react";
6
+ import { Link as A, NavLink as j, Outlet as M, useLocation as ie, useNavigate as ae, useOutletContext as oe, useParams as se, useRoutes as N, useSearchParams as P } from "react-router-dom";
7
+ import { mergeProps as ce } from "@base-ui/react/merge-props";
8
+ import { useRender as F } from "@base-ui/react/use-render";
9
+ import { cva as I } from "class-variance-authority";
10
+ import { cn as L } from "cn";
11
+ import { Button as R } from "@base-ui/react/button";
12
+ import { Fragment as le, jsx as z, jsxs as B } from "react/jsx-runtime";
13
+ import { Input as ue } from "@base-ui/react/input";
14
+ import { Select as V } from "@base-ui/react/select";
15
+ import { Toast as H } from "@base-ui/react/toast";
16
+ //#region src/components/ui/badge.tsx
17
+ var de = I("group/badge inline-flex w-fit shrink-0 items-center justify-center gap-1.5 overflow-hidden rounded-none border-0 bg-transparent px-0 py-0 text-[0.625rem] font-semibold tracking-widest whitespace-nowrap uppercase transition-colors focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-0 has-data-[icon=inline-start]:pl-0 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!", {
18
+ variants: { variant: {
19
+ default: "text-foreground [a]:hover:text-foreground/70",
20
+ secondary: "text-muted-foreground [a]:hover:text-foreground",
21
+ destructive: "text-destructive focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:text-destructive/70",
22
+ outline: "text-foreground [a]:hover:text-foreground/70",
23
+ ghost: "text-muted-foreground hover:text-foreground",
24
+ link: "text-foreground underline-offset-4 hover:underline"
25
+ } },
26
+ defaultVariants: { variant: "default" }
27
+ });
28
+ function U({ className: e, variant: t = "default", render: n, ...r }) {
29
+ return F({
30
+ defaultTagName: "span",
31
+ props: ce({ className: L(de({ variant: t }), e) }, r),
32
+ render: n,
33
+ state: {
34
+ slot: "badge",
35
+ variant: t
36
+ }
37
+ });
38
+ }
39
+ //#endregion
40
+ //#region src/components/ui/button.tsx
41
+ var W = I("group/button inline-flex shrink-0 items-center justify-center rounded-none border border-transparent bg-clip-padding text-xs font-semibold tracking-widest whitespace-nowrap uppercase transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5", {
42
+ variants: {
43
+ variant: {
44
+ default: "bg-primary text-primary-foreground hover:bg-primary/80",
45
+ outline: "border-border bg-transparent hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-input/30",
46
+ secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
47
+ ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
48
+ destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
49
+ link: "text-primary underline underline-offset-4 hover:underline"
50
+ },
51
+ size: {
52
+ default: "h-10 gap-1.5 px-6 has-data-[icon=inline-end]:pr-4 has-data-[icon=inline-start]:pl-4",
53
+ xs: "h-7 gap-1 px-3 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2 [&_svg:not([class*='size-'])]:size-3",
54
+ sm: "h-9 gap-1 px-4 has-data-[icon=inline-end]:pr-3 has-data-[icon=inline-start]:pl-3",
55
+ lg: "h-11 gap-1.5 px-8 has-data-[icon=inline-end]:pr-5 has-data-[icon=inline-start]:pl-5",
56
+ icon: "size-10",
57
+ "icon-xs": "size-7 [&_svg:not([class*='size-'])]:size-3",
58
+ "icon-sm": "size-9",
59
+ "icon-lg": "size-11"
60
+ }
61
+ },
62
+ defaultVariants: {
63
+ variant: "default",
64
+ size: "default"
65
+ }
66
+ });
67
+ function G({ className: e, variant: t = "default", size: n = "default", ...r }) {
68
+ return /* @__PURE__ */ z(R, {
69
+ "data-slot": "button",
70
+ className: L(W({
71
+ variant: t,
72
+ size: n,
73
+ className: e
74
+ })),
75
+ ...r
76
+ });
77
+ }
78
+ //#endregion
79
+ //#region src/components/ui/input.tsx
80
+ function fe({ className: e, type: t, ...n }) {
81
+ return /* @__PURE__ */ z(ue, {
82
+ type: t,
83
+ "data-slot": "input",
84
+ className: L("h-10 w-full min-w-0 border border-transparent border-b-input bg-transparent px-0 py-1 text-base transition-[color,border-color] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-b-ring disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-b-destructive md:text-sm dark:aria-invalid:border-b-destructive/50", e),
85
+ ...n
86
+ });
87
+ }
88
+ //#endregion
89
+ //#region src/components/ui/label.tsx
90
+ function pe({ className: e, ...t }) {
91
+ return /* @__PURE__ */ z("label", {
92
+ "data-slot": "label",
93
+ className: L("flex items-center gap-2 text-xs font-semibold tracking-wide uppercase select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50 peer-data-[slot=checkbox]:text-sm peer-data-[slot=checkbox]:font-normal peer-data-[slot=checkbox]:tracking-normal peer-data-[slot=checkbox]:normal-case peer-data-[slot=radio-group-item]:text-sm peer-data-[slot=radio-group-item]:font-normal peer-data-[slot=radio-group-item]:tracking-normal peer-data-[slot=radio-group-item]:normal-case peer-data-[slot=switch]:text-sm peer-data-[slot=switch]:font-normal peer-data-[slot=switch]:tracking-normal peer-data-[slot=switch]:normal-case", e),
94
+ ...t
95
+ });
96
+ }
97
+ //#endregion
98
+ //#region src/lib/admin-portal.ts
99
+ var K = t(null), me = V.Root;
100
+ function he({ className: e, ...t }) {
101
+ return /* @__PURE__ */ z(V.Value, {
102
+ "data-slot": "select-value",
103
+ className: L("flex flex-1 text-left", e),
104
+ ...t
105
+ });
106
+ }
107
+ function ge({ className: e, size: t = "default", children: n, ...r }) {
108
+ return /* @__PURE__ */ B(V.Trigger, {
109
+ "data-slot": "select-trigger",
110
+ "data-size": t,
111
+ className: L("flex w-fit items-center justify-between gap-1.5 rounded-none border border-transparent border-b-input bg-transparent px-0 py-2 text-sm whitespace-nowrap transition-[color,border-color] outline-none focus-visible:border-b-ring disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-b-destructive data-placeholder:text-muted-foreground data-[size=default]:h-10 data-[size=sm]:h-9 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:aria-invalid:border-b-destructive/50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5", e),
112
+ ...r,
113
+ children: [n, /* @__PURE__ */ z(V.Icon, { render: /* @__PURE__ */ z(_, { className: "pointer-events-none size-3.5 text-muted-foreground" }) })]
114
+ });
115
+ }
116
+ function _e({ className: t, children: n, side: r = "bottom", sideOffset: i = 4, align: a = "center", alignOffset: o = 0, alignItemWithTrigger: s = !0, ...c }) {
117
+ let l = e.useContext(K);
118
+ return /* @__PURE__ */ z(V.Portal, {
119
+ container: l,
120
+ children: /* @__PURE__ */ z(V.Positioner, {
121
+ side: r,
122
+ sideOffset: i,
123
+ align: a,
124
+ alignOffset: o,
125
+ alignItemWithTrigger: s,
126
+ className: "isolate z-50",
127
+ children: /* @__PURE__ */ B(V.Popup, {
128
+ "data-slot": "select-content",
129
+ "data-align-trigger": s,
130
+ className: L("relative isolate z-50 max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-none bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", t),
131
+ ...c,
132
+ children: [
133
+ /* @__PURE__ */ z(ve, {}),
134
+ /* @__PURE__ */ z(V.List, { children: n }),
135
+ /* @__PURE__ */ z(J, {})
136
+ ]
137
+ })
138
+ })
139
+ });
140
+ }
141
+ function q({ className: e, children: t, ...n }) {
142
+ return /* @__PURE__ */ B(V.Item, {
143
+ "data-slot": "select-item",
144
+ className: L("relative flex w-full cursor-default items-center gap-2.5 rounded-none py-2 pr-8 pl-3 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2", e),
145
+ ...n,
146
+ children: [/* @__PURE__ */ z(V.ItemText, {
147
+ className: "flex flex-1 shrink-0 gap-2 whitespace-nowrap",
148
+ children: t
149
+ }), /* @__PURE__ */ z(V.ItemIndicator, {
150
+ render: /* @__PURE__ */ z("span", { className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center" }),
151
+ children: /* @__PURE__ */ z(h, { className: "pointer-events-none" })
152
+ })]
153
+ });
154
+ }
155
+ function ve({ className: e, ...t }) {
156
+ return /* @__PURE__ */ z(V.ScrollUpArrow, {
157
+ "data-slot": "select-scroll-up-button",
158
+ className: L("top-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-3.5", e),
159
+ ...t,
160
+ children: /* @__PURE__ */ z(b, {})
161
+ });
162
+ }
163
+ function J({ className: e, ...t }) {
164
+ return /* @__PURE__ */ z(V.ScrollDownArrow, {
165
+ "data-slot": "select-scroll-down-button",
166
+ className: L("bottom-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-3.5", e),
167
+ ...t,
168
+ children: /* @__PURE__ */ z(_, {})
169
+ });
170
+ }
171
+ //#endregion
172
+ //#region src/components/ui/table.tsx
173
+ function ye({ className: e, ...t }) {
174
+ return /* @__PURE__ */ z("div", {
175
+ "data-slot": "table-container",
176
+ className: "relative w-full overflow-x-auto",
177
+ children: /* @__PURE__ */ z("table", {
178
+ "data-slot": "table",
179
+ className: L("w-full caption-bottom text-sm", e),
180
+ ...t
181
+ })
182
+ });
183
+ }
184
+ function be({ className: e, ...t }) {
185
+ return /* @__PURE__ */ z("thead", {
186
+ "data-slot": "table-header",
187
+ className: L("[&_tr]:border-b", e),
188
+ ...t
189
+ });
190
+ }
191
+ function xe({ className: e, ...t }) {
192
+ return /* @__PURE__ */ z("tbody", {
193
+ "data-slot": "table-body",
194
+ className: L("[&_tr:last-child]:border-0", e),
195
+ ...t
196
+ });
197
+ }
198
+ function Se({ className: e, ...t }) {
199
+ return /* @__PURE__ */ z("tr", {
200
+ "data-slot": "table-row",
201
+ className: L("border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted", e),
202
+ ...t
203
+ });
204
+ }
205
+ function Ce({ className: e, ...t }) {
206
+ return /* @__PURE__ */ z("th", {
207
+ "data-slot": "table-head",
208
+ className: L("h-12 px-3 text-left align-middle text-xs font-medium tracking-wider whitespace-nowrap text-muted-foreground uppercase [&:has([role=checkbox])]:pr-0", e),
209
+ ...t
210
+ });
211
+ }
212
+ function we({ className: e, ...t }) {
213
+ return /* @__PURE__ */ z("td", {
214
+ "data-slot": "table-cell",
215
+ className: L("p-3 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", e),
216
+ ...t
217
+ });
218
+ }
219
+ //#endregion
220
+ //#region src/components/ui/textarea.tsx
221
+ function Te({ className: e, ...t }) {
222
+ return /* @__PURE__ */ z("textarea", {
223
+ "data-slot": "textarea",
224
+ className: L("flex field-sizing-content min-h-16 w-full resize-none rounded-none border border-transparent border-b-input bg-transparent px-0 py-3 text-base transition-[color,border-color] outline-none placeholder:text-muted-foreground focus-visible:border-b-ring disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-b-destructive md:text-sm dark:aria-invalid:border-b-destructive/50", e),
225
+ ...t
226
+ });
227
+ }
228
+ //#endregion
229
+ //#region src/components/ui/toast.tsx
230
+ var Ee = H.createToastManager();
231
+ function Y({ ...e }) {
232
+ return /* @__PURE__ */ z(H.Provider, { ...e });
233
+ }
234
+ function De({ ...t }) {
235
+ let n = e.useContext(K);
236
+ return /* @__PURE__ */ z(H.Portal, {
237
+ "data-slot": "toast-portal",
238
+ container: n,
239
+ ...t
240
+ });
241
+ }
242
+ function Oe({ className: e, ...t }) {
243
+ return /* @__PURE__ */ z(H.Viewport, {
244
+ "data-slot": "toast-viewport",
245
+ className: L("pointer-events-none fixed inset-x-4 bottom-4 z-50 mx-auto w-auto max-w-sm outline-none sm:right-4 sm:left-auto sm:mx-0 sm:w-full", e),
246
+ ...t
247
+ });
248
+ }
249
+ function ke({ className: e, ...t }) {
250
+ return /* @__PURE__ */ z(H.Root, {
251
+ "data-slot": "toast",
252
+ className: L("group/toast pointer-events-auto absolute right-0 bottom-0 z-[calc(1000-var(--toast-index))] w-full origin-bottom rounded-none! border bg-popover text-popover-foreground shadow-lg will-change-transform outline-none select-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50", "[--gap:0.75rem] [--height:var(--toast-frontmost-height,var(--toast-height))] [--offset-y:calc(var(--toast-offset-y)*-1+calc(var(--toast-index)*var(--gap)*-1)+var(--toast-swipe-movement-y))] [--peek:0.75rem] [--scale:calc(max(0,1-(var(--toast-index)*0.1)))] [--shrink:calc(1-var(--scale))]", "h-(--height) [transform:translateX(var(--toast-swipe-movement-x))_translateY(calc(var(--toast-swipe-movement-y)-(var(--toast-index)*var(--peek))-(var(--shrink)*var(--height))))_scale(var(--scale))] [transition:transform_500ms_cubic-bezier(0.22,1,0.36,1),opacity_500ms,height_150ms]", "after:absolute after:top-full after:left-0 after:h-[calc(var(--gap)+1px)] after:w-full after:content-['']", "data-expanded:h-(--toast-height) data-expanded:[transform:translateX(var(--toast-swipe-movement-x))_translateY(var(--offset-y))]", "data-limited:opacity-0 data-starting-style:[transform:translateY(150%)]", "[&[data-ending-style]:not([data-limited]):not([data-swipe-direction])]:[transform:translateY(150%)]", "data-ending-style:data-[swipe-direction=down]:[transform:translateY(calc(var(--toast-swipe-movement-y)+150%))]", "data-ending-style:data-[swipe-direction=left]:[transform:translateX(calc(var(--toast-swipe-movement-x)-150%))_translateY(var(--offset-y))]", "data-ending-style:data-[swipe-direction=right]:[transform:translateX(calc(var(--toast-swipe-movement-x)+150%))_translateY(var(--offset-y))]", "data-ending-style:data-[swipe-direction=up]:[transform:translateY(calc(var(--toast-swipe-movement-y)-150%))]", "data-expanded:data-ending-style:data-[swipe-direction=down]:[transform:translateY(calc(var(--toast-swipe-movement-y)+150%))]", "data-expanded:data-ending-style:data-[swipe-direction=left]:[transform:translateX(calc(var(--toast-swipe-movement-x)-150%))_translateY(var(--offset-y))]", "data-expanded:data-ending-style:data-[swipe-direction=right]:[transform:translateX(calc(var(--toast-swipe-movement-x)+150%))_translateY(var(--offset-y))]", "data-expanded:data-ending-style:data-[swipe-direction=up]:[transform:translateY(calc(var(--toast-swipe-movement-y)-150%))]", e),
253
+ ...t
254
+ });
255
+ }
256
+ function Ae({ className: e, ...t }) {
257
+ return /* @__PURE__ */ z(H.Content, {
258
+ "data-slot": "toast-content",
259
+ className: L("flex h-full items-center gap-3 overflow-hidden p-4 transition-opacity duration-250 ease-[cubic-bezier(0.22,1,0.36,1)] data-behind:opacity-0 data-expanded:opacity-100", e),
260
+ ...t
261
+ });
262
+ }
263
+ function je({ className: e, ...t }) {
264
+ return /* @__PURE__ */ z(H.Title, {
265
+ "data-slot": "toast-title",
266
+ className: L("text-sm font-medium", e),
267
+ ...t
268
+ });
269
+ }
270
+ function X({ className: e, ...t }) {
271
+ return /* @__PURE__ */ z(H.Description, {
272
+ "data-slot": "toast-description",
273
+ className: L("text-sm text-muted-foreground", e),
274
+ ...t
275
+ });
276
+ }
277
+ function Me({ className: e, render: t = /* @__PURE__ */ z(G, {
278
+ variant: "outline",
279
+ size: "sm"
280
+ }), ...n }) {
281
+ return /* @__PURE__ */ z(H.Action, {
282
+ "data-slot": "toast-action",
283
+ render: t,
284
+ className: L("shrink-0", e),
285
+ ...n
286
+ });
287
+ }
288
+ function Ne({ className: e, children: t, render: n = /* @__PURE__ */ z(G, {
289
+ variant: "ghost",
290
+ size: "icon-sm"
291
+ }), ...r }) {
292
+ return /* @__PURE__ */ z(H.Close, {
293
+ "data-slot": "toast-close",
294
+ "aria-label": "Close toast",
295
+ render: n,
296
+ className: L("relative shrink-0 text-muted-foreground after:absolute after:-inset-2 after:content-[''] hover:text-foreground", e),
297
+ ...r,
298
+ children: t ?? /* @__PURE__ */ z(k, { "aria-hidden": "true" })
299
+ });
300
+ }
301
+ function Pe({ type: e }) {
302
+ let t = null;
303
+ return e === "success" && (t = /* @__PURE__ */ z(x, { "aria-hidden": "true" })), e === "info" && (t = /* @__PURE__ */ z(S, { "aria-hidden": "true" })), e === "warning" && (t = /* @__PURE__ */ z(O, { "aria-hidden": "true" })), e === "error" && (t = /* @__PURE__ */ z(T, {
304
+ className: "text-destructive",
305
+ "aria-hidden": "true"
306
+ })), e === "loading" && (t = /* @__PURE__ */ z(C, {
307
+ className: "animate-spin",
308
+ "aria-hidden": "true"
309
+ })), t ? /* @__PURE__ */ z("span", {
310
+ "data-slot": "toast-icon",
311
+ className: "shrink-0 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
312
+ children: t
313
+ }) : null;
314
+ }
315
+ function Fe() {
316
+ let { toasts: e } = H.useToastManager();
317
+ return e.map((e) => /* @__PURE__ */ z(ke, {
318
+ toast: e,
319
+ children: /* @__PURE__ */ B(Ae, { children: [
320
+ /* @__PURE__ */ z(Pe, { type: e.type }),
321
+ /* @__PURE__ */ B("div", {
322
+ className: "flex min-w-0 flex-1 flex-col gap-1",
323
+ children: [/* @__PURE__ */ z(je, {}), /* @__PURE__ */ z(X, {})]
324
+ }),
325
+ /* @__PURE__ */ z(Me, {}),
326
+ /* @__PURE__ */ z(Ne, {})
327
+ ] })
328
+ }, e.id));
329
+ }
330
+ function Ie({ children: e, toastManager: t = Ee, ...n }) {
331
+ return /* @__PURE__ */ B(Y, {
332
+ toastManager: t,
333
+ ...n,
334
+ children: [e, /* @__PURE__ */ z(De, { children: /* @__PURE__ */ z(Oe, { children: /* @__PURE__ */ z(Fe, {}) }) })]
335
+ });
336
+ }
337
+ H.createToastManager;
338
+ var Le = H.useToastManager, Re = new Intl.DateTimeFormat(void 0, {
339
+ dateStyle: "medium",
340
+ timeStyle: "short"
341
+ }), ze = new Intl.DateTimeFormat(void 0, { dateStyle: "medium" }), Be = 10, Ve = "__bebop_filter_all__";
342
+ function He(e, t) {
343
+ return e[t] || void 0;
344
+ }
345
+ function Ue(e, t) {
346
+ return e[t];
347
+ }
348
+ function We(e, t = !1) {
349
+ if (!(e instanceof Date) && typeof e != "string" && typeof e != "number") return "—";
350
+ let n = e instanceof Date ? e : new Date(e);
351
+ return Number.isNaN(n.valueOf()) ? "—" : (t ? Re : ze).format(n);
352
+ }
353
+ function Ge(e, t, n) {
354
+ if (e === t) return 0;
355
+ if (e == null) return -1;
356
+ if (t == null) return 1;
357
+ if (n?.kind === "number" || n?.kind === "integer") {
358
+ let n = Number(e) - Number(t);
359
+ if (!Number.isNaN(n)) return n;
360
+ }
361
+ if (n?.kind === "boolean" && typeof e == "boolean" && typeof t == "boolean") return Number(e) - Number(t);
362
+ if (n?.kind === "date") {
363
+ let n = e instanceof Date ? e.getTime() : new Date(String(e)).getTime(), r = t instanceof Date ? t.getTime() : new Date(String(t)).getTime();
364
+ if (!Number.isNaN(n) && !Number.isNaN(r)) return n - r;
365
+ }
366
+ return String(e).localeCompare(String(t), void 0, {
367
+ numeric: !0,
368
+ sensitivity: "base"
369
+ });
370
+ }
371
+ function Ke(e) {
372
+ return e.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ");
373
+ }
374
+ function qe(e, t) {
375
+ return ("optionLabels" in e ? e.optionLabels?.[t] : void 0) ?? Ke(t);
376
+ }
377
+ function Je(e, t, n) {
378
+ return t == null || t === "" ? /* @__PURE__ */ z("span", {
379
+ className: "text-muted-foreground",
380
+ children: "—"
381
+ }) : e?.kind === "boolean" ? /* @__PURE__ */ z(U, {
382
+ variant: t ? "default" : "secondary",
383
+ children: t ? "Yes" : "No"
384
+ }) : e?.kind === "date" ? We(t) : e?.kind === "json" ? /* @__PURE__ */ z("span", {
385
+ className: "font-mono text-xs",
386
+ children: JSON.stringify(t)
387
+ }) : e?.kind === "relation" ? n?.[e.relationTo ?? ""]?.find((e) => e.id === t)?.name ?? /* @__PURE__ */ z("span", {
388
+ className: "font-mono text-xs",
389
+ children: String(t).slice(0, 8)
390
+ }) : e?.kind === "select" ? qe(e, String(t)) : String(t);
391
+ }
392
+ function Z(e, t) {
393
+ return e.kind === "join" ? void 0 : t[e.storageName];
394
+ }
395
+ function Q(e, t) {
396
+ return e.fields.find((e) => e.name === t);
397
+ }
398
+ function Ye(e) {
399
+ return e.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ");
400
+ }
401
+ function $(e) {
402
+ return e.fields.filter((e) => e.kind !== "join");
403
+ }
404
+ function Xe(e, t, n) {
405
+ let r = Ue(e, t), i = n.enabled === !1 ? void 0 : r?.query({
406
+ where: n.where,
407
+ orderBy: n.sort,
408
+ includeTimestamps: !0,
409
+ ...n.searchActive ? {} : {
410
+ limit: n.pageSize,
411
+ offset: (n.page - 1) * n.pageSize
412
+ }
413
+ }), a = n.enabled === !1 || n.searchActive ? void 0 : r?.queryIds({ where: n.where });
414
+ return {
415
+ rows: s(i),
416
+ ids: s(a)
417
+ };
418
+ }
419
+ function Ze(e, t, n) {
420
+ let [i, a] = o({}), s = n.map((e) => JSON.stringify(e)).join("\0");
421
+ return r(() => {
422
+ let r = !0;
423
+ if (!t || n.length === 0) {
424
+ a((e) => Object.keys(e).length ? {} : e);
425
+ return;
426
+ }
427
+ return a(Object.fromEntries(n.map((e) => [e.id, {
428
+ update: "unknown",
429
+ delete: "unknown"
430
+ }]))), Promise.all(n.map(async (n) => {
431
+ try {
432
+ let [r, i] = await Promise.all([e.canUpdate(t, n.id, n), e.canDelete(t, n.id)]);
433
+ return [n.id, {
434
+ update: r,
435
+ delete: i
436
+ }];
437
+ } catch {
438
+ return [n.id, {
439
+ update: "unknown",
440
+ delete: "unknown"
441
+ }];
442
+ }
443
+ })).then((e) => {
444
+ r && a(Object.fromEntries(e));
445
+ }), () => {
446
+ r = !1;
447
+ };
448
+ }, [
449
+ e,
450
+ s,
451
+ t
452
+ ]), i;
453
+ }
454
+ function Qe(e, t, n) {
455
+ let [i, a] = o({}), s = n.map((e) => JSON.stringify(e)).join("\0");
456
+ return r(() => {
457
+ let r = !0;
458
+ if (!t || n.length === 0) {
459
+ a((e) => Object.keys(e).length ? {} : e);
460
+ return;
461
+ }
462
+ return a(Object.fromEntries(n.map((e) => [e.id, "unknown"]))), Promise.all(n.map(async (n) => {
463
+ try {
464
+ return [n.id, await e.canRead(t, n.id)];
465
+ } catch {
466
+ return [n.id, "unknown"];
467
+ }
468
+ })).then((e) => {
469
+ r && a(Object.fromEntries(e));
470
+ }), () => {
471
+ r = !1;
472
+ };
473
+ }, [
474
+ e,
475
+ s,
476
+ t
477
+ ]), i;
478
+ }
479
+ function $e({ app: e, client: t, manifest: n, canAccessAdmin: i, user: a, createDefaults: s, relationOptions: c, onLogout: l }) {
480
+ let [u, d] = o();
481
+ r(() => {
482
+ if (i) return t.onMutationError((e) => {
483
+ d(e.code === "permission_denied" ? "Jazz rejected a write because the current session does not have access." : "Jazz could not sync a recent write. The local change may be reverted when sync finishes.");
484
+ });
485
+ }, [i, t]);
486
+ let f = N([{
487
+ element: /* @__PURE__ */ z(et, {
488
+ manifest: n,
489
+ user: a,
490
+ onLogout: l,
491
+ mutationError: u
492
+ }),
493
+ children: [
494
+ {
495
+ index: !0,
496
+ element: /* @__PURE__ */ z(tt, { manifest: n })
497
+ },
498
+ {
499
+ path: "collections/:collectionSlug",
500
+ element: /* @__PURE__ */ z(nt, {
501
+ app: e,
502
+ client: t,
503
+ manifest: n,
504
+ relationOptions: c
505
+ })
506
+ },
507
+ {
508
+ path: "collections/:collectionSlug/create",
509
+ element: /* @__PURE__ */ z(it, {
510
+ app: e,
511
+ client: t,
512
+ manifest: n,
513
+ createDefaults: s,
514
+ relationOptions: c
515
+ })
516
+ },
517
+ {
518
+ path: "collections/:collectionSlug/:id",
519
+ element: /* @__PURE__ */ z(it, {
520
+ app: e,
521
+ client: t,
522
+ manifest: n,
523
+ createDefaults: s,
524
+ relationOptions: c
525
+ })
526
+ },
527
+ {
528
+ path: "*",
529
+ element: /* @__PURE__ */ z(pt, {})
530
+ }
531
+ ]
532
+ }]);
533
+ return i ? f : /* @__PURE__ */ z("main", {
534
+ className: "bebop-admin grid min-h-svh place-items-center bg-background px-6 text-foreground",
535
+ children: /* @__PURE__ */ z("p", {
536
+ role: "alert",
537
+ children: "You do not have access to the Bebop admin."
538
+ })
539
+ });
540
+ }
541
+ function et({ manifest: e, user: t, onLogout: r, mutationError: i }) {
542
+ let s = a(null), [c, l] = o(!1), [u, d] = o(!1), [f, p] = o(!0), [m, h] = o(), g = ie(), _ = n((e) => {
543
+ h(e ? {
544
+ path: g.pathname,
545
+ title: e
546
+ } : void 0);
547
+ }, [g.pathname]), te = m?.path === g.pathname ? m.title : void 0, b = g.pathname.match(/\/collections\/([^/]+)/)?.[1], x = b ? e.collections[b] : void 0, S = g.pathname.endsWith("/create"), C = !!(x && g.pathname.match(/\/collections\/[^/]+\/[^/]+\/?$/) && !S), T = Object.values(e.collections).sort((e, t) => e.labels.plural.localeCompare(t.labels.plural)), re = t?.name?.trim() || "Signed in", E = t?.email?.trim() || "Email unavailable", D = (t?.name?.trim() || t?.email?.trim() || "U").split(/[\s@._-]+/).filter(Boolean).slice(0, 2).map((e) => e[0]).join("").toUpperCase();
548
+ return /* @__PURE__ */ z(K.Provider, {
549
+ value: s,
550
+ children: /* @__PURE__ */ z(Ie, { children: /* @__PURE__ */ B("div", {
551
+ ref: s,
552
+ className: "bebop-admin min-h-svh bg-background text-foreground",
553
+ children: [
554
+ /* @__PURE__ */ B("aside", {
555
+ className: `admin-sidebar ${u ? "admin-sidebar-hidden" : ""} ${c ? "admin-sidebar-open" : ""}`,
556
+ children: [
557
+ /* @__PURE__ */ z("div", {
558
+ className: "admin-sidebar-header",
559
+ children: /* @__PURE__ */ z(G, {
560
+ variant: "outline",
561
+ size: "icon-xs",
562
+ "aria-label": "Collapse sidebar",
563
+ onClick: () => d(!0),
564
+ children: /* @__PURE__ */ z(ee, { size: 18 })
565
+ })
566
+ }),
567
+ /* @__PURE__ */ B("div", {
568
+ className: "admin-sidebar-scroll",
569
+ children: [/* @__PURE__ */ B("button", {
570
+ className: "admin-nav-heading",
571
+ "aria-expanded": f,
572
+ onClick: () => p((e) => !e),
573
+ children: [/* @__PURE__ */ z("span", { children: "Collections" }), /* @__PURE__ */ z(y, {
574
+ size: 16,
575
+ className: f ? "" : "rotate-180"
576
+ })]
577
+ }), f && /* @__PURE__ */ z("nav", {
578
+ "aria-label": "Collections",
579
+ className: "admin-collection-nav",
580
+ children: T.map((e) => /* @__PURE__ */ z(j, {
581
+ to: `/admin/collections/${e.slug}`,
582
+ className: ({ isActive: e }) => `admin-nav-link ${e ? "admin-nav-active" : ""}`,
583
+ onClick: () => l(!1),
584
+ children: /* @__PURE__ */ z("span", {
585
+ className: "truncate",
586
+ children: e.labels.plural
587
+ })
588
+ }, e.slug))
589
+ })]
590
+ }),
591
+ /* @__PURE__ */ B("div", {
592
+ className: "admin-sidebar-footer",
593
+ children: [
594
+ /* @__PURE__ */ z("div", {
595
+ className: "admin-avatar",
596
+ children: D
597
+ }),
598
+ /* @__PURE__ */ B("div", {
599
+ className: "min-w-0 flex-1",
600
+ children: [/* @__PURE__ */ z("p", {
601
+ className: "truncate text-sm font-medium text-sidebar-foreground",
602
+ children: re
603
+ }), /* @__PURE__ */ z("p", {
604
+ className: "truncate text-xs text-sidebar-foreground/60",
605
+ children: E
606
+ })]
607
+ }),
608
+ r && /* @__PURE__ */ z(G, {
609
+ variant: "ghost",
610
+ size: "icon",
611
+ className: "text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
612
+ "aria-label": "Sign out",
613
+ onClick: () => void r(),
614
+ children: /* @__PURE__ */ z(ne, { size: 16 })
615
+ })
616
+ ]
617
+ })
618
+ ]
619
+ }),
620
+ c && /* @__PURE__ */ z("button", {
621
+ className: "admin-mobile-backdrop",
622
+ "aria-label": "Close navigation",
623
+ onClick: () => l(!1)
624
+ }),
625
+ /* @__PURE__ */ B("div", {
626
+ className: `admin-main ${u ? "admin-main-expanded" : ""}`,
627
+ children: [/* @__PURE__ */ B("header", {
628
+ className: "admin-topbar",
629
+ children: [
630
+ /* @__PURE__ */ z(G, {
631
+ variant: "ghost",
632
+ size: "icon",
633
+ className: "admin-mobile-menu",
634
+ "aria-label": "Open navigation",
635
+ onClick: () => l(!0),
636
+ children: /* @__PURE__ */ z(w, { size: 18 })
637
+ }),
638
+ u && /* @__PURE__ */ z(G, {
639
+ variant: "outline",
640
+ size: "icon",
641
+ className: "admin-sidebar-expand",
642
+ "aria-label": "Expand sidebar",
643
+ onClick: () => d(!1),
644
+ children: /* @__PURE__ */ z(v, { size: 18 })
645
+ }),
646
+ /* @__PURE__ */ B("div", {
647
+ className: "admin-breadcrumbs",
648
+ children: [
649
+ /* @__PURE__ */ z(A, {
650
+ to: "/admin",
651
+ className: "admin-brand-mark",
652
+ "aria-label": "Bebop dashboard",
653
+ children: "b"
654
+ }),
655
+ /* @__PURE__ */ z("span", {
656
+ className: "admin-breadcrumb-divider",
657
+ children: "/"
658
+ }),
659
+ x ? /* @__PURE__ */ z(A, {
660
+ to: `/admin/collections/${x.slug}`,
661
+ className: "hover:underline",
662
+ children: x.labels.plural
663
+ }) : /* @__PURE__ */ z("span", { children: "Dashboard" }),
664
+ (S || C) && /* @__PURE__ */ B(le, { children: [/* @__PURE__ */ z("span", {
665
+ className: "text-muted-foreground",
666
+ children: "/"
667
+ }), /* @__PURE__ */ z("span", {
668
+ className: "max-w-56 truncate",
669
+ title: te,
670
+ children: S ? `New ${x?.labels.singular ?? "document"}` : te ?? "Document"
671
+ })] }),
672
+ b && !x && /* @__PURE__ */ z("span", { children: "Not found" })
673
+ ]
674
+ })
675
+ ]
676
+ }), /* @__PURE__ */ B("main", {
677
+ className: "admin-content",
678
+ children: [i && /* @__PURE__ */ z("div", {
679
+ className: "mb-5 border border-destructive/40 bg-destructive/10 px-4 py-3 text-sm text-destructive",
680
+ role: "alert",
681
+ children: i
682
+ }), /* @__PURE__ */ z(M, { context: { setDocumentBreadcrumb: _ } })]
683
+ })]
684
+ })
685
+ ]
686
+ }) })
687
+ });
688
+ }
689
+ function tt({ manifest: e }) {
690
+ let t = Object.values(e.collections).sort((e, t) => e.labels.plural.localeCompare(t.labels.plural));
691
+ return /* @__PURE__ */ B("section", { children: [/* @__PURE__ */ z("h1", {
692
+ className: "mb-6 text-[32px] font-normal leading-tight tracking-tight",
693
+ children: "Collections"
694
+ }), /* @__PURE__ */ z("div", {
695
+ className: "admin-collection-grid",
696
+ children: t.map((e) => /* @__PURE__ */ B("article", {
697
+ className: "admin-collection-card",
698
+ children: [/* @__PURE__ */ z(A, {
699
+ to: `/admin/collections/${e.slug}`,
700
+ className: "admin-collection-title",
701
+ children: e.labels.plural
702
+ }), /* @__PURE__ */ z(A, {
703
+ to: `/admin/collections/${e.slug}/create`,
704
+ className: "admin-collection-add",
705
+ "aria-label": `Create ${e.labels.singular}`,
706
+ children: /* @__PURE__ */ z(re, { size: 19 })
707
+ })]
708
+ }, e.slug))
709
+ })] });
710
+ }
711
+ function nt({ app: e, client: t, manifest: n, relationOptions: r }) {
712
+ let { collectionSlug: i = "" } = se(), a = n.collections[i];
713
+ return a ? /* @__PURE__ */ z(rt, {
714
+ app: e,
715
+ client: t,
716
+ collection: a,
717
+ relationOptions: r
718
+ }, a.slug) : /* @__PURE__ */ z(pt, {});
719
+ }
720
+ function rt({ app: e, client: t, collection: n, relationOptions: a }) {
721
+ let s = ae();
722
+ Le();
723
+ let l = c(), u = He(e, n.slug), [d, ee] = o(""), [h, _] = o({}), [y, b] = o({
724
+ field: n.defaultColumns[0] ?? "id",
725
+ direction: "asc"
726
+ }), [x, S] = o(1), [C, ne] = o(Be), [w, T] = o(() => /* @__PURE__ */ new Set()), [O, k] = o(() => n.defaultColumns.length ? [...n.defaultColumns] : $(n).slice(0, 4).map((e) => e.name)), [j, M] = o(null), [ie, oe] = o(), [se, N] = o(), P = n.fields.filter((e) => e.kind === "boolean" || e.kind === "select"), ce = i(() => Object.fromEntries(P.flatMap((e) => {
727
+ let t = h[e.name];
728
+ return t ? [[e.storageName, e.kind === "boolean" ? t === "true" : t]] : [];
729
+ })), [n, h]), F = !!d.trim(), I = Q(n, y.field), L = Q(n, n.defaultColumns[0] ?? ""), R = I && I.kind !== "join" ? I.storageName : y.field === "id" || L?.kind === "join" ? "id" : L?.storageName ?? "id", { rows: ue, ids: V } = Xe(t, n.slug, {
730
+ where: ce,
731
+ sort: {
732
+ field: R,
733
+ direction: y.direction
734
+ },
735
+ page: x,
736
+ pageSize: C,
737
+ searchActive: F
738
+ }), { data: H, isLoading: de, error: U } = ue, W = H ?? [], pe = Qe(l, u, W), K = W.filter((e) => pe[e.id] !== "denied"), ve = $(n).map((e) => e.name), J = ve.filter((e) => O.includes(e)), Te = i(() => {
739
+ let e = d.trim().toLocaleLowerCase(), t = K.filter((t) => {
740
+ let r = !e || n.listSearchableFields.some((r) => {
741
+ let i = Q(n, r), o = i ? Z(i, t) : t[r];
742
+ return `${(i?.kind === "relation" ? a?.[i.relationTo ?? ""]?.find((e) => e.id === o)?.name : void 0) ?? ""} ${String(o ?? "")}`.toLocaleLowerCase().includes(e);
743
+ }) || !n.listSearchableFields.length && t.id.toLocaleLowerCase().includes(e), i = P.every((e) => {
744
+ let n = h[e.name];
745
+ if (!n) return !0;
746
+ let r = Z(e, t);
747
+ return e.kind === "boolean" ? String(!!r) === n : String(r ?? "") === n;
748
+ });
749
+ return r && i;
750
+ }), r = Q(n, y.field);
751
+ return t.sort((e, t) => {
752
+ let n = Ge(r ? Z(r, e) : e[y.field], r ? Z(r, t) : t[y.field], r);
753
+ return y.direction === "asc" ? n : -n;
754
+ }), t;
755
+ }, [
756
+ n,
757
+ P,
758
+ h,
759
+ K,
760
+ a,
761
+ d,
762
+ y
763
+ ]), Ee = F ? Te.length : V.data?.length ?? 0, Y = Math.max(1, Math.ceil(Ee / C)), De = F ? Te.slice((Math.min(x, Y) - 1) * C, Math.min(x, Y) * C) : Te, Oe = Ze(l, u, De), ke = De.filter((e) => Oe[e.id]?.delete !== "denied"), Ae = ke.length > 0 && ke.every((e) => w.has(e.id)), je = K.filter((e) => w.has(e.id)), X = n.useAsTitle ? Q(n, n.useAsTitle) : void 0, Me = (X ?? Q(n, n.listSearchableFields[0] ?? ""))?.label ?? "Name", Ne = X && J.includes(X.name) ? X.name : J[0];
764
+ r(() => {
765
+ S(1), T(/* @__PURE__ */ new Set());
766
+ }, [d, h]), r(() => {
767
+ T(/* @__PURE__ */ new Set());
768
+ }, [
769
+ x,
770
+ C,
771
+ y
772
+ ]), r(() => {
773
+ (V.data || F) && S((e) => Math.min(e, Y));
774
+ }, [
775
+ V.data,
776
+ Y,
777
+ F
778
+ ]), r(() => {
779
+ let e = n.defaultColumns.length ? [...n.defaultColumns] : $(n).slice(0, 4).map((e) => e.name);
780
+ k(e), b({
781
+ field: e[0] ?? "id",
782
+ direction: "asc"
783
+ }), T(/* @__PURE__ */ new Set()), S(1), ne(Be);
784
+ }, [n]);
785
+ function Pe(e) {
786
+ b((t) => ({
787
+ field: e,
788
+ direction: t.field === e && t.direction === "asc" ? "desc" : "asc"
789
+ }));
790
+ }
791
+ function Fe(e) {
792
+ T((t) => {
793
+ let n = new Set(t);
794
+ return n.has(e) ? n.delete(e) : n.add(e), n;
795
+ });
796
+ }
797
+ function Ie() {
798
+ T((e) => {
799
+ let t = new Set(e);
800
+ return Ae ? ke.forEach((e) => t.delete(e.id)) : ke.forEach((e) => t.add(e.id)), t;
801
+ });
802
+ }
803
+ let Re = j?.length === 1 ? String(X ? Z(X, j[0]) ?? j[0].id : j[0].id) : "", ze = Ee ? (Math.min(x, Y) - 1) * C + 1 : 0, Ue = Math.min(x * C, Ee), Ke = de || !F && V.isLoading, $e = U ?? (F ? void 0 : V.error);
804
+ return /* @__PURE__ */ B("div", { children: [
805
+ /* @__PURE__ */ B("div", {
806
+ className: "admin-list-heading",
807
+ children: [/* @__PURE__ */ z("h1", {
808
+ className: "text-[32px] font-normal leading-tight tracking-tight",
809
+ children: n.labels.plural
810
+ }), /* @__PURE__ */ z(G, {
811
+ variant: "secondary",
812
+ size: "xs",
813
+ className: "text-[13px] font-medium normal-case tracking-normal",
814
+ onClick: () => s(`/admin/collections/${n.slug}/create`),
815
+ children: "Create New"
816
+ })]
817
+ }),
818
+ se && /* @__PURE__ */ z("p", {
819
+ className: "mb-3 border border-destructive/40 bg-destructive/10 px-4 py-3 text-sm text-destructive",
820
+ role: "alert",
821
+ children: se
822
+ }),
823
+ /* @__PURE__ */ B("div", {
824
+ className: "admin-table-toolbar",
825
+ children: [/* @__PURE__ */ B("div", {
826
+ className: "relative min-w-0 flex-1",
827
+ children: [/* @__PURE__ */ z(E, {
828
+ size: 16,
829
+ className: "pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"
830
+ }), /* @__PURE__ */ z(fe, {
831
+ value: d,
832
+ onChange: (e) => ee(e.target.value),
833
+ placeholder: `Search by ${Me}`,
834
+ className: "h-8 pl-10 text-[13px] focus-visible:bg-background",
835
+ "aria-label": `Search by ${Me}`
836
+ })]
837
+ }), /* @__PURE__ */ B("div", {
838
+ className: "flex shrink-0 items-center gap-2",
839
+ children: [
840
+ je.length > 0 && /* @__PURE__ */ B(G, {
841
+ variant: "destructive",
842
+ onClick: () => {
843
+ oe(void 0), N(void 0), M(je);
844
+ },
845
+ children: [
846
+ /* @__PURE__ */ z(D, { size: 15 }),
847
+ " Delete ",
848
+ je.length
849
+ ]
850
+ }),
851
+ /* @__PURE__ */ B("details", {
852
+ className: "admin-table-menu",
853
+ children: [/* @__PURE__ */ B("summary", {
854
+ className: "admin-table-menu-trigger",
855
+ children: ["Columns ", /* @__PURE__ */ z(g, { size: 15 })]
856
+ }), /* @__PURE__ */ B("div", {
857
+ className: "admin-table-menu-content",
858
+ children: [/* @__PURE__ */ z("p", {
859
+ className: "admin-table-menu-label",
860
+ children: "Visible columns"
861
+ }), ve.map((e) => {
862
+ let t = Q(n, e), r = O.includes(e);
863
+ return /* @__PURE__ */ B("label", {
864
+ className: "admin-menu-checkbox",
865
+ children: [/* @__PURE__ */ z("input", {
866
+ type: "checkbox",
867
+ checked: r,
868
+ disabled: r && O.length === 1,
869
+ onChange: () => k((t) => r ? t.filter((t) => t !== e) : [...t, e])
870
+ }), /* @__PURE__ */ z("span", { children: t?.label ?? Ye(e) })]
871
+ }, e);
872
+ })]
873
+ })]
874
+ }),
875
+ P.length > 0 && /* @__PURE__ */ B("details", {
876
+ className: "admin-table-menu",
877
+ children: [/* @__PURE__ */ B("summary", {
878
+ className: "admin-table-menu-trigger",
879
+ children: ["Filters ", /* @__PURE__ */ z(g, { size: 15 })]
880
+ }), /* @__PURE__ */ z("div", {
881
+ className: "admin-table-menu-content admin-filter-menu",
882
+ children: P.map((e) => /* @__PURE__ */ B("label", {
883
+ className: "admin-filter-field",
884
+ children: [/* @__PURE__ */ z("span", { children: e.label }), /* @__PURE__ */ B(me, {
885
+ value: h[e.name] || Ve,
886
+ onValueChange: (t) => _((n) => ({
887
+ ...n,
888
+ [e.name]: t === Ve ? "" : t ?? ""
889
+ })),
890
+ children: [/* @__PURE__ */ z(ge, {
891
+ className: "w-full",
892
+ "aria-label": `Filter by ${e.label}`,
893
+ children: /* @__PURE__ */ z(he, { children: h[e.name] ? e.kind === "boolean" ? h[e.name] === "true" ? "Yes" : "No" : qe(e, h[e.name]) : `All ${e.label.toLocaleLowerCase()}` })
894
+ }), /* @__PURE__ */ B(_e, { children: [/* @__PURE__ */ B(q, {
895
+ value: Ve,
896
+ children: ["All ", e.label.toLocaleLowerCase()]
897
+ }), e.kind === "boolean" ? /* @__PURE__ */ B(le, { children: [/* @__PURE__ */ z(q, {
898
+ value: "true",
899
+ children: "Yes"
900
+ }), /* @__PURE__ */ z(q, {
901
+ value: "false",
902
+ children: "No"
903
+ })] }) : e.options?.map((t) => /* @__PURE__ */ z(q, {
904
+ value: t,
905
+ children: qe(e, t)
906
+ }, t))] })]
907
+ })]
908
+ }, e.name))
909
+ })]
910
+ })
911
+ ]
912
+ })]
913
+ }),
914
+ $e ? /* @__PURE__ */ B("div", {
915
+ className: "py-12 text-center text-sm text-destructive",
916
+ children: ["Could not load this collection: ", $e.message]
917
+ }) : Ke ? /* @__PURE__ */ z("div", {
918
+ className: "py-12 text-center text-sm text-muted-foreground",
919
+ children: "Loading documents…"
920
+ }) : Ee === 0 ? /* @__PURE__ */ B("div", {
921
+ className: "py-16 text-center",
922
+ children: [
923
+ /* @__PURE__ */ z("h2", {
924
+ className: "text-sm font-medium",
925
+ children: K.length ? "No matching documents" : W.length ? "No readable documents" : "No documents yet"
926
+ }),
927
+ /* @__PURE__ */ z("p", {
928
+ className: "mt-1 text-sm text-muted-foreground",
929
+ children: K.length ? "Try changing your search or filters." : W.length ? "Jazz denied read access for the available documents." : `Create your first ${n.labels.singular.toLocaleLowerCase()} to get started.`
930
+ }),
931
+ !W.length && /* @__PURE__ */ B(G, {
932
+ variant: "secondary",
933
+ className: "mt-4",
934
+ onClick: () => s(`/admin/collections/${n.slug}/create`),
935
+ children: [/* @__PURE__ */ z(re, { size: 16 }), " Create New"]
936
+ })
937
+ ]
938
+ }) : /* @__PURE__ */ B("div", {
939
+ className: "admin-table-section",
940
+ children: [/* @__PURE__ */ B(ye, { children: [/* @__PURE__ */ z(be, { children: /* @__PURE__ */ B(Se, { children: [
941
+ /* @__PURE__ */ z(Ce, {
942
+ className: "w-12",
943
+ children: /* @__PURE__ */ z("input", {
944
+ type: "checkbox",
945
+ className: "admin-checkbox",
946
+ "aria-label": "Select all documents on this page",
947
+ checked: Ae,
948
+ disabled: ke.length === 0,
949
+ onChange: Ie
950
+ })
951
+ }),
952
+ J.map((e) => {
953
+ let t = Q(n, e), r = y.field === e ? y.direction === "asc" ? p : f : m;
954
+ return /* @__PURE__ */ z(Ce, {
955
+ className: "h-10 text-[13px] font-normal normal-case tracking-normal",
956
+ children: /* @__PURE__ */ B("button", {
957
+ className: "admin-sort-button",
958
+ onClick: () => Pe(e),
959
+ children: [t?.label ?? Ye(e), /* @__PURE__ */ z(r, { size: 13 })]
960
+ })
961
+ }, e);
962
+ }),
963
+ n.timestamps && /* @__PURE__ */ z(Ce, {
964
+ className: "h-10 text-[13px] font-normal normal-case tracking-normal",
965
+ children: "Updated"
966
+ })
967
+ ] }) }), /* @__PURE__ */ z(xe, { children: De.length === 0 ? /* @__PURE__ */ z(Se, { children: /* @__PURE__ */ z(we, {
968
+ colSpan: J.length + (n.timestamps ? 2 : 1),
969
+ className: "py-8 text-center text-sm text-muted-foreground",
970
+ children: "No documents on this page."
971
+ }) }) : De.map((e, t) => /* @__PURE__ */ B(Se, {
972
+ className: t % 2 == 0 ? "bg-muted/50 hover:bg-muted" : "hover:bg-muted/50",
973
+ children: [
974
+ /* @__PURE__ */ z(we, {
975
+ className: "w-12",
976
+ children: /* @__PURE__ */ z("input", {
977
+ type: "checkbox",
978
+ className: "admin-checkbox",
979
+ "aria-label": `Select ${String(X ? Z(X, e) ?? e.id : e.id)}`,
980
+ checked: w.has(e.id),
981
+ disabled: Oe[e.id]?.delete === "denied",
982
+ onChange: () => Fe(e.id)
983
+ })
984
+ }),
985
+ J.map((t) => {
986
+ let r = Q(n, t), i = r ? Z(r, e) : e[t], o = Ne === t;
987
+ return /* @__PURE__ */ z(we, {
988
+ className: `admin-table-cell ${o ? "font-medium" : ""}`,
989
+ children: o ? /* @__PURE__ */ z(A, {
990
+ to: `/admin/collections/${n.slug}/${e.id}`,
991
+ className: "underline underline-offset-2 hover:text-primary",
992
+ children: Je(r, i, a)
993
+ }) : Je(r, i, a)
994
+ }, t);
995
+ }),
996
+ n.timestamps && /* @__PURE__ */ z(we, {
997
+ className: "whitespace-nowrap text-xs text-muted-foreground",
998
+ children: We(e.$updatedAt, !0)
999
+ })
1000
+ ]
1001
+ }, e.id)) })] }), /* @__PURE__ */ B("div", {
1002
+ className: "admin-table-pagination",
1003
+ children: [/* @__PURE__ */ B("span", { children: [
1004
+ ze,
1005
+ "–",
1006
+ Ue,
1007
+ " of ",
1008
+ Ee
1009
+ ] }), /* @__PURE__ */ B("div", {
1010
+ className: "flex items-center justify-end gap-2",
1011
+ children: [
1012
+ /* @__PURE__ */ z("span", {
1013
+ className: "mr-1",
1014
+ children: "Per Page:"
1015
+ }),
1016
+ /* @__PURE__ */ B(me, {
1017
+ value: String(C),
1018
+ onValueChange: (e) => {
1019
+ e && (ne(Number(e)), S(1));
1020
+ },
1021
+ children: [/* @__PURE__ */ z(ge, {
1022
+ className: "w-20",
1023
+ children: /* @__PURE__ */ z(he, {})
1024
+ }), /* @__PURE__ */ z(_e, { children: [
1025
+ 10,
1026
+ 25,
1027
+ 50
1028
+ ].map((e) => /* @__PURE__ */ z(q, {
1029
+ value: String(e),
1030
+ children: e
1031
+ }, e)) })]
1032
+ }),
1033
+ /* @__PURE__ */ z(G, {
1034
+ variant: "ghost",
1035
+ size: "icon",
1036
+ "aria-label": "Previous page",
1037
+ disabled: x <= 1,
1038
+ onClick: () => S((e) => Math.max(1, e - 1)),
1039
+ children: /* @__PURE__ */ z(te, { size: 16 })
1040
+ }),
1041
+ /* @__PURE__ */ z(G, {
1042
+ variant: "ghost",
1043
+ size: "icon",
1044
+ "aria-label": "Next page",
1045
+ disabled: x >= Y,
1046
+ onClick: () => S((e) => Math.min(Y, e + 1)),
1047
+ children: /* @__PURE__ */ z(v, { size: 16 })
1048
+ })
1049
+ ]
1050
+ })]
1051
+ })]
1052
+ }),
1053
+ j && /* @__PURE__ */ z("div", {
1054
+ className: "fixed inset-0 z-50 flex items-center justify-center bg-black/45 p-4",
1055
+ onMouseDown: (e) => {
1056
+ e.target === e.currentTarget && (oe(void 0), M(null));
1057
+ },
1058
+ children: /* @__PURE__ */ B("section", {
1059
+ role: "alertdialog",
1060
+ "aria-modal": "true",
1061
+ "aria-labelledby": "delete-documents-title",
1062
+ "aria-describedby": "delete-documents-description",
1063
+ className: "w-full max-w-md rounded-none border bg-background p-6 shadow-xl",
1064
+ children: [
1065
+ /* @__PURE__ */ B("h2", {
1066
+ id: "delete-documents-title",
1067
+ className: "font-heading text-lg font-semibold uppercase tracking-wide",
1068
+ children: [
1069
+ "Delete ",
1070
+ j.length === 1 ? "document" : "documents",
1071
+ "?"
1072
+ ]
1073
+ }),
1074
+ /* @__PURE__ */ B("p", {
1075
+ id: "delete-documents-description",
1076
+ className: "mt-2 text-sm text-muted-foreground",
1077
+ children: [j.length === 1 ? /* @__PURE__ */ B(le, { children: [
1078
+ "Delete “",
1079
+ Re,
1080
+ "”?"
1081
+ ] }) : `Delete ${j.length} selected documents?`, " This action cannot be undone."]
1082
+ }),
1083
+ ie && /* @__PURE__ */ z("p", {
1084
+ className: "mt-3 text-sm text-destructive",
1085
+ role: "alert",
1086
+ children: ie
1087
+ }),
1088
+ /* @__PURE__ */ B("div", {
1089
+ className: "mt-6 flex justify-end gap-2",
1090
+ children: [/* @__PURE__ */ z(G, {
1091
+ variant: "outline",
1092
+ autoFocus: !0,
1093
+ onClick: () => {
1094
+ oe(void 0), M(null);
1095
+ },
1096
+ children: "Cancel"
1097
+ }), /* @__PURE__ */ B(G, {
1098
+ variant: "destructive",
1099
+ onClick: () => {},
1100
+ children: [
1101
+ /* @__PURE__ */ z(D, { size: 15 }),
1102
+ " Delete ",
1103
+ j.length === 1 ? "document" : "documents"
1104
+ ]
1105
+ })]
1106
+ })
1107
+ ]
1108
+ })
1109
+ })
1110
+ ] });
1111
+ }
1112
+ function it({ app: e, client: t, manifest: n, createDefaults: r, relationOptions: i }) {
1113
+ let { collectionSlug: a = "", id: o } = se(), [s] = P(), c = n.collections[a];
1114
+ if (!c) return /* @__PURE__ */ z(pt, {});
1115
+ let l = at(n, a, s);
1116
+ return /* @__PURE__ */ z(ot, {
1117
+ app: e,
1118
+ client: t,
1119
+ manifest: n,
1120
+ collection: c,
1121
+ id: o,
1122
+ createDefaults: r?.[a],
1123
+ joinContext: l,
1124
+ relationOptions: i
1125
+ }, `${a}:${o ?? "new"}:${s.toString()}`);
1126
+ }
1127
+ function at(e, t, n) {
1128
+ let r = n.get("bebopParent"), [i, a, ...o] = (n.get("bebopJoin") ?? "").split(".");
1129
+ if (!r || !i || !a || o.length) return;
1130
+ let s = e.collections[i], c = e.collections[t], l = s?.fields.find((e) => e.kind === "join" && e.name === a);
1131
+ if (!s || !c || !l || l.collection !== t) return;
1132
+ let u = c.fields.find((e) => e.kind === "relation" && e.name === l.on && e.relationTo === i);
1133
+ if (u) return {
1134
+ sourceSlug: i,
1135
+ parentId: r,
1136
+ relationship: u,
1137
+ returnTo: `/admin/collections/${i}/${encodeURIComponent(r)}`
1138
+ };
1139
+ }
1140
+ function ot({ app: e, client: t, manifest: n, collection: a, id: s, createDefaults: u, joinContext: f, relationOptions: ee }) {
1141
+ let p = ae(), m = Le(), { setDocumentBreadcrumb: h } = oe(), g = c(), _ = He(e, a.slug), te = s ? Ue(t, a.slug)?.query({
1142
+ where: { id: s },
1143
+ includeTimestamps: !0
1144
+ }) : void 0, { data: v, isLoading: y, error: b } = l(te), x = i(() => ({
1145
+ ...u,
1146
+ ...f && !s ? { [f.relationship.name]: f.parentId } : {}
1147
+ }), [
1148
+ u,
1149
+ s,
1150
+ f
1151
+ ]), S = d({ defaultValues: s ? {} : ct(a, void 0, x) }), { register: C, handleSubmit: ne, reset: w, setValue: T, formState: { errors: re, isSubmitting: E, isDirty: D, dirtyFields: O } } = S, [k, A] = o("unknown"), [j, M] = o("unknown"), [ie, se] = o(), [N, P] = o(!1), ce = f && (!s || v?.[f.relationship.storageName] === f.parentId) ? f.returnTo : void 0, F = S.watch(), I = i(() => ut(a, F), [a, F]), L = JSON.stringify(I), R = a.useAsTitle ? Q(a, a.useAsTitle) : void 0, ue = R ? Object.hasOwn(F, R.name) ? F[R.name] : v ? Z(R, v) : void 0 : void 0, V = ue != null && String(ue).trim() ? String(ue) : s ? `Untitled ${a.labels.singular.toLocaleLowerCase()}` : `New ${a.labels.singular}`, H = R && v ? Z(R, v) : void 0, de = H != null && String(H).trim() ? String(H) : s ?? "", U = a.fields.filter((e) => e.kind !== "join" && e.admin?.position !== "sidebar"), W = a.fields.filter((e) => e.kind !== "join" && e.admin?.position === "sidebar"), fe = a.fields.filter((e) => e.kind === "join");
1152
+ if (r(() => {
1153
+ h(s ? V : void 0);
1154
+ }, [
1155
+ s,
1156
+ h,
1157
+ V
1158
+ ]), r(() => {
1159
+ v && w(ct(a, v));
1160
+ }, [
1161
+ a,
1162
+ v,
1163
+ w
1164
+ ]), r(() => {
1165
+ if (s || !x) return;
1166
+ let e = ct(a, void 0, x);
1167
+ for (let t of $(a)) Object.hasOwn(x, t.name) && !O[t.name] && T(t.name, e[t.name], { shouldDirty: !1 });
1168
+ }, [
1169
+ a,
1170
+ x,
1171
+ O,
1172
+ s,
1173
+ T
1174
+ ]), r(() => {
1175
+ let e = !0;
1176
+ if (!s || !_) {
1177
+ M("unknown");
1178
+ return;
1179
+ }
1180
+ if (!v) {
1181
+ M("unknown");
1182
+ return;
1183
+ }
1184
+ return M("unknown"), g.canRead(_, s).then((t) => {
1185
+ e && M(t);
1186
+ }).catch(() => {
1187
+ e && M("unknown");
1188
+ }), () => {
1189
+ e = !1;
1190
+ };
1191
+ }, [
1192
+ g,
1193
+ v,
1194
+ s,
1195
+ _
1196
+ ]), r(() => {
1197
+ let e = !0;
1198
+ if (!_ || s && !v) {
1199
+ A("unknown");
1200
+ return;
1201
+ }
1202
+ return A("unknown"), (s ? g.canUpdate(_, s, I) : g.canInsert(_, I)).then((t) => {
1203
+ e && A(t);
1204
+ }).catch(() => {
1205
+ e && A("unknown");
1206
+ }), () => {
1207
+ e = !1;
1208
+ };
1209
+ }, [
1210
+ g,
1211
+ v,
1212
+ s,
1213
+ L,
1214
+ _
1215
+ ]), b) return /* @__PURE__ */ B("div", {
1216
+ className: "py-16 text-center text-sm text-destructive",
1217
+ children: ["Could not load document: ", b.message]
1218
+ });
1219
+ if (s && y) return /* @__PURE__ */ z("div", {
1220
+ className: "py-16 text-center text-sm text-muted-foreground",
1221
+ children: "Loading document…"
1222
+ });
1223
+ if (s && !v) return /* @__PURE__ */ z(pt, { message: "This document may have been deleted or is no longer available." });
1224
+ if (s && j === "denied") return /* @__PURE__ */ z("div", {
1225
+ className: "py-16 text-center text-sm text-destructive",
1226
+ role: "alert",
1227
+ children: "Your current session cannot read this document."
1228
+ });
1229
+ async function K(e) {
1230
+ let n = ut(a, e);
1231
+ se(void 0);
1232
+ try {
1233
+ if (!_) throw Error("The generated Bebop app is missing this collection.");
1234
+ let e = s ? await g.canUpdate(_, s, n) : await g.canInsert(_, n);
1235
+ if (A(e), e === "denied") throw Error("Your current session cannot save this document.");
1236
+ let r = Ue(t, a.slug);
1237
+ if (!r) throw Error("The Bebop mutation client is missing this collection.");
1238
+ let i = (s ? await r.update(s, n) : await r.create(n))?.doc;
1239
+ m.add({
1240
+ type: "success",
1241
+ title: `${a.labels.singular} ${s ? "updated" : "created"} locally`,
1242
+ description: "Jazz sync may still be pending."
1243
+ }), ce && f && i?.[f.relationship.storageName] === f.parentId ? p(ce) : !s && fe.length > 0 && i?.id ? p(`/admin/collections/${a.slug}/${encodeURIComponent(i.id)}`) : p(`/admin/collections/${a.slug}`);
1244
+ } catch (e) {
1245
+ let t = e instanceof Error && "localWriteApplied" in e;
1246
+ P(t), se(t ? `${e.message} The local change was applied and may still sync.` : e instanceof Error ? e.message : "The document could not be saved."), m.add({
1247
+ type: t ? "warning" : "error",
1248
+ title: t ? "Local change needs attention" : "Could not save document",
1249
+ description: e instanceof Error ? e.message : "The document could not be saved."
1250
+ });
1251
+ }
1252
+ }
1253
+ function me(r) {
1254
+ return /* @__PURE__ */ B("div", {
1255
+ className: "admin-editor-field",
1256
+ children: [r.kind === "boolean" ? /* @__PURE__ */ B("label", {
1257
+ className: "admin-editor-checkbox-label",
1258
+ children: [
1259
+ /* @__PURE__ */ z("input", {
1260
+ type: "checkbox",
1261
+ className: "size-4 accent-primary",
1262
+ ...C(r.name, { required: r.required })
1263
+ }),
1264
+ /* @__PURE__ */ z("span", { children: r.label }),
1265
+ r.required && /* @__PURE__ */ z("span", {
1266
+ className: "text-destructive",
1267
+ children: "*"
1268
+ })
1269
+ ]
1270
+ }) : /* @__PURE__ */ B(le, { children: [/* @__PURE__ */ B(pe, {
1271
+ htmlFor: `field-${r.name}`,
1272
+ className: "text-[13px] font-normal normal-case tracking-normal",
1273
+ children: [r.label, r.required && /* @__PURE__ */ z("span", {
1274
+ className: "text-destructive",
1275
+ children: "*"
1276
+ })]
1277
+ }), /* @__PURE__ */ z(dt, {
1278
+ field: r,
1279
+ app: e,
1280
+ client: t,
1281
+ manifest: n,
1282
+ register: C,
1283
+ control: S.control,
1284
+ relationOptions: ee
1285
+ })] }), re[r.name] && /* @__PURE__ */ z("p", {
1286
+ className: "text-xs text-destructive",
1287
+ role: "alert",
1288
+ children: String(re[r.name]?.message ?? "Invalid value")
1289
+ })]
1290
+ }, r.name);
1291
+ }
1292
+ return /* @__PURE__ */ B("div", {
1293
+ className: "admin-editor",
1294
+ children: [
1295
+ /* @__PURE__ */ z("div", {
1296
+ className: "admin-editor-heading",
1297
+ children: /* @__PURE__ */ z("h1", {
1298
+ className: "truncate",
1299
+ title: V,
1300
+ children: V
1301
+ })
1302
+ }),
1303
+ /* @__PURE__ */ B("form", {
1304
+ onSubmit: ne(K),
1305
+ children: [
1306
+ /* @__PURE__ */ B("div", {
1307
+ className: "admin-editor-meta",
1308
+ children: [/* @__PURE__ */ z("div", {
1309
+ className: "admin-editor-dates",
1310
+ children: s && a.timestamps ? /* @__PURE__ */ B(le, { children: [/* @__PURE__ */ B("span", { children: [/* @__PURE__ */ z("span", {
1311
+ className: "text-muted-foreground",
1312
+ children: "Last Modified: "
1313
+ }), We(v?.$updatedAt, !0)] }), /* @__PURE__ */ B("span", { children: [/* @__PURE__ */ z("span", {
1314
+ className: "text-muted-foreground",
1315
+ children: "Created: "
1316
+ }), We(v?.$createdAt, !0)] })] }) : /* @__PURE__ */ z("span", {
1317
+ className: "text-muted-foreground",
1318
+ children: "New document"
1319
+ })
1320
+ }), /* @__PURE__ */ B("div", {
1321
+ className: "admin-editor-actions",
1322
+ children: [/* @__PURE__ */ z(G, {
1323
+ variant: "secondary",
1324
+ size: "sm",
1325
+ type: "submit",
1326
+ className: "normal-case tracking-normal",
1327
+ disabled: E || N || k === "denied" || !(!s || D),
1328
+ children: N ? "Local write applied" : s ? "Save" : "Create"
1329
+ }), /* @__PURE__ */ z(G, {
1330
+ variant: "outline",
1331
+ size: "sm",
1332
+ type: "button",
1333
+ className: "normal-case tracking-normal",
1334
+ onClick: () => p(ce ?? `/admin/collections/${a.slug}`),
1335
+ children: "Cancel"
1336
+ })]
1337
+ })]
1338
+ }),
1339
+ k === "denied" && /* @__PURE__ */ z("p", {
1340
+ className: "admin-editor-message text-destructive",
1341
+ role: "status",
1342
+ children: s ? "Your current session cannot update this document." : "Your current session cannot create this document."
1343
+ }),
1344
+ ie && /* @__PURE__ */ z("p", {
1345
+ className: "admin-editor-message text-destructive",
1346
+ role: "alert",
1347
+ children: ie
1348
+ }),
1349
+ N && !ie && /* @__PURE__ */ z("p", {
1350
+ className: "admin-editor-message text-muted-foreground",
1351
+ role: "status",
1352
+ children: "The local change was applied. Jazz may still be syncing it."
1353
+ }),
1354
+ /* @__PURE__ */ B("fieldset", {
1355
+ disabled: !!(N || s && k === "denied"),
1356
+ className: `admin-editor-grid ${W.length ? "" : "admin-editor-grid-single"}`,
1357
+ children: [/* @__PURE__ */ z("div", {
1358
+ className: "admin-editor-main",
1359
+ children: U.map(me)
1360
+ }), W.length > 0 && /* @__PURE__ */ B("aside", {
1361
+ className: "admin-editor-side",
1362
+ "aria-label": "Additional fields",
1363
+ children: [W.map(me), s && /* @__PURE__ */ B("div", {
1364
+ className: "admin-editor-document-id",
1365
+ children: [/* @__PURE__ */ z("span", { children: "Document ID" }), /* @__PURE__ */ z("code", { children: s })]
1366
+ })]
1367
+ })]
1368
+ })
1369
+ ]
1370
+ }),
1371
+ fe.map((r) => s && v ? /* @__PURE__ */ z(st, {
1372
+ app: e,
1373
+ client: t,
1374
+ manifest: n,
1375
+ source: a,
1376
+ field: r,
1377
+ parentId: s,
1378
+ parentLabel: de,
1379
+ relationOptions: ee
1380
+ }, r.name) : /* @__PURE__ */ B("section", {
1381
+ className: "mt-8 border-t pt-6",
1382
+ children: [/* @__PURE__ */ z("h2", {
1383
+ className: "font-heading text-base font-semibold uppercase tracking-wide",
1384
+ children: r.label
1385
+ }), /* @__PURE__ */ B("p", {
1386
+ className: "mt-2 text-sm text-muted-foreground",
1387
+ children: [
1388
+ "Save this ",
1389
+ a.labels.singular.toLocaleLowerCase(),
1390
+ " before managing ",
1391
+ n.collections[r.collection]?.labels.plural.toLocaleLowerCase() ?? r.label.toLocaleLowerCase(),
1392
+ "."
1393
+ ]
1394
+ })]
1395
+ }, r.name))
1396
+ ]
1397
+ });
1398
+ }
1399
+ function st({ app: e, client: t, manifest: n, source: a, field: s, parentId: l, parentLabel: u, relationOptions: d }) {
1400
+ let ee = ae(), h = c(), _ = n.collections[s.collection], y = _?.fields.find((e) => e.kind === "relation" && e.name === s.on && e.relationTo === a.slug), b = He(e, s.collection), x = _ ? $(_) : [], S = i(() => {
1401
+ let e = _ ? $(_) : [], t = (s.admin?.defaultColumns ?? _?.defaultColumns)?.filter((t) => e.some((e) => e.name === t));
1402
+ return t?.length ? t : e.slice(0, 4).map((e) => e.name);
1403
+ }, [s.admin?.defaultColumns, _]), [C, ne] = o(S), [w, T] = o({
1404
+ field: S[0] ?? "id",
1405
+ direction: "asc"
1406
+ }), [E, D] = o(1), [O, k] = o(Be), [j, M] = o("unknown"), ie = i(() => y ? { [y.storageName]: l } : {}, [l, y]), oe = _ ? Q(_, w.field) : void 0, se = oe && oe.kind !== "join" ? oe.storageName : "id", { rows: N, ids: P } = Xe(t, s.collection, {
1407
+ where: ie,
1408
+ sort: {
1409
+ field: se,
1410
+ direction: w.direction
1411
+ },
1412
+ page: E,
1413
+ pageSize: O,
1414
+ searchActive: !1,
1415
+ enabled: !!(_ && y && b)
1416
+ }), { data: ce, isLoading: F, error: I } = N, L = ce ?? [], R = Qe(h, b, L), le = L.filter((e) => R[e.id] !== "denied"), ue = x.map((e) => e.name), V = ue.filter((e) => C.includes(e)), H = _?.useAsTitle ? Q(_, _.useAsTitle) : void 0, de = H && H.kind !== "join" && V.includes(H.name) ? H.name : V[0], U = P.data?.length ?? 0, W = Math.max(1, Math.ceil(U / O)), fe = le, pe = L.some((e) => R[e.id] === "denied"), K = s.admin?.allowCreate !== !1;
1417
+ r(() => {
1418
+ ne(S), T({
1419
+ field: S[0] ?? "id",
1420
+ direction: "asc"
1421
+ }), D(1);
1422
+ }, [S]), r(() => {
1423
+ P.data && D((e) => Math.min(e, W));
1424
+ }, [P.data, W]), r(() => {
1425
+ let e = !0;
1426
+ if (!K || !b || !y) {
1427
+ M("denied");
1428
+ return;
1429
+ }
1430
+ return M("unknown"), h.canInsert(b, { [y.storageName]: l }).then((t) => {
1431
+ e && M(t);
1432
+ }).catch(() => {
1433
+ e && M("unknown");
1434
+ }), () => {
1435
+ e = !1;
1436
+ };
1437
+ }, [
1438
+ K,
1439
+ h,
1440
+ l,
1441
+ y,
1442
+ b
1443
+ ]);
1444
+ let ve = new URLSearchParams({
1445
+ bebopJoin: `${a.slug}.${s.name}`,
1446
+ bebopParent: l
1447
+ }).toString(), J = _;
1448
+ return /* @__PURE__ */ B("section", {
1449
+ className: "mt-8 border-t pt-6",
1450
+ children: [
1451
+ /* @__PURE__ */ B("div", {
1452
+ className: "mb-4 flex flex-wrap items-center justify-between gap-3",
1453
+ children: [/* @__PURE__ */ z("h2", {
1454
+ className: "text-base font-medium",
1455
+ children: s.label
1456
+ }), /* @__PURE__ */ B("div", {
1457
+ className: "flex items-center gap-2",
1458
+ children: [K && /* @__PURE__ */ B(G, {
1459
+ variant: "secondary",
1460
+ size: "sm",
1461
+ disabled: j === "denied",
1462
+ onClick: () => ee(`/admin/collections/${s.collection}/create?${ve}`),
1463
+ children: [/* @__PURE__ */ z(re, { size: 15 }), " Add New"]
1464
+ }), /* @__PURE__ */ B("details", {
1465
+ className: "admin-table-menu",
1466
+ children: [/* @__PURE__ */ B("summary", {
1467
+ className: "admin-table-menu-trigger",
1468
+ children: ["Columns ", /* @__PURE__ */ z(g, { size: 15 })]
1469
+ }), /* @__PURE__ */ B("div", {
1470
+ className: "admin-table-menu-content",
1471
+ children: [/* @__PURE__ */ z("p", {
1472
+ className: "admin-table-menu-label",
1473
+ children: "Visible columns"
1474
+ }), ue.map((e) => {
1475
+ let t = Q(J, e), n = C.includes(e);
1476
+ return /* @__PURE__ */ B("label", {
1477
+ className: "admin-menu-checkbox",
1478
+ children: [/* @__PURE__ */ z("input", {
1479
+ type: "checkbox",
1480
+ checked: n,
1481
+ disabled: n && C.length === 1,
1482
+ onChange: () => ne((t) => n ? t.filter((t) => t !== e) : [...t, e])
1483
+ }), /* @__PURE__ */ z("span", { children: t?.label ?? Ye(e) })]
1484
+ }, e);
1485
+ })]
1486
+ })]
1487
+ })]
1488
+ })]
1489
+ }),
1490
+ K && j === "denied" && /* @__PURE__ */ z("p", {
1491
+ className: "mb-3 text-sm text-muted-foreground",
1492
+ role: "status",
1493
+ children: "Your current session cannot add records to this list."
1494
+ }),
1495
+ I ? /* @__PURE__ */ B("div", {
1496
+ className: "py-10 text-center text-sm text-destructive",
1497
+ children: ["Could not load related documents: ", I.message]
1498
+ }) : F || P.isLoading ? /* @__PURE__ */ B("div", {
1499
+ className: "py-10 text-center text-sm text-muted-foreground",
1500
+ children: [
1501
+ "Loading ",
1502
+ J?.labels.plural.toLocaleLowerCase() ?? "records",
1503
+ "…"
1504
+ ]
1505
+ }) : !J || !y ? /* @__PURE__ */ z("div", {
1506
+ className: "py-10 text-center text-sm text-destructive",
1507
+ children: "The generated join relation is missing or invalid."
1508
+ }) : U === 0 ? /* @__PURE__ */ B("div", {
1509
+ className: "py-10 text-center",
1510
+ children: [/* @__PURE__ */ z("p", {
1511
+ className: "text-sm font-medium",
1512
+ children: L.length ? "No matching documents" : `No ${J.labels.plural.toLocaleLowerCase()} yet`
1513
+ }), /* @__PURE__ */ z("p", {
1514
+ className: "mt-1 text-sm text-muted-foreground",
1515
+ children: L.length ? "Try another search." : `Records related to this ${a.labels.singular.toLocaleLowerCase()} will appear here.`
1516
+ })]
1517
+ }) : /* @__PURE__ */ B("div", {
1518
+ className: "admin-join-table-surface",
1519
+ children: [/* @__PURE__ */ z("div", {
1520
+ className: "admin-table-section",
1521
+ children: /* @__PURE__ */ B(ye, { children: [/* @__PURE__ */ z(be, { children: /* @__PURE__ */ B(Se, { children: [V.map((e) => {
1522
+ let t = Q(J, e), n = w.field === e ? w.direction === "asc" ? p : f : m;
1523
+ return /* @__PURE__ */ z(Ce, {
1524
+ className: "h-10 text-[13px] font-normal normal-case tracking-normal",
1525
+ children: /* @__PURE__ */ B("button", {
1526
+ className: "admin-sort-button",
1527
+ onClick: () => T((t) => ({
1528
+ field: e,
1529
+ direction: t.field === e && t.direction === "asc" ? "desc" : "asc"
1530
+ })),
1531
+ children: [t?.label ?? Ye(e), /* @__PURE__ */ z(n, { size: 13 })]
1532
+ })
1533
+ }, e);
1534
+ }), J.timestamps && /* @__PURE__ */ z(Ce, {
1535
+ className: "h-10 text-[13px] font-normal normal-case tracking-normal",
1536
+ children: "Updated"
1537
+ })] }) }), /* @__PURE__ */ z(xe, { children: fe.length === 0 ? /* @__PURE__ */ z(Se, { children: /* @__PURE__ */ z(we, {
1538
+ colSpan: V.length + +!!J.timestamps,
1539
+ className: "py-8 text-center text-sm text-muted-foreground",
1540
+ children: pe ? "No readable documents on this page." : "No documents on this page."
1541
+ }) }) : fe.map((e) => /* @__PURE__ */ B(Se, {
1542
+ className: "hover:bg-muted",
1543
+ children: [V.map((t) => {
1544
+ let n = Q(J, t), r = n ? Z(n, e) : e[t], i = n?.kind === "relation" && n.name === s.on && r === l ? u : Je(n, r, d);
1545
+ return /* @__PURE__ */ z(we, {
1546
+ className: "admin-table-cell",
1547
+ children: t === de ? /* @__PURE__ */ z(A, {
1548
+ to: `/admin/collections/${s.collection}/${encodeURIComponent(e.id)}?${ve}`,
1549
+ className: "underline underline-offset-2 hover:text-primary",
1550
+ children: i
1551
+ }) : i
1552
+ }, t);
1553
+ }), J.timestamps && /* @__PURE__ */ z(we, {
1554
+ className: "whitespace-nowrap text-xs text-muted-foreground",
1555
+ children: We(e.$updatedAt, !0)
1556
+ })]
1557
+ }, e.id)) })] })
1558
+ }), /* @__PURE__ */ B("div", {
1559
+ className: "admin-table-pagination admin-join-table-pagination",
1560
+ children: [/* @__PURE__ */ B("span", {
1561
+ className: "shrink-0 whitespace-nowrap",
1562
+ children: [
1563
+ U ? (Math.min(E, W) - 1) * O + 1 : 0,
1564
+ "–",
1565
+ Math.min(E * O, U),
1566
+ " of ",
1567
+ U
1568
+ ]
1569
+ }), /* @__PURE__ */ B("div", {
1570
+ className: "flex shrink-0 flex-nowrap items-center justify-end gap-2",
1571
+ children: [
1572
+ /* @__PURE__ */ z("span", {
1573
+ className: "mr-1 shrink-0 whitespace-nowrap",
1574
+ children: "Per Page:"
1575
+ }),
1576
+ /* @__PURE__ */ B(me, {
1577
+ value: String(O),
1578
+ onValueChange: (e) => {
1579
+ e && (k(Number(e)), D(1));
1580
+ },
1581
+ children: [/* @__PURE__ */ z(ge, {
1582
+ className: "w-20 shrink-0",
1583
+ children: /* @__PURE__ */ z(he, {})
1584
+ }), /* @__PURE__ */ z(_e, { children: [
1585
+ 10,
1586
+ 25,
1587
+ 50
1588
+ ].map((e) => /* @__PURE__ */ z(q, {
1589
+ value: String(e),
1590
+ children: e
1591
+ }, e)) })]
1592
+ }),
1593
+ /* @__PURE__ */ z(G, {
1594
+ className: "shrink-0",
1595
+ variant: "ghost",
1596
+ size: "icon",
1597
+ "aria-label": "Previous page",
1598
+ disabled: E <= 1,
1599
+ onClick: () => D((e) => Math.max(1, e - 1)),
1600
+ children: /* @__PURE__ */ z(te, { size: 16 })
1601
+ }),
1602
+ /* @__PURE__ */ z(G, {
1603
+ className: "shrink-0",
1604
+ variant: "ghost",
1605
+ size: "icon",
1606
+ "aria-label": "Next page",
1607
+ disabled: E >= W,
1608
+ onClick: () => D((e) => Math.min(W, e + 1)),
1609
+ children: /* @__PURE__ */ z(v, { size: 16 })
1610
+ })
1611
+ ]
1612
+ })]
1613
+ })]
1614
+ })
1615
+ ]
1616
+ });
1617
+ }
1618
+ function ct(e, t, n) {
1619
+ return Object.fromEntries($(e).map((e) => {
1620
+ let r = t ? Z(e, t) : n?.[e.name];
1621
+ return e.kind === "boolean" ? [e.name, !!r] : e.kind === "date" ? [e.name, r instanceof Date ? lt(r, e.admin?.date?.pickerAppearance === "dayAndTime") : ""] : e.kind === "json" ? [e.name, r == null ? "" : JSON.stringify(r, null, 2)] : [e.name, r == null ? "" : String(r)];
1622
+ }));
1623
+ }
1624
+ function lt(e, t = !1) {
1625
+ let n = e.getFullYear(), r = String(e.getMonth() + 1).padStart(2, "0"), i = String(e.getDate()).padStart(2, "0");
1626
+ return t ? `${n}-${r}-${i}T${String(e.getHours()).padStart(2, "0")}:${String(e.getMinutes()).padStart(2, "0")}` : `${n}-${r}-${i}`;
1627
+ }
1628
+ function ut(e, t) {
1629
+ return Object.fromEntries($(e).flatMap((e) => {
1630
+ let n = t[e.name];
1631
+ return e.kind === "boolean" ? [[e.storageName, !!n]] : n === "" || n == null ? e.required ? [] : [[e.storageName, null]] : e.kind === "number" || e.kind === "integer" ? [[e.storageName, Number(n)]] : e.kind === "date" ? [[e.storageName, new Date(e.admin?.date?.pickerAppearance === "dayAndTime" ? String(n) : `${String(n)}T00:00:00`)]] : e.kind === "json" ? [[e.storageName, JSON.parse(String(n))]] : [[e.storageName, n]];
1632
+ }));
1633
+ }
1634
+ function dt({ field: e, app: t, client: n, manifest: r, register: i, control: a, relationOptions: o }) {
1635
+ let s = {
1636
+ required: e.required ? `${e.label} is required.` : !1,
1637
+ validate: (t) => {
1638
+ if (typeof t == "string" && t.trim() === "") return !e.required || `${e.label} is required.`;
1639
+ if (e.kind === "relation" && t && o?.[e.relationTo ?? ""] && !o[e.relationTo ?? ""].some((e) => e.id === t)) return `Select a valid ${e.label.toLocaleLowerCase()}.`;
1640
+ if (e.kind === "json" && t) try {
1641
+ JSON.parse(String(t));
1642
+ } catch {
1643
+ return "Enter valid JSON.";
1644
+ }
1645
+ return e.kind === "integer" && t !== "" && !Number.isInteger(Number(t)) ? "Enter a whole number." : !0;
1646
+ }
1647
+ };
1648
+ if (e.kind === "relation" && e.relationTo) return /* @__PURE__ */ z(u, {
1649
+ control: a,
1650
+ name: e.name,
1651
+ rules: s,
1652
+ render: ({ field: i }) => /* @__PURE__ */ z(ft, {
1653
+ field: e,
1654
+ app: t,
1655
+ client: n,
1656
+ manifest: r,
1657
+ value: typeof i.value == "string" && i.value ? i.value : null,
1658
+ onChange: i.onChange,
1659
+ onBlur: i.onBlur,
1660
+ inputRef: i.ref,
1661
+ options: o?.[e.relationTo ?? ""]
1662
+ })
1663
+ });
1664
+ if (e.kind === "select") return /* @__PURE__ */ z(u, {
1665
+ control: a,
1666
+ name: e.name,
1667
+ rules: s,
1668
+ render: ({ field: t }) => /* @__PURE__ */ B(me, {
1669
+ value: typeof t.value == "string" && t.value ? t.value : null,
1670
+ onValueChange: t.onChange,
1671
+ children: [/* @__PURE__ */ z(ge, {
1672
+ id: `field-${e.name}`,
1673
+ ref: t.ref,
1674
+ onBlur: t.onBlur,
1675
+ className: "w-full",
1676
+ children: /* @__PURE__ */ z(he, { placeholder: `Select ${e.label.toLocaleLowerCase()}` })
1677
+ }), /* @__PURE__ */ z(_e, { children: e.options?.map((t) => /* @__PURE__ */ z(q, {
1678
+ value: t,
1679
+ children: qe(e, t)
1680
+ }, t)) })]
1681
+ })
1682
+ });
1683
+ let c = i(e.name, s);
1684
+ if (e.kind === "json") return /* @__PURE__ */ z(Te, {
1685
+ id: `field-${e.name}`,
1686
+ rows: 7,
1687
+ className: "font-mono text-xs",
1688
+ placeholder: "{}",
1689
+ ...c
1690
+ });
1691
+ if (e.kind === "text" && e.admin?.input === "textarea") return /* @__PURE__ */ z(Te, {
1692
+ id: `field-${e.name}`,
1693
+ rows: 7,
1694
+ ...c
1695
+ });
1696
+ let l = e.kind === "date" ? e.admin?.date?.pickerAppearance === "dayAndTime" ? "datetime-local" : "date" : e.kind === "number" || e.kind === "integer" ? "number" : "text";
1697
+ return /* @__PURE__ */ z(fe, {
1698
+ id: `field-${e.name}`,
1699
+ type: l,
1700
+ step: e.kind === "integer" ? 1 : e.kind === "number" ? "any" : void 0,
1701
+ ...c
1702
+ });
1703
+ }
1704
+ function ft({ field: e, app: t, client: n, manifest: r, value: i, onChange: a, onBlur: o, inputRef: l, options: u }) {
1705
+ let d = e.relationTo ?? "", f = u ? void 0 : He(t, d), ee = u ? void 0 : Ue(n, d)?.query(), { data: p, isLoading: m } = s(ee), h = Qe(c(), f, p ?? []), g = (p ?? []).filter((e) => h[e.id] !== "denied"), _ = r.collections[d], te = _?.useAsTitle ? _.fields.find((e) => e.name === _.useAsTitle) : void 0, v = u ?? g.map((e) => ({
1706
+ id: e.id,
1707
+ name: String(te ? Z(te, e) ?? e.id : e.id)
1708
+ }));
1709
+ return /* @__PURE__ */ B(me, {
1710
+ value: i,
1711
+ onValueChange: a,
1712
+ children: [/* @__PURE__ */ z(ge, {
1713
+ id: `field-${e.name}`,
1714
+ ref: l,
1715
+ onBlur: o,
1716
+ className: "w-full",
1717
+ children: /* @__PURE__ */ z(he, {
1718
+ placeholder: m ? "Loading related records…" : `Select ${e.label.toLocaleLowerCase()}`,
1719
+ children: (t) => t ? v.find((e) => e.id === t)?.name ?? t : m ? "Loading related records…" : `Select ${e.label.toLocaleLowerCase()}`
1720
+ })
1721
+ }), /* @__PURE__ */ z(_e, { children: v.map((e) => /* @__PURE__ */ z(q, {
1722
+ value: e.id,
1723
+ children: e.name
1724
+ }, e.id)) })]
1725
+ });
1726
+ }
1727
+ function pt({ message: e = "We couldn’t find the page you’re looking for." }) {
1728
+ return /* @__PURE__ */ B("div", {
1729
+ className: "flex min-h-72 flex-col items-center justify-center text-center",
1730
+ children: [
1731
+ /* @__PURE__ */ z("p", {
1732
+ className: "text-sm font-medium",
1733
+ children: "Page not found"
1734
+ }),
1735
+ /* @__PURE__ */ z("p", {
1736
+ className: "mt-1 text-sm text-muted-foreground",
1737
+ children: e
1738
+ }),
1739
+ /* @__PURE__ */ z(G, {
1740
+ render: /* @__PURE__ */ z(A, { to: "/admin" }),
1741
+ variant: "outline",
1742
+ className: "mt-5",
1743
+ children: "Back to overview"
1744
+ })
1745
+ ]
1746
+ });
1747
+ }
1748
+ //#endregion
1749
+ export { $e as BebopAdmin };