@jgb-solutions/kit 0.2.2 → 0.3.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +129 -3
  3. package/dist/admin/blocks/ActivityFeed.d.ts +20 -0
  4. package/dist/admin/blocks/BarChart.d.ts +26 -0
  5. package/dist/admin/blocks/ChartPoints.d.ts +24 -0
  6. package/dist/admin/blocks/DataTable.d.ts +58 -0
  7. package/dist/admin/blocks/Filters.d.ts +12 -0
  8. package/dist/admin/blocks/Hero.d.ts +22 -0
  9. package/dist/admin/blocks/LineChart.d.ts +24 -0
  10. package/dist/admin/blocks/Pagination.d.ts +30 -0
  11. package/dist/admin/blocks/Segmented.d.ts +15 -0
  12. package/dist/admin/blocks/Stat.d.ts +35 -0
  13. package/dist/admin/blocks/Status.d.ts +22 -0
  14. package/dist/admin/blocks/Tile.d.ts +20 -0
  15. package/dist/admin/blocks/sorting.d.ts +29 -0
  16. package/dist/admin/contrast.d.ts +12 -0
  17. package/dist/admin/forms/ConfirmDialog.d.ts +25 -0
  18. package/dist/admin/forms/Field.d.ts +48 -0
  19. package/dist/admin/forms/People.d.ts +28 -0
  20. package/dist/admin/forms/Toast.d.ts +17 -0
  21. package/dist/admin/icons.d.ts +31 -0
  22. package/dist/admin/index.d.ts +33 -0
  23. package/dist/admin/shell/AdminShell.d.ts +31 -0
  24. package/dist/admin/shell/Dock.d.ts +8 -0
  25. package/dist/admin/shell/PageHeader.d.ts +19 -0
  26. package/dist/admin/shell/Sidebar.d.ts +27 -0
  27. package/dist/admin/shell/ThemeToggle.d.ts +10 -0
  28. package/dist/admin/shell/nav.d.ts +33 -0
  29. package/dist/admin/styles.css +1677 -0
  30. package/dist/admin/theme.d.ts +30 -0
  31. package/dist/admin/ui/Avatar.d.ts +14 -0
  32. package/dist/admin/ui/Button.d.ts +19 -0
  33. package/dist/admin.d.ts +2 -0
  34. package/dist/admin.js +2168 -0
  35. package/dist/auth/expo.d.ts +6 -0
  36. package/dist/auth/expo.js +7 -8
  37. package/dist/auth/rules.d.ts +6 -2
  38. package/dist/auth/rules.js +2 -2
  39. package/dist/auth.js +2 -2
  40. package/package.json +36 -7
package/dist/admin.js ADDED
@@ -0,0 +1,2168 @@
1
+ // src/admin/shell/AdminShell.tsx
2
+ import { useMemo as useMemo2 } from "react";
3
+
4
+ // src/admin/contrast.ts
5
+ function parseHex(color) {
6
+ const hex = color.trim().replace(/^#/, "");
7
+ const full = hex.length === 3 ? [...hex].map((c) => c + c).join("") : hex;
8
+ if (!/^[0-9a-f]{6}$/i.test(full))
9
+ return null;
10
+ return [0, 2, 4].map((at) => Number.parseInt(full.slice(at, at + 2), 16));
11
+ }
12
+ function luminance([r, g, b]) {
13
+ const channel = (value) => {
14
+ const c = value / 255;
15
+ return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
16
+ };
17
+ return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
18
+ }
19
+ function contrastRatio(a, b) {
20
+ const ca = parseHex(a);
21
+ const cb = parseHex(b);
22
+ if (!ca || !cb)
23
+ return null;
24
+ const [hi, lo] = [luminance(ca), luminance(cb)].sort((x, y) => y - x);
25
+ return (hi + 0.05) / (lo + 0.05);
26
+ }
27
+ function inkOn(brand, light = "#ffffff", dark = "#1c1930") {
28
+ const onLight = contrastRatio(brand, light);
29
+ const onDark = contrastRatio(brand, dark);
30
+ if (onLight === null || onDark === null)
31
+ return light;
32
+ return onLight >= 4.5 || onLight >= onDark ? light : dark;
33
+ }
34
+
35
+ // src/admin/forms/Toast.tsx
36
+ import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react";
37
+
38
+ // src/admin/icons.tsx
39
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
40
+ function icon(paths, extra = {}) {
41
+ return function Icon(props) {
42
+ return /* @__PURE__ */ jsx("svg", {
43
+ viewBox: "0 0 24 24",
44
+ fill: "none",
45
+ stroke: "currentColor",
46
+ strokeWidth: 1.9,
47
+ strokeLinecap: "round",
48
+ strokeLinejoin: "round",
49
+ "aria-hidden": "true",
50
+ focusable: "false",
51
+ ...extra,
52
+ ...props,
53
+ children: paths
54
+ });
55
+ };
56
+ }
57
+ var icons = {
58
+ home: icon(/* @__PURE__ */ jsxs(Fragment, {
59
+ children: [
60
+ /* @__PURE__ */ jsx("path", {
61
+ d: "M3 11.5 12 4l9 7.5"
62
+ }),
63
+ /* @__PURE__ */ jsx("path", {
64
+ d: "M5.5 10v9.5h13V10"
65
+ })
66
+ ]
67
+ })),
68
+ users: icon(/* @__PURE__ */ jsxs(Fragment, {
69
+ children: [
70
+ /* @__PURE__ */ jsx("circle", {
71
+ cx: "9",
72
+ cy: "8",
73
+ r: "3.5"
74
+ }),
75
+ /* @__PURE__ */ jsx("path", {
76
+ d: "M2.5 20c.8-3.6 3.4-5.5 6.5-5.5s5.7 1.9 6.5 5.5"
77
+ }),
78
+ /* @__PURE__ */ jsx("path", {
79
+ d: "M16 4.6a3.5 3.5 0 0 1 0 6.8M18 14.8c1.9.7 3.1 2.4 3.5 5.2"
80
+ })
81
+ ]
82
+ })),
83
+ box: icon(/* @__PURE__ */ jsxs(Fragment, {
84
+ children: [
85
+ /* @__PURE__ */ jsx("path", {
86
+ d: "m12 3 8.5 4.5v9L12 21l-8.5-4.5v-9z"
87
+ }),
88
+ /* @__PURE__ */ jsx("path", {
89
+ d: "m3.5 7.5 8.5 4.5 8.5-4.5M12 12v9"
90
+ })
91
+ ]
92
+ })),
93
+ chart: icon(/* @__PURE__ */ jsx("path", {
94
+ d: "M4 20h16M7 16v-5M12 16V7M17 16v-8"
95
+ })),
96
+ flag: icon(/* @__PURE__ */ jsx("path", {
97
+ d: "M5 21V4M5 4h11l-2 4 2 4H5"
98
+ })),
99
+ gear: icon(/* @__PURE__ */ jsxs(Fragment, {
100
+ children: [
101
+ /* @__PURE__ */ jsx("circle", {
102
+ cx: "12",
103
+ cy: "12",
104
+ r: "3"
105
+ }),
106
+ /* @__PURE__ */ jsx("path", {
107
+ d: "M12 2.5v3M12 18.5v3M2.5 12h3M18.5 12h3M5.3 5.3l2.1 2.1M16.6 16.6l2.1 2.1M5.3 18.7l2.1-2.1M16.6 7.4l2.1-2.1"
108
+ })
109
+ ]
110
+ })),
111
+ search: icon(/* @__PURE__ */ jsxs(Fragment, {
112
+ children: [
113
+ /* @__PURE__ */ jsx("circle", {
114
+ cx: "11",
115
+ cy: "11",
116
+ r: "6.5"
117
+ }),
118
+ /* @__PURE__ */ jsx("path", {
119
+ d: "m16 16 4.5 4.5"
120
+ })
121
+ ]
122
+ })),
123
+ bell: icon(/* @__PURE__ */ jsxs(Fragment, {
124
+ children: [
125
+ /* @__PURE__ */ jsx("path", {
126
+ d: "M6 16V11a6 6 0 1 1 12 0v5l1.5 2h-15z"
127
+ }),
128
+ /* @__PURE__ */ jsx("path", {
129
+ d: "M10 20.5a2 2 0 0 0 4 0"
130
+ })
131
+ ]
132
+ })),
133
+ screen: icon(/* @__PURE__ */ jsxs(Fragment, {
134
+ children: [
135
+ /* @__PURE__ */ jsx("rect", {
136
+ x: "3",
137
+ y: "4",
138
+ width: "18",
139
+ height: "12",
140
+ rx: "2"
141
+ }),
142
+ /* @__PURE__ */ jsx("path", {
143
+ d: "M8.5 20h7M12 16v4"
144
+ })
145
+ ]
146
+ })),
147
+ moon: icon(/* @__PURE__ */ jsx("path", {
148
+ d: "M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"
149
+ })),
150
+ sun: icon(/* @__PURE__ */ jsxs(Fragment, {
151
+ children: [
152
+ /* @__PURE__ */ jsx("circle", {
153
+ cx: "12",
154
+ cy: "12",
155
+ r: "4"
156
+ }),
157
+ /* @__PURE__ */ jsx("path", {
158
+ d: "M12 2.5v2M12 19.5v2M2.5 12h2M19.5 12h2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4"
159
+ })
160
+ ]
161
+ })),
162
+ sidebar: icon(/* @__PURE__ */ jsxs(Fragment, {
163
+ children: [
164
+ /* @__PURE__ */ jsx("rect", {
165
+ x: "3.5",
166
+ y: "4.5",
167
+ width: "17",
168
+ height: "15",
169
+ rx: "3"
170
+ }),
171
+ /* @__PURE__ */ jsx("path", {
172
+ d: "M9.5 4.5v15"
173
+ })
174
+ ]
175
+ })),
176
+ doc: icon(/* @__PURE__ */ jsxs(Fragment, {
177
+ children: [
178
+ /* @__PURE__ */ jsx("path", {
179
+ d: "M6 3.5h8l4 4v13H6z"
180
+ }),
181
+ /* @__PURE__ */ jsx("path", {
182
+ d: "M14 3.5v4h4"
183
+ })
184
+ ]
185
+ })),
186
+ plus: icon(/* @__PURE__ */ jsx("path", {
187
+ d: "M12 5v14M5 12h14"
188
+ }), { strokeWidth: 2 }),
189
+ check: icon(/* @__PURE__ */ jsx("path", {
190
+ d: "m5 12.5 4.5 4.5L19 7.5"
191
+ }), { strokeWidth: 2.2 }),
192
+ block: icon(/* @__PURE__ */ jsxs(Fragment, {
193
+ children: [
194
+ /* @__PURE__ */ jsx("circle", {
195
+ cx: "12",
196
+ cy: "12",
197
+ r: "8"
198
+ }),
199
+ /* @__PURE__ */ jsx("path", {
200
+ d: "m6.5 6.5 11 11"
201
+ })
202
+ ]
203
+ }), { strokeWidth: 2 }),
204
+ chevronDown: icon(/* @__PURE__ */ jsx("path", {
205
+ d: "m7 10 5 5 5-5"
206
+ }), { strokeWidth: 2 }),
207
+ chevronRight: icon(/* @__PURE__ */ jsx("path", {
208
+ d: "m10 7 5 5-5 5"
209
+ }), { strokeWidth: 2 }),
210
+ chevronLeft: icon(/* @__PURE__ */ jsx("path", {
211
+ d: "m14 7-5 5 5 5"
212
+ }), { strokeWidth: 2 }),
213
+ close: icon(/* @__PURE__ */ jsx("path", {
214
+ d: "M6 6l12 12M18 6 6 18"
215
+ }), { strokeWidth: 2 })
216
+ };
217
+
218
+ // src/admin/forms/Toast.tsx
219
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
220
+ var ToastContext = createContext(null);
221
+ function useToast() {
222
+ const api = useContext(ToastContext);
223
+ if (!api)
224
+ throw new Error("useToast must be used inside <AdminShell>.");
225
+ return api;
226
+ }
227
+ function ToastProvider({ children }) {
228
+ const [toasts, setToasts] = useState([]);
229
+ const next = useRef(1);
230
+ const dismiss = useCallback((id) => setToasts((all) => all.filter((t) => t.id !== id)), []);
231
+ const add = useCallback((message, tone) => {
232
+ const id = next.current++;
233
+ setToasts((all) => [...all.slice(-2), { id, message, tone }]);
234
+ }, []);
235
+ const api = useRef({ done: (m) => add(m, "done"), error: (m) => add(m, "error") });
236
+ return /* @__PURE__ */ jsxs2(ToastContext.Provider, {
237
+ value: api.current,
238
+ children: [
239
+ children,
240
+ /* @__PURE__ */ jsx2("div", {
241
+ className: "ja-toasts",
242
+ role: "status",
243
+ "aria-live": "polite",
244
+ children: toasts.map((toast) => /* @__PURE__ */ jsx2(ToastItem, {
245
+ toast,
246
+ onDismiss: () => dismiss(toast.id)
247
+ }, toast.id))
248
+ })
249
+ ]
250
+ });
251
+ }
252
+ function ToastItem({ toast, onDismiss }) {
253
+ useEffect(() => {
254
+ if (toast.tone !== "done")
255
+ return;
256
+ const timer = setTimeout(onDismiss, 4000);
257
+ return () => clearTimeout(timer);
258
+ }, [toast.tone, onDismiss]);
259
+ return /* @__PURE__ */ jsxs2("div", {
260
+ className: "ja-toast",
261
+ "data-tone": toast.tone,
262
+ children: [
263
+ /* @__PURE__ */ jsx2("span", {
264
+ className: "ja-toast-mark",
265
+ "aria-hidden": "true",
266
+ children: toast.tone === "done" ? /* @__PURE__ */ jsx2(icons.check, {}) : "!"
267
+ }),
268
+ /* @__PURE__ */ jsx2("span", {
269
+ children: toast.message
270
+ }),
271
+ toast.tone === "error" && /* @__PURE__ */ jsx2("button", {
272
+ type: "button",
273
+ className: "ja-toast-close",
274
+ "aria-label": "Dismiss",
275
+ onClick: onDismiss,
276
+ children: /* @__PURE__ */ jsx2(icons.close, {})
277
+ })
278
+ ]
279
+ });
280
+ }
281
+
282
+ // src/admin/theme.tsx
283
+ import { createContext as createContext2, useCallback as useCallback2, useContext as useContext2, useEffect as useEffect2, useMemo, useState as useState2 } from "react";
284
+ var ThemeContext = createContext2(null);
285
+ var storage = {
286
+ get(key) {
287
+ try {
288
+ return globalThis.localStorage?.getItem(key) ?? null;
289
+ } catch {
290
+ return null;
291
+ }
292
+ },
293
+ set(key, value) {
294
+ try {
295
+ globalThis.localStorage?.setItem(key, value);
296
+ } catch {}
297
+ }
298
+ };
299
+ var isChoice = (value) => value === "light" || value === "dark" || value === "system";
300
+ function systemTheme() {
301
+ return typeof matchMedia === "function" && matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
302
+ }
303
+ function useThemeState(options) {
304
+ const { choice: controlled, defaultChoice = "system", onChoiceChange, storageKey = "jgb-admin-theme" } = options;
305
+ const [stored, setStored] = useState2(defaultChoice);
306
+ const [system, setSystem] = useState2("light");
307
+ useEffect2(() => {
308
+ const saved = storage.get(storageKey);
309
+ if (controlled === undefined && isChoice(saved))
310
+ setStored(saved);
311
+ setSystem(systemTheme());
312
+ if (typeof matchMedia !== "function")
313
+ return;
314
+ const query = matchMedia("(prefers-color-scheme: dark)");
315
+ const onChange = () => setSystem(query.matches ? "dark" : "light");
316
+ query.addEventListener("change", onChange);
317
+ return () => query.removeEventListener("change", onChange);
318
+ }, [controlled, storageKey]);
319
+ const choice = controlled ?? stored;
320
+ const setChoice = useCallback2((next) => {
321
+ if (controlled === undefined) {
322
+ setStored(next);
323
+ storage.set(storageKey, next);
324
+ }
325
+ onChoiceChange?.(next);
326
+ }, [controlled, onChoiceChange, storageKey]);
327
+ return useMemo(() => ({ choice, theme: choice === "system" ? system : choice, setChoice }), [choice, system, setChoice]);
328
+ }
329
+ var ThemeProvider = ThemeContext.Provider;
330
+ function useAdminTheme() {
331
+ const state = useContext2(ThemeContext);
332
+ if (!state)
333
+ throw new Error("useAdminTheme must be used inside <AdminShell>.");
334
+ return state;
335
+ }
336
+
337
+ // src/admin/shell/Dock.tsx
338
+ import { Fragment as Fragment2 } from "react";
339
+
340
+ // src/admin/shell/nav.tsx
341
+ import { jsx as jsx3 } from "react/jsx-runtime";
342
+ var plainLink = ({ item, children, ...rest }) => /* @__PURE__ */ jsx3("a", {
343
+ href: item.href,
344
+ ...rest,
345
+ children
346
+ });
347
+ var formatCount = (count) => typeof count === "number" ? count.toLocaleString("en-US") : count;
348
+ var formatBadge = (count) => typeof count === "number" && count > 99 ? "99+" : formatCount(count);
349
+
350
+ // src/admin/shell/Dock.tsx
351
+ import { jsx as jsx4, jsxs as jsxs3, Fragment as Fragment3 } from "react/jsx-runtime";
352
+ function Dock({ items, renderLink = plainLink }) {
353
+ return /* @__PURE__ */ jsx4("nav", {
354
+ className: "ja-dock",
355
+ "aria-label": "Admin",
356
+ children: items.slice(0, 5).map((item) => /* @__PURE__ */ jsx4(Fragment2, {
357
+ children: renderLink({
358
+ item,
359
+ className: "ja-docklink",
360
+ "aria-current": item.current ? "page" : undefined,
361
+ title: undefined,
362
+ children: /* @__PURE__ */ jsxs3(Fragment3, {
363
+ children: [
364
+ item.icon,
365
+ /* @__PURE__ */ jsx4("span", {
366
+ children: item.label
367
+ })
368
+ ]
369
+ })
370
+ })
371
+ }, item.key))
372
+ });
373
+ }
374
+
375
+ // src/admin/shell/Sidebar.tsx
376
+ import { useEffect as useEffect3, useId, useState as useState3 } from "react";
377
+
378
+ // src/admin/ui/Button.tsx
379
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
380
+ function Button({ variant = "primary", size = "normal", icon, className, children, type = "button", ...rest }) {
381
+ return /* @__PURE__ */ jsxs4("button", {
382
+ type,
383
+ className: className ? `ja-button ${className}` : "ja-button",
384
+ "data-variant": variant === "primary" ? undefined : variant,
385
+ "data-size": size === "normal" ? undefined : size,
386
+ ...rest,
387
+ children: [
388
+ icon,
389
+ children
390
+ ]
391
+ });
392
+ }
393
+ function IconButton({ label, icon, dot = false, tone = "tile", className, type = "button", ...rest }) {
394
+ return /* @__PURE__ */ jsxs4("button", {
395
+ type,
396
+ "aria-label": label,
397
+ title: label,
398
+ className: className ? `ja-icon-button ${className}` : "ja-icon-button",
399
+ "data-tone": tone === "tile" ? undefined : tone,
400
+ ...rest,
401
+ children: [
402
+ icon,
403
+ dot && /* @__PURE__ */ jsx5("span", {
404
+ className: "ja-dot",
405
+ "aria-hidden": "true"
406
+ })
407
+ ]
408
+ });
409
+ }
410
+
411
+ // src/admin/ui/Avatar.tsx
412
+ import { jsx as jsx6 } from "react/jsx-runtime";
413
+ var TONES = [
414
+ ["#ffd9c9", "#8a2d12"],
415
+ ["#d9ecff", "#1d4f91"],
416
+ ["#e6f6ec", "#17603f"],
417
+ ["#f1e8ff", "#5b2a9e"],
418
+ ["#fff1c7", "#6b4a00"],
419
+ ["#ffe0ee", "#8c1d4f"]
420
+ ];
421
+ function initials(name) {
422
+ const words = name.trim().split(/\s+/).filter(Boolean);
423
+ const letters = words.length > 1 ? [words[0], words[words.length - 1]] : words;
424
+ return letters.map((word) => [...word][0].toUpperCase()).join("");
425
+ }
426
+ function toneOf(name) {
427
+ let hash = 0;
428
+ for (const char of name)
429
+ hash = hash * 31 + char.codePointAt(0) >>> 0;
430
+ return TONES[hash % TONES.length];
431
+ }
432
+ function Avatar({ name, src, size = 38, shape = "round" }) {
433
+ const [background, color] = toneOf(name);
434
+ const style = {
435
+ "--size": `${size}px`,
436
+ "--avatar-radius": shape === "round" ? "50%" : `${Math.round(size * 0.37)}px`,
437
+ background,
438
+ color
439
+ };
440
+ return /* @__PURE__ */ jsx6("span", {
441
+ className: "ja-avatar",
442
+ style,
443
+ "aria-hidden": "true",
444
+ children: src ? /* @__PURE__ */ jsx6("img", {
445
+ src,
446
+ alt: ""
447
+ }) : initials(name)
448
+ });
449
+ }
450
+
451
+ // src/admin/shell/Sidebar.tsx
452
+ import { jsx as jsx7, jsxs as jsxs5, Fragment as Fragment4 } from "react/jsx-runtime";
453
+ function Sidebar({ app, sections, user, renderLink = plainLink, storageKey = "jgb-admin-sidebar", footer }) {
454
+ const [collapsed, setCollapsed] = useState3(false);
455
+ const labelId = useId();
456
+ useEffect3(() => {
457
+ setCollapsed(storage.get(storageKey) === "collapsed");
458
+ }, [storageKey]);
459
+ const toggle = () => {
460
+ setCollapsed((was) => {
461
+ storage.set(storageKey, was ? "open" : "collapsed");
462
+ return !was;
463
+ });
464
+ };
465
+ const group = (section, index) => {
466
+ const id = `${labelId}-${index}`;
467
+ return /* @__PURE__ */ jsxs5("div", {
468
+ children: [
469
+ section.label && !collapsed && /* @__PURE__ */ jsx7("div", {
470
+ className: "ja-navlabel",
471
+ id,
472
+ children: section.label
473
+ }),
474
+ /* @__PURE__ */ jsx7("ul", {
475
+ className: "ja-nav",
476
+ "aria-labelledby": section.label && !collapsed ? id : undefined,
477
+ children: section.items.map((item) => /* @__PURE__ */ jsx7("li", {
478
+ children: renderLink({
479
+ item,
480
+ className: "ja-navlink",
481
+ "aria-current": item.current ? "page" : undefined,
482
+ title: collapsed ? item.count !== undefined ? `${item.label}, ${formatCount(item.count)}` : item.label : undefined,
483
+ children: /* @__PURE__ */ jsxs5(Fragment4, {
484
+ children: [
485
+ item.icon,
486
+ /* @__PURE__ */ jsx7("span", {
487
+ className: collapsed ? "ja-sr" : undefined,
488
+ children: item.label
489
+ }),
490
+ item.count !== undefined && /* @__PURE__ */ jsx7("span", {
491
+ className: "ja-count",
492
+ children: collapsed ? /* @__PURE__ */ jsxs5(Fragment4, {
493
+ children: [
494
+ /* @__PURE__ */ jsxs5("span", {
495
+ className: "ja-sr",
496
+ children: [
497
+ ", ",
498
+ formatCount(item.count)
499
+ ]
500
+ }),
501
+ /* @__PURE__ */ jsx7("span", {
502
+ "aria-hidden": "true",
503
+ children: formatBadge(item.count)
504
+ })
505
+ ]
506
+ }) : /* @__PURE__ */ jsxs5(Fragment4, {
507
+ children: [
508
+ /* @__PURE__ */ jsx7("span", {
509
+ className: "ja-sr",
510
+ children: ", "
511
+ }),
512
+ formatCount(item.count)
513
+ ]
514
+ })
515
+ })
516
+ ]
517
+ })
518
+ })
519
+ }, item.key))
520
+ })
521
+ ]
522
+ }, section.label ?? index);
523
+ };
524
+ const start = sections.filter((section) => section.placement !== "end");
525
+ const end = sections.filter((section) => section.placement === "end");
526
+ return /* @__PURE__ */ jsxs5("aside", {
527
+ className: "ja-sidebar",
528
+ "data-collapsed": collapsed ? "true" : undefined,
529
+ "aria-label": `${app.name} admin`,
530
+ children: [
531
+ /* @__PURE__ */ jsxs5("div", {
532
+ className: "ja-brandrow",
533
+ children: [
534
+ /* @__PURE__ */ jsx7("span", {
535
+ className: "ja-mark",
536
+ "aria-hidden": "true",
537
+ children: app.mark
538
+ }),
539
+ /* @__PURE__ */ jsx7("span", {
540
+ className: collapsed ? "ja-sr" : "ja-brand-name",
541
+ children: app.name
542
+ }),
543
+ /* @__PURE__ */ jsx7(IconButton, {
544
+ className: "ja-collapse",
545
+ tone: "night",
546
+ icon: /* @__PURE__ */ jsx7(icons.sidebar, {}),
547
+ label: collapsed ? "Show the menu labels" : "Collapse the menu to icons",
548
+ "aria-expanded": !collapsed,
549
+ onClick: toggle
550
+ })
551
+ ]
552
+ }),
553
+ /* @__PURE__ */ jsxs5("nav", {
554
+ "aria-label": "Admin",
555
+ className: "ja-sidebar-nav",
556
+ children: [
557
+ start.map(group),
558
+ end.length > 0 && /* @__PURE__ */ jsx7("div", {
559
+ className: "ja-nav-end",
560
+ children: end.map((section, i) => group(section, start.length + i))
561
+ })
562
+ ]
563
+ }),
564
+ (user || footer) && /* @__PURE__ */ jsxs5("div", {
565
+ className: "ja-sidebar-bottom",
566
+ children: [
567
+ footer,
568
+ user && /* @__PURE__ */ jsxs5("div", {
569
+ className: "ja-me",
570
+ title: collapsed ? `${user.name}${user.role ? `, ${user.role}` : ""}` : undefined,
571
+ children: [
572
+ /* @__PURE__ */ jsx7(Avatar, {
573
+ name: user.name,
574
+ src: user.image,
575
+ size: 36
576
+ }),
577
+ /* @__PURE__ */ jsxs5("span", {
578
+ className: collapsed ? "ja-sr" : undefined,
579
+ children: [
580
+ /* @__PURE__ */ jsx7("b", {
581
+ children: user.name
582
+ }),
583
+ user.role && /* @__PURE__ */ jsx7("small", {
584
+ children: user.role
585
+ })
586
+ ]
587
+ })
588
+ ]
589
+ })
590
+ ]
591
+ })
592
+ ]
593
+ });
594
+ }
595
+
596
+ // src/admin/shell/ThemeToggle.tsx
597
+ import { useRef as useRef2 } from "react";
598
+ import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
599
+ var OPTIONS = [
600
+ { choice: "light", label: "Light", short: "Light", Icon: icons.sun },
601
+ { choice: "dark", label: "Dark", short: "Dark", Icon: icons.moon },
602
+ { choice: "system", label: "Match system", short: "System", Icon: icons.screen }
603
+ ];
604
+ function nextIndex(key, current, count) {
605
+ if (key === "ArrowRight" || key === "ArrowDown")
606
+ return (current + 1) % count;
607
+ if (key === "ArrowLeft" || key === "ArrowUp")
608
+ return (current - 1 + count) % count;
609
+ if (key === "Home")
610
+ return 0;
611
+ if (key === "End")
612
+ return count - 1;
613
+ return null;
614
+ }
615
+ function ThemeToggle({ tone = "tile" }) {
616
+ const { choice, setChoice } = useAdminTheme();
617
+ const buttons = useRef2([]);
618
+ const index = OPTIONS.findIndex((option) => option.choice === choice);
619
+ const current = OPTIONS[index] ?? OPTIONS[2];
620
+ const next = OPTIONS[(index + 1) % OPTIONS.length] ?? OPTIONS[0];
621
+ const onKeyDown = (event) => {
622
+ const to = nextIndex(event.key, index, OPTIONS.length);
623
+ const option = to === null ? undefined : OPTIONS[to];
624
+ if (to === null || !option)
625
+ return;
626
+ event.preventDefault();
627
+ setChoice(option.choice);
628
+ buttons.current[to]?.focus();
629
+ };
630
+ return /* @__PURE__ */ jsxs6("div", {
631
+ className: "ja-theme",
632
+ "data-tone": tone === "tile" ? undefined : tone,
633
+ children: [
634
+ /* @__PURE__ */ jsx8("div", {
635
+ role: "radiogroup",
636
+ "aria-label": "Theme",
637
+ className: "ja-theme-options",
638
+ onKeyDown,
639
+ children: OPTIONS.map((option, i) => /* @__PURE__ */ jsxs6("button", {
640
+ ref: (el) => {
641
+ buttons.current[i] = el;
642
+ },
643
+ type: "button",
644
+ role: "radio",
645
+ "aria-checked": option.choice === choice,
646
+ "aria-label": option.label,
647
+ title: option.label,
648
+ tabIndex: option.choice === choice ? 0 : -1,
649
+ onClick: () => setChoice(option.choice),
650
+ children: [
651
+ /* @__PURE__ */ jsx8(option.Icon, {}),
652
+ /* @__PURE__ */ jsx8("span", {
653
+ "aria-hidden": "true",
654
+ children: option.short
655
+ })
656
+ ]
657
+ }, option.choice))
658
+ }),
659
+ /* @__PURE__ */ jsx8(IconButton, {
660
+ className: "ja-theme-cycle",
661
+ tone,
662
+ icon: /* @__PURE__ */ jsx8(current.Icon, {}),
663
+ label: `Theme: ${current.label}. Switch to ${next.label}`,
664
+ onClick: () => setChoice(next.choice)
665
+ })
666
+ ]
667
+ });
668
+ }
669
+
670
+ // src/admin/shell/AdminShell.tsx
671
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
672
+ function AdminShell({
673
+ app,
674
+ brand,
675
+ nav,
676
+ dockItems,
677
+ user,
678
+ renderLink,
679
+ mobileActions,
680
+ sidebarFooter,
681
+ theme,
682
+ defaultTheme,
683
+ onThemeChange,
684
+ children
685
+ }) {
686
+ const state = useThemeState({ choice: theme, defaultChoice: defaultTheme, onChoiceChange: onThemeChange });
687
+ const style = useMemo2(() => brand ? { "--brand": brand, "--brand-ink": inkOn(brand) } : undefined, [brand]);
688
+ const all = nav.flatMap((section) => section.items);
689
+ const dock = dockItems ? dockItems.map((key) => all.find((item) => item.key === key)).filter((item) => item !== undefined) : all.slice(0, 5);
690
+ return /* @__PURE__ */ jsx9(ThemeProvider, {
691
+ value: state,
692
+ children: /* @__PURE__ */ jsx9("div", {
693
+ className: "ja-root",
694
+ "data-theme": state.choice === "system" ? undefined : state.choice,
695
+ style,
696
+ children: /* @__PURE__ */ jsxs7(ToastProvider, {
697
+ children: [
698
+ /* @__PURE__ */ jsxs7("div", {
699
+ className: "ja-shell",
700
+ children: [
701
+ /* @__PURE__ */ jsx9(Sidebar, {
702
+ app,
703
+ sections: nav,
704
+ user,
705
+ renderLink,
706
+ footer: sidebarFooter
707
+ }),
708
+ /* @__PURE__ */ jsxs7("main", {
709
+ className: "ja-main",
710
+ id: "main",
711
+ children: [
712
+ /* @__PURE__ */ jsxs7("div", {
713
+ className: "ja-mobile-top",
714
+ children: [
715
+ /* @__PURE__ */ jsx9("span", {
716
+ className: "ja-mark",
717
+ "aria-hidden": "true",
718
+ children: app.mark
719
+ }),
720
+ /* @__PURE__ */ jsx9("span", {
721
+ children: app.name
722
+ }),
723
+ /* @__PURE__ */ jsxs7("div", {
724
+ className: "ja-actions",
725
+ children: [
726
+ /* @__PURE__ */ jsx9(ThemeToggle, {}),
727
+ mobileActions
728
+ ]
729
+ })
730
+ ]
731
+ }),
732
+ children
733
+ ]
734
+ })
735
+ ]
736
+ }),
737
+ /* @__PURE__ */ jsx9(Dock, {
738
+ items: dock,
739
+ renderLink
740
+ })
741
+ ]
742
+ })
743
+ })
744
+ });
745
+ }
746
+ // src/admin/shell/PageHeader.tsx
747
+ import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
748
+ function PageHeader({ title, description, tools, actions }) {
749
+ return /* @__PURE__ */ jsxs8("header", {
750
+ className: "ja-page-header",
751
+ children: [
752
+ /* @__PURE__ */ jsxs8("div", {
753
+ children: [
754
+ /* @__PURE__ */ jsx10("h1", {
755
+ className: "ja-page-title",
756
+ children: title
757
+ }),
758
+ description && /* @__PURE__ */ jsx10("p", {
759
+ children: description
760
+ })
761
+ ]
762
+ }),
763
+ tools && /* @__PURE__ */ jsx10("div", {
764
+ className: "ja-actions ja-desktop-only",
765
+ children: tools
766
+ }),
767
+ actions && /* @__PURE__ */ jsx10("div", {
768
+ className: "ja-actions",
769
+ children: actions
770
+ })
771
+ ]
772
+ });
773
+ }
774
+ function TopSearch({ label, placeholder, className, ...input }) {
775
+ return /* @__PURE__ */ jsxs8("label", {
776
+ className: className ? `ja-topsearch ${className}` : "ja-topsearch",
777
+ children: [
778
+ /* @__PURE__ */ jsx10(icons.search, {}),
779
+ /* @__PURE__ */ jsx10("span", {
780
+ className: "ja-sr",
781
+ children: label
782
+ }),
783
+ /* @__PURE__ */ jsx10("input", {
784
+ type: "search",
785
+ placeholder: placeholder ?? label,
786
+ ...input
787
+ })
788
+ ]
789
+ });
790
+ }
791
+ // src/admin/blocks/Tile.tsx
792
+ import { useId as useId2 } from "react";
793
+ import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
794
+ function Bento({ children, className, ...rest }) {
795
+ return /* @__PURE__ */ jsx11("section", {
796
+ className: className ? `ja-bento ${className}` : "ja-bento",
797
+ ...rest,
798
+ children
799
+ });
800
+ }
801
+ function Tile({
802
+ span = 12,
803
+ rowSpan = 1,
804
+ phoneSpan = 2,
805
+ tone = "plain",
806
+ title,
807
+ actions,
808
+ as,
809
+ style,
810
+ children,
811
+ className,
812
+ ...rest
813
+ }) {
814
+ const Element = as ?? (title ? "section" : "div");
815
+ const titleId = useId2();
816
+ const labelled = title && !rest["aria-label"] && !rest["aria-labelledby"] ? titleId : undefined;
817
+ const vars = { "--span": span, "--row-span": rowSpan, "--phone-span": phoneSpan, ...style };
818
+ return /* @__PURE__ */ jsxs9(Element, {
819
+ className: className ? `ja-tile ${className}` : "ja-tile",
820
+ "data-tone": tone === "plain" ? undefined : tone,
821
+ style: vars,
822
+ "aria-labelledby": labelled,
823
+ ...rest,
824
+ children: [
825
+ (title || actions) && /* @__PURE__ */ jsxs9("div", {
826
+ className: "ja-tile-head",
827
+ children: [
828
+ title && /* @__PURE__ */ jsx11("h2", {
829
+ className: "ja-tile-title",
830
+ id: titleId,
831
+ children: title
832
+ }),
833
+ actions
834
+ ]
835
+ }),
836
+ children
837
+ ]
838
+ });
839
+ }
840
+ // src/admin/blocks/Stat.tsx
841
+ import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
842
+ function DeltaText({ delta }) {
843
+ const good = delta.good ?? delta.direction === "up";
844
+ return /* @__PURE__ */ jsxs10("span", {
845
+ className: "ja-delta",
846
+ "data-good": good ? "true" : "false",
847
+ children: [
848
+ /* @__PURE__ */ jsx12("span", {
849
+ className: "ja-sr",
850
+ children: delta.direction === "up" ? "Up " : "Down "
851
+ }),
852
+ delta.value,
853
+ delta.label && /* @__PURE__ */ jsxs10("span", {
854
+ className: "ja-label",
855
+ children: [
856
+ " ",
857
+ delta.label
858
+ ]
859
+ })
860
+ ]
861
+ });
862
+ }
863
+ function Meter({ value, label }) {
864
+ const share = Math.min(1, Math.max(0, value));
865
+ return /* @__PURE__ */ jsx12("div", {
866
+ className: "ja-meter",
867
+ role: "meter",
868
+ "aria-label": label,
869
+ "aria-valuemin": 0,
870
+ "aria-valuemax": 100,
871
+ "aria-valuenow": Math.round(share * 100),
872
+ children: /* @__PURE__ */ jsx12("span", {
873
+ style: { width: `${share * 100}%` }
874
+ })
875
+ });
876
+ }
877
+ function AvatarStack({ names, more = 0, label }) {
878
+ return /* @__PURE__ */ jsxs10("div", {
879
+ className: "ja-avatar-stack",
880
+ role: "img",
881
+ "aria-label": label,
882
+ children: [
883
+ names.slice(0, 4).map((name) => /* @__PURE__ */ jsx12(Avatar, {
884
+ name,
885
+ size: 30
886
+ }, name)),
887
+ more > 0 && /* @__PURE__ */ jsxs10("span", {
888
+ className: "ja-more",
889
+ "aria-hidden": "true",
890
+ children: [
891
+ "+",
892
+ more.toLocaleString("en-US")
893
+ ]
894
+ })
895
+ ]
896
+ });
897
+ }
898
+ function StatTile({ label, value, delta, note, children, span = 3, ...tile }) {
899
+ return /* @__PURE__ */ jsxs10(Tile, {
900
+ span,
901
+ ...tile,
902
+ children: [
903
+ /* @__PURE__ */ jsx12("div", {
904
+ className: "ja-label",
905
+ children: label
906
+ }),
907
+ /* @__PURE__ */ jsx12("div", {
908
+ className: "ja-number",
909
+ children: value
910
+ }),
911
+ children,
912
+ (note || delta) && /* @__PURE__ */ jsxs10("p", {
913
+ className: "ja-note",
914
+ children: [
915
+ note,
916
+ note && delta && ", ",
917
+ delta && /* @__PURE__ */ jsx12(DeltaText, {
918
+ delta
919
+ })
920
+ ]
921
+ })
922
+ ]
923
+ });
924
+ }
925
+ // src/admin/blocks/LineChart.tsx
926
+ import { useId as useId3, useState as useState5 } from "react";
927
+
928
+ // src/admin/blocks/ChartPoints.tsx
929
+ import { useState as useState4 } from "react";
930
+ import { jsx as jsx13, jsxs as jsxs11, Fragment as Fragment5 } from "react/jsx-runtime";
931
+ function nextPoint(key, current, count) {
932
+ if (count === 0)
933
+ return null;
934
+ switch (key) {
935
+ case "ArrowRight":
936
+ case "ArrowDown":
937
+ return Math.min(count - 1, current + 1);
938
+ case "ArrowLeft":
939
+ case "ArrowUp":
940
+ return Math.max(0, current - 1);
941
+ case "Home":
942
+ return 0;
943
+ case "End":
944
+ return count - 1;
945
+ default:
946
+ return null;
947
+ }
948
+ }
949
+ function areaStyle(center, width) {
950
+ const left = Math.max(0, center - width / 2);
951
+ const right = Math.min(100, center + width / 2);
952
+ return { left: `${left}%`, width: `${right - left}%` };
953
+ }
954
+ function ChartPoints({ names, centers, width, active, onActive, tipTop, tip }) {
955
+ const [stop, setStop] = useState4(names.length - 1);
956
+ const tabStop = Math.min(stop, names.length - 1);
957
+ const onKeyDown = (event, index) => {
958
+ const next = nextPoint(event.key, index, names.length);
959
+ if (next === null)
960
+ return;
961
+ event.preventDefault();
962
+ setStop(next);
963
+ const sibling = event.currentTarget.parentElement?.children[next];
964
+ if (sibling instanceof HTMLElement)
965
+ sibling.focus();
966
+ };
967
+ const center = active === null ? 0 : centers[active] ?? 0;
968
+ const top = active === null ? 0 : tipTop(active);
969
+ const beside = top < 32;
970
+ const toStart = center > 60;
971
+ const offset = Math.min(width / 2, 6);
972
+ const tipLeft = beside ? center + (toStart ? -offset : offset) : center;
973
+ const side = beside ? toStart ? "before" : "after" : center < 18 ? "start" : center > 82 ? "end" : undefined;
974
+ return /* @__PURE__ */ jsxs11(Fragment5, {
975
+ children: [
976
+ /* @__PURE__ */ jsx13("div", {
977
+ className: "ja-chart-points",
978
+ onPointerLeave: () => onActive(null),
979
+ children: names.map((name, i) => /* @__PURE__ */ jsx13("span", {
980
+ role: "img",
981
+ "aria-label": name,
982
+ tabIndex: i === tabStop ? 0 : -1,
983
+ className: "ja-chart-point",
984
+ "data-active": i === active || undefined,
985
+ style: areaStyle(centers[i] ?? 0, width),
986
+ onPointerEnter: () => onActive(i),
987
+ onFocus: () => {
988
+ setStop(i);
989
+ onActive(i);
990
+ },
991
+ onBlur: () => onActive(null),
992
+ onKeyDown: (event) => onKeyDown(event, i)
993
+ }, name))
994
+ }),
995
+ active !== null && /* @__PURE__ */ jsx13("div", {
996
+ className: "ja-chart-tip",
997
+ "aria-hidden": "true",
998
+ "data-side": side,
999
+ style: { left: `${tipLeft}%`, top: `${beside ? Math.max(top, 4) : top}%` },
1000
+ children: tip(active)
1001
+ })
1002
+ ]
1003
+ });
1004
+ }
1005
+
1006
+ // src/admin/blocks/LineChart.tsx
1007
+ import { jsx as jsx14, jsxs as jsxs12, Fragment as Fragment6 } from "react/jsx-runtime";
1008
+ function scalePoints(values, width, height, pad = 12) {
1009
+ if (values.length === 0)
1010
+ return [];
1011
+ const max = Math.max(...values);
1012
+ const min = Math.min(0, ...values);
1013
+ const range = max - min || 1;
1014
+ const step = values.length > 1 ? width / (values.length - 1) : 0;
1015
+ return values.map((value, i) => [values.length > 1 ? i * step : width / 2, pad + (1 - (value - min) / range) * (height - pad * 2)]);
1016
+ }
1017
+ function smoothPath(points) {
1018
+ if (points.length === 0)
1019
+ return "";
1020
+ const [first] = points;
1021
+ if (points.length === 1)
1022
+ return `M${first[0]} ${first[1]}`;
1023
+ let d = `M${round(first[0])} ${round(first[1])}`;
1024
+ for (let i = 0;i < points.length - 1; i++) {
1025
+ const p0 = points[i - 1] ?? points[i];
1026
+ const p1 = points[i];
1027
+ const p2 = points[i + 1];
1028
+ const p3 = points[i + 2] ?? p2;
1029
+ const c1 = [p1[0] + (p2[0] - p0[0]) / 6, p1[1] + (p2[1] - p0[1]) / 6];
1030
+ const c2 = [p2[0] - (p3[0] - p1[0]) / 6, p2[1] - (p3[1] - p1[1]) / 6];
1031
+ d += ` C${round(c1[0])} ${round(c1[1])} ${round(c2[0])} ${round(c2[1])} ${round(p2[0])} ${round(p2[1])}`;
1032
+ }
1033
+ return d;
1034
+ }
1035
+ var round = (n) => Math.round(n * 10) / 10;
1036
+ function LineChart({ data, label, color = "sun", height = 150, format = (v) => v.toLocaleString("en-US") }) {
1037
+ const id = useId3();
1038
+ const width = 400;
1039
+ const points = scalePoints(data.map((point) => point.value), width, height);
1040
+ const line = smoothPath(points);
1041
+ const [active, setActive] = useState5(null);
1042
+ const shown = active === null ? points[points.length - 1] : points[active];
1043
+ const stroke = color === "sun" ? "var(--sun)" : "var(--brand)";
1044
+ return /* @__PURE__ */ jsxs12("figure", {
1045
+ className: "ja-chart",
1046
+ children: [
1047
+ /* @__PURE__ */ jsxs12("div", {
1048
+ className: "ja-chart-plot",
1049
+ children: [
1050
+ /* @__PURE__ */ jsxs12("svg", {
1051
+ viewBox: `0 0 ${width} ${height}`,
1052
+ preserveAspectRatio: "none",
1053
+ width: "100%",
1054
+ height,
1055
+ role: "img",
1056
+ "aria-label": label,
1057
+ children: [
1058
+ /* @__PURE__ */ jsx14("defs", {
1059
+ children: /* @__PURE__ */ jsxs12("linearGradient", {
1060
+ id: `${id}-fade`,
1061
+ x1: "0",
1062
+ x2: "0",
1063
+ y1: "0",
1064
+ y2: "1",
1065
+ children: [
1066
+ /* @__PURE__ */ jsx14("stop", {
1067
+ offset: "0",
1068
+ stopColor: stroke,
1069
+ stopOpacity: "0.35"
1070
+ }),
1071
+ /* @__PURE__ */ jsx14("stop", {
1072
+ offset: "1",
1073
+ stopColor: stroke,
1074
+ stopOpacity: "0"
1075
+ })
1076
+ ]
1077
+ })
1078
+ }),
1079
+ points.length > 1 && /* @__PURE__ */ jsx14("path", {
1080
+ d: `${line} L${width} ${height} L0 ${height} Z`,
1081
+ fill: `url(#${id}-fade)`
1082
+ }),
1083
+ /* @__PURE__ */ jsx14("path", {
1084
+ d: line,
1085
+ fill: "none",
1086
+ stroke,
1087
+ strokeWidth: "3.5",
1088
+ strokeLinecap: "round",
1089
+ vectorEffect: "non-scaling-stroke"
1090
+ })
1091
+ ]
1092
+ }),
1093
+ active !== null && shown && /* @__PURE__ */ jsx14("span", {
1094
+ className: "ja-chart-guide",
1095
+ style: { left: `${shown[0] / width * 100}%` }
1096
+ }),
1097
+ shown && /* @__PURE__ */ jsx14("span", {
1098
+ className: "ja-chart-dot",
1099
+ style: { left: `${shown[0] / width * 100}%`, top: `${shown[1] / height * 100}%`, background: stroke }
1100
+ }),
1101
+ /* @__PURE__ */ jsx14(ChartPoints, {
1102
+ names: data.map((point) => `${point.label}: ${format(point.value)}`),
1103
+ centers: points.map(([x]) => x / width * 100),
1104
+ width: 100 / Math.max(1, data.length - 1),
1105
+ active,
1106
+ onActive: setActive,
1107
+ tipTop: (i) => (points[i]?.[1] ?? 0) / height * 100,
1108
+ tip: (i) => /* @__PURE__ */ jsxs12(Fragment6, {
1109
+ children: [
1110
+ /* @__PURE__ */ jsx14("span", {
1111
+ children: data[i]?.label
1112
+ }),
1113
+ /* @__PURE__ */ jsx14("strong", {
1114
+ children: format(data[i]?.value ?? 0)
1115
+ })
1116
+ ]
1117
+ })
1118
+ })
1119
+ ]
1120
+ }),
1121
+ /* @__PURE__ */ jsx14("div", {
1122
+ className: "ja-chart-labels",
1123
+ "aria-hidden": "true",
1124
+ children: data.map((point) => /* @__PURE__ */ jsx14("span", {
1125
+ children: point.label
1126
+ }, point.label))
1127
+ }),
1128
+ /* @__PURE__ */ jsx14("div", {
1129
+ className: "ja-sr",
1130
+ children: /* @__PURE__ */ jsxs12("table", {
1131
+ children: [
1132
+ /* @__PURE__ */ jsx14("caption", {
1133
+ children: label
1134
+ }),
1135
+ /* @__PURE__ */ jsx14("tbody", {
1136
+ children: data.map((point) => /* @__PURE__ */ jsxs12("tr", {
1137
+ children: [
1138
+ /* @__PURE__ */ jsx14("th", {
1139
+ scope: "row",
1140
+ children: point.label
1141
+ }),
1142
+ /* @__PURE__ */ jsx14("td", {
1143
+ children: format(point.value)
1144
+ })
1145
+ ]
1146
+ }, point.label))
1147
+ })
1148
+ ]
1149
+ })
1150
+ })
1151
+ ]
1152
+ });
1153
+ }
1154
+
1155
+ // src/admin/blocks/Segmented.tsx
1156
+ import { jsx as jsx15 } from "react/jsx-runtime";
1157
+ function SegmentedControl({
1158
+ label,
1159
+ options,
1160
+ value,
1161
+ onChange
1162
+ }) {
1163
+ return /* @__PURE__ */ jsx15("div", {
1164
+ className: "ja-segmented",
1165
+ role: "group",
1166
+ "aria-label": label,
1167
+ children: options.map((option) => /* @__PURE__ */ jsx15("button", {
1168
+ type: "button",
1169
+ "aria-pressed": option.value === value,
1170
+ onClick: () => onChange(option.value),
1171
+ children: option.label
1172
+ }, option.value))
1173
+ });
1174
+ }
1175
+
1176
+ // src/admin/blocks/Hero.tsx
1177
+ import { jsx as jsx16, jsxs as jsxs13 } from "react/jsx-runtime";
1178
+ function HeroChartTile({
1179
+ label,
1180
+ value,
1181
+ delta,
1182
+ data,
1183
+ chartLabel,
1184
+ periods,
1185
+ span = 5,
1186
+ rowSpan = 2,
1187
+ className,
1188
+ ...tile
1189
+ }) {
1190
+ return /* @__PURE__ */ jsxs13(Tile, {
1191
+ span,
1192
+ rowSpan,
1193
+ tone: "night",
1194
+ className: className ? `ja-hero ${className}` : "ja-hero",
1195
+ ...tile,
1196
+ children: [
1197
+ /* @__PURE__ */ jsxs13("div", {
1198
+ className: "ja-tile-head",
1199
+ style: { marginBottom: 0 },
1200
+ children: [
1201
+ /* @__PURE__ */ jsx16("span", {
1202
+ className: "ja-label",
1203
+ children: label
1204
+ }),
1205
+ periods && /* @__PURE__ */ jsx16(SegmentedControl, {
1206
+ label: periods.label,
1207
+ options: periods.options,
1208
+ value: periods.value,
1209
+ onChange: periods.onChange
1210
+ })
1211
+ ]
1212
+ }),
1213
+ /* @__PURE__ */ jsx16("div", {
1214
+ className: "ja-number",
1215
+ children: value
1216
+ }),
1217
+ delta && /* @__PURE__ */ jsx16("span", {
1218
+ children: /* @__PURE__ */ jsx16(DeltaText, {
1219
+ delta
1220
+ })
1221
+ }),
1222
+ /* @__PURE__ */ jsx16("div", {
1223
+ className: "ja-hero-chart",
1224
+ children: /* @__PURE__ */ jsx16(LineChart, {
1225
+ data,
1226
+ label: chartLabel
1227
+ })
1228
+ })
1229
+ ]
1230
+ });
1231
+ }
1232
+ // src/admin/blocks/DataTable.tsx
1233
+ import { useId as useId4 } from "react";
1234
+
1235
+ // src/admin/blocks/sorting.ts
1236
+ function nextSort(current, key, first = "asc") {
1237
+ if (current?.key === key)
1238
+ return { key, direction: current.direction === "asc" ? "desc" : "asc" };
1239
+ return { key, direction: first };
1240
+ }
1241
+ function sortRows(rows, compare, direction) {
1242
+ if (!compare)
1243
+ return [...rows];
1244
+ const sign = direction === "asc" ? 1 : -1;
1245
+ return rows.map((row, index) => ({ row, index })).sort((a, b) => sign * compare(a.row, b.row) || a.index - b.index).map(({ row }) => row);
1246
+ }
1247
+ var byText = (value) => (a, b) => value(a).localeCompare(value(b), undefined, { numeric: true, sensitivity: "base" });
1248
+ var byNumber = (value) => (a, b) => {
1249
+ const x = value(a);
1250
+ const y = value(b);
1251
+ if (x === null || y === null)
1252
+ return x === y ? 0 : x === null ? -1 : 1;
1253
+ return x - y;
1254
+ };
1255
+ var sortValue = (sort) => `${sort.key}:${sort.direction}`;
1256
+ function parseSortValue(value) {
1257
+ const at = value.lastIndexOf(":");
1258
+ const direction = value.slice(at + 1);
1259
+ if (at <= 0 || direction !== "asc" && direction !== "desc")
1260
+ return;
1261
+ return { key: value.slice(0, at), direction };
1262
+ }
1263
+
1264
+ // src/admin/blocks/DataTable.tsx
1265
+ import { jsx as jsx17, jsxs as jsxs14 } from "react/jsx-runtime";
1266
+ function DataTable({
1267
+ label,
1268
+ columns,
1269
+ rows: given,
1270
+ rowKey,
1271
+ flash,
1272
+ loading = false,
1273
+ empty,
1274
+ sort,
1275
+ onSortChange,
1276
+ sortRows: sortHere = false
1277
+ }) {
1278
+ const sortId = useId4();
1279
+ if (!loading && given.length === 0)
1280
+ return /* @__PURE__ */ jsx17("div", {
1281
+ className: "ja-empty",
1282
+ children: empty ?? "Nothing here yet."
1283
+ });
1284
+ const sortable = onSortChange ? columns.filter((column) => column.sort) : [];
1285
+ const sorted = sort && sortHere ? columns.find((column) => column.key === sort.key) : undefined;
1286
+ const rows = sorted && sort ? sortRows(given, sorted.sort?.compare, sort.direction) : given;
1287
+ return /* @__PURE__ */ jsxs14("div", {
1288
+ className: "ja-table-wrap",
1289
+ "aria-busy": loading || undefined,
1290
+ children: [
1291
+ onSortChange && sortable.length > 0 && /* @__PURE__ */ jsxs14("div", {
1292
+ className: "ja-sort-phone",
1293
+ children: [
1294
+ /* @__PURE__ */ jsx17("label", {
1295
+ htmlFor: sortId,
1296
+ children: "Sort by"
1297
+ }),
1298
+ /* @__PURE__ */ jsxs14("span", {
1299
+ className: "ja-select-wrap",
1300
+ children: [
1301
+ /* @__PURE__ */ jsxs14("select", {
1302
+ id: sortId,
1303
+ className: "ja-select",
1304
+ value: sort ? sortValue(sort) : "",
1305
+ onChange: (event) => {
1306
+ const next = parseSortValue(event.target.value);
1307
+ if (next)
1308
+ onSortChange(next);
1309
+ },
1310
+ children: [
1311
+ !sort && /* @__PURE__ */ jsx17("option", {
1312
+ value: "",
1313
+ children: "Choose"
1314
+ }),
1315
+ sortable.flatMap((column) => {
1316
+ const name = column.sort?.label ?? (typeof column.header === "string" ? column.header : column.srHeader ?? column.key);
1317
+ return ["asc", "desc"].map((direction) => /* @__PURE__ */ jsx17("option", {
1318
+ value: sortValue({ key: column.key, direction }),
1319
+ children: `${name}, ${direction === "asc" ? column.sort?.ascLabel ?? "ascending" : column.sort?.descLabel ?? "descending"}`
1320
+ }, `${column.key}:${direction}`));
1321
+ })
1322
+ ]
1323
+ }),
1324
+ /* @__PURE__ */ jsx17(icons.chevronDown, {})
1325
+ ]
1326
+ })
1327
+ ]
1328
+ }),
1329
+ /* @__PURE__ */ jsxs14("table", {
1330
+ className: "ja-table",
1331
+ "aria-label": label,
1332
+ children: [
1333
+ /* @__PURE__ */ jsx17("thead", {
1334
+ children: /* @__PURE__ */ jsx17("tr", {
1335
+ children: columns.map((column) => {
1336
+ const content = column.header || column.srHeader && /* @__PURE__ */ jsx17("span", {
1337
+ className: "ja-sr",
1338
+ children: column.srHeader
1339
+ });
1340
+ const current = sort?.key === column.key ? sort.direction : undefined;
1341
+ return /* @__PURE__ */ jsx17("th", {
1342
+ scope: "col",
1343
+ "data-align": column.align === "end" ? "end" : undefined,
1344
+ "aria-sort": current === "asc" ? "ascending" : current === "desc" ? "descending" : undefined,
1345
+ children: column.sort && onSortChange ? /* @__PURE__ */ jsxs14("button", {
1346
+ type: "button",
1347
+ className: "ja-sort",
1348
+ "data-sorted": current,
1349
+ onClick: () => onSortChange(nextSort(sort, column.key, column.sort?.first)),
1350
+ children: [
1351
+ content,
1352
+ /* @__PURE__ */ jsx17("span", {
1353
+ className: "ja-sort-arrow",
1354
+ "aria-hidden": "true",
1355
+ children: current === "desc" ? /* @__PURE__ */ jsx17(icons.chevronDown, {}) : /* @__PURE__ */ jsx17(icons.chevronDown, {
1356
+ style: { rotate: "180deg" }
1357
+ })
1358
+ })
1359
+ ]
1360
+ }) : content
1361
+ }, column.key);
1362
+ })
1363
+ })
1364
+ }),
1365
+ /* @__PURE__ */ jsx17("tbody", {
1366
+ children: loading ? Array.from({ length: Math.max(3, Math.min(rows.length, 6)) }, (_, i) => /* @__PURE__ */ jsx17("tr", {
1367
+ "aria-hidden": "true",
1368
+ children: columns.map((column) => /* @__PURE__ */ jsx17("td", {
1369
+ "data-phone": column.phone?.hidden ? "hidden" : undefined,
1370
+ children: /* @__PURE__ */ jsx17("span", {
1371
+ className: "ja-skeleton",
1372
+ style: { width: `${50 + (i * 17 + column.key.length * 7) % 40}%` }
1373
+ })
1374
+ }, column.key))
1375
+ }, `skeleton-${i}`)) : rows.map((row) => {
1376
+ const key = rowKey(row);
1377
+ return /* @__PURE__ */ jsx17("tr", {
1378
+ "data-flash": flash?.has(key) ? "true" : undefined,
1379
+ children: columns.map((column) => /* @__PURE__ */ jsx17("td", {
1380
+ "data-align": column.align === "end" ? "end" : undefined,
1381
+ "data-phone": column.phone?.hidden ? "hidden" : column.phone?.full ? "full" : undefined,
1382
+ "data-phone-align": column.phone?.align === "end" ? "end" : undefined,
1383
+ style: column.phone?.order !== undefined ? { "--phone-order": column.phone.order } : undefined,
1384
+ children: column.cell(row)
1385
+ }, column.key))
1386
+ }, key);
1387
+ })
1388
+ })
1389
+ ]
1390
+ }),
1391
+ loading && /* @__PURE__ */ jsx17("span", {
1392
+ className: "ja-sr",
1393
+ role: "status",
1394
+ children: "Loading"
1395
+ })
1396
+ ]
1397
+ });
1398
+ }
1399
+ function PersonCell({ name, detail, avatar }) {
1400
+ return /* @__PURE__ */ jsxs14("div", {
1401
+ className: "ja-who",
1402
+ children: [
1403
+ avatar,
1404
+ /* @__PURE__ */ jsxs14("span", {
1405
+ children: [
1406
+ /* @__PURE__ */ jsx17("b", {
1407
+ children: name
1408
+ }),
1409
+ detail && /* @__PURE__ */ jsx17("small", {
1410
+ children: detail
1411
+ })
1412
+ ]
1413
+ })
1414
+ ]
1415
+ });
1416
+ }
1417
+ function RowAction({ children, danger = false, ...rest }) {
1418
+ return /* @__PURE__ */ jsx17("button", {
1419
+ type: "button",
1420
+ className: "ja-row-action",
1421
+ "data-variant": danger ? "danger" : undefined,
1422
+ ...rest,
1423
+ children
1424
+ });
1425
+ }
1426
+ // src/admin/blocks/Filters.tsx
1427
+ import { jsx as jsx18, jsxs as jsxs15 } from "react/jsx-runtime";
1428
+ function FilterTabs({
1429
+ label,
1430
+ options,
1431
+ value,
1432
+ onChange
1433
+ }) {
1434
+ return /* @__PURE__ */ jsx18("div", {
1435
+ className: "ja-filters",
1436
+ role: "group",
1437
+ "aria-label": label,
1438
+ children: options.map((option) => /* @__PURE__ */ jsxs15("button", {
1439
+ type: "button",
1440
+ "aria-pressed": option.value === value,
1441
+ onClick: () => onChange(option.value),
1442
+ children: [
1443
+ option.label,
1444
+ option.count !== undefined && /* @__PURE__ */ jsxs15("span", {
1445
+ children: [
1446
+ " ",
1447
+ option.count.toLocaleString("en-US")
1448
+ ]
1449
+ })
1450
+ ]
1451
+ }, option.value))
1452
+ });
1453
+ }
1454
+ // src/admin/blocks/Pagination.tsx
1455
+ import { useId as useId5 } from "react";
1456
+ import { jsx as jsx19, jsxs as jsxs16 } from "react/jsx-runtime";
1457
+ var PAGE_SIZES = [25, 50, 100, 200];
1458
+ function PageSize({ value, onChange, options = PAGE_SIZES, label = "Rows per page" }) {
1459
+ const id = useId5();
1460
+ return /* @__PURE__ */ jsxs16("div", {
1461
+ className: "ja-page-size",
1462
+ children: [
1463
+ /* @__PURE__ */ jsx19("label", {
1464
+ htmlFor: id,
1465
+ children: label
1466
+ }),
1467
+ /* @__PURE__ */ jsxs16("span", {
1468
+ className: "ja-select-wrap",
1469
+ children: [
1470
+ /* @__PURE__ */ jsx19("select", {
1471
+ id,
1472
+ className: "ja-select",
1473
+ value,
1474
+ onChange: (event) => onChange(Number(event.target.value)),
1475
+ children: options.map((size) => /* @__PURE__ */ jsx19("option", {
1476
+ value: size,
1477
+ children: size
1478
+ }, size))
1479
+ }),
1480
+ /* @__PURE__ */ jsx19(icons.chevronDown, {})
1481
+ ]
1482
+ })
1483
+ ]
1484
+ });
1485
+ }
1486
+ function pageWindow(page, pages) {
1487
+ if (pages <= 7)
1488
+ return Array.from({ length: pages }, (_, i) => i + 1);
1489
+ const near = [page - 1, page, page + 1].filter((p) => p > 1 && p < pages);
1490
+ const list = [1];
1491
+ if (near[0] > 2)
1492
+ list.push(null);
1493
+ list.push(...near);
1494
+ if (near[near.length - 1] < pages - 1)
1495
+ list.push(null);
1496
+ list.push(pages);
1497
+ return list;
1498
+ }
1499
+ function Pagination({ page, pages, onPage, summary, label = "Pages", pageSize, onPageSize, pageSizes }) {
1500
+ const sized = pageSize !== undefined && onPageSize !== undefined;
1501
+ if (pages <= 1 && !summary && !sized)
1502
+ return null;
1503
+ return /* @__PURE__ */ jsxs16("div", {
1504
+ className: "ja-pager",
1505
+ children: [
1506
+ /* @__PURE__ */ jsx19("span", {
1507
+ children: summary
1508
+ }),
1509
+ sized && /* @__PURE__ */ jsx19(PageSize, {
1510
+ value: pageSize,
1511
+ onChange: onPageSize,
1512
+ options: pageSizes
1513
+ }),
1514
+ pages > 1 && /* @__PURE__ */ jsx19("nav", {
1515
+ "aria-label": label,
1516
+ children: /* @__PURE__ */ jsxs16("ul", {
1517
+ className: "ja-pages",
1518
+ children: [
1519
+ page > 1 && /* @__PURE__ */ jsx19("li", {
1520
+ children: /* @__PURE__ */ jsx19("button", {
1521
+ type: "button",
1522
+ "aria-label": "Previous page",
1523
+ onClick: () => onPage(page - 1),
1524
+ children: /* @__PURE__ */ jsx19(icons.chevronLeft, {})
1525
+ })
1526
+ }),
1527
+ pageWindow(page, pages).map((p, i) => p === null ? /* @__PURE__ */ jsx19("li", {
1528
+ "aria-hidden": "true",
1529
+ className: "ja-muted",
1530
+ style: { alignSelf: "center" },
1531
+ children: "…"
1532
+ }, `gap-${i}`) : /* @__PURE__ */ jsx19("li", {
1533
+ children: /* @__PURE__ */ jsx19("button", {
1534
+ type: "button",
1535
+ "aria-current": p === page ? "page" : undefined,
1536
+ "aria-label": `Page ${p}`,
1537
+ onClick: () => p !== page && onPage(p),
1538
+ children: p
1539
+ })
1540
+ }, p)),
1541
+ page < pages && /* @__PURE__ */ jsx19("li", {
1542
+ children: /* @__PURE__ */ jsx19("button", {
1543
+ type: "button",
1544
+ "aria-label": "Next page",
1545
+ onClick: () => onPage(page + 1),
1546
+ children: /* @__PURE__ */ jsx19(icons.chevronRight, {})
1547
+ })
1548
+ })
1549
+ ]
1550
+ })
1551
+ })
1552
+ ]
1553
+ });
1554
+ }
1555
+ // src/admin/blocks/Status.tsx
1556
+ import { jsx as jsx20 } from "react/jsx-runtime";
1557
+ var PEOPLE_STATUS = {
1558
+ active: { label: "Active", tone: "good" },
1559
+ invited: { label: "Invited", tone: "warn" },
1560
+ suspended: { label: "Suspended", tone: "bad" }
1561
+ };
1562
+ function StatusBadge({ tone, children }) {
1563
+ return /* @__PURE__ */ jsx20("span", {
1564
+ className: "ja-status",
1565
+ "data-tone": tone,
1566
+ children
1567
+ });
1568
+ }
1569
+ // src/admin/blocks/ActivityFeed.tsx
1570
+ import { jsx as jsx21, jsxs as jsxs17 } from "react/jsx-runtime";
1571
+ function ActivityFeed({ items, loading = false, empty = "Nothing has happened yet." }) {
1572
+ if (loading)
1573
+ return /* @__PURE__ */ jsx21("ol", {
1574
+ className: "ja-feed",
1575
+ "aria-busy": "true",
1576
+ children: [0, 1, 2].map((i) => /* @__PURE__ */ jsxs17("li", {
1577
+ className: "ja-feed-item",
1578
+ "aria-hidden": "true",
1579
+ children: [
1580
+ /* @__PURE__ */ jsx21("span", {
1581
+ className: "ja-feed-icon"
1582
+ }),
1583
+ /* @__PURE__ */ jsxs17("span", {
1584
+ style: { flex: 1, display: "grid", gap: 8 },
1585
+ children: [
1586
+ /* @__PURE__ */ jsx21("span", {
1587
+ className: "ja-skeleton",
1588
+ style: { width: `${70 - i * 12}%` }
1589
+ }),
1590
+ /* @__PURE__ */ jsx21("span", {
1591
+ className: "ja-skeleton",
1592
+ style: { width: "30%", height: 10 }
1593
+ })
1594
+ ]
1595
+ })
1596
+ ]
1597
+ }, i))
1598
+ });
1599
+ if (items.length === 0)
1600
+ return /* @__PURE__ */ jsx21("p", {
1601
+ className: "ja-empty",
1602
+ children: empty
1603
+ });
1604
+ return /* @__PURE__ */ jsx21("ol", {
1605
+ className: "ja-feed",
1606
+ children: items.map((item, i) => /* @__PURE__ */ jsxs17("li", {
1607
+ style: { display: "contents" },
1608
+ children: [
1609
+ item.day && item.day !== items[i - 1]?.day && /* @__PURE__ */ jsx21("div", {
1610
+ className: "ja-feed-day",
1611
+ children: item.day
1612
+ }),
1613
+ /* @__PURE__ */ jsxs17("div", {
1614
+ className: "ja-feed-item",
1615
+ children: [
1616
+ /* @__PURE__ */ jsx21("span", {
1617
+ className: "ja-feed-icon",
1618
+ "data-tone": item.tone && item.tone !== "brand" ? item.tone : undefined,
1619
+ "aria-hidden": "true",
1620
+ children: item.icon
1621
+ }),
1622
+ /* @__PURE__ */ jsxs17("span", {
1623
+ children: [
1624
+ item.text,
1625
+ /* @__PURE__ */ jsx21("small", {
1626
+ children: item.datetime ? /* @__PURE__ */ jsx21("time", {
1627
+ dateTime: item.datetime,
1628
+ children: item.time
1629
+ }) : item.time
1630
+ })
1631
+ ]
1632
+ })
1633
+ ]
1634
+ })
1635
+ ]
1636
+ }, item.id))
1637
+ });
1638
+ }
1639
+ // src/admin/forms/Field.tsx
1640
+ import { useId as useId6 } from "react";
1641
+ import { jsx as jsx22, jsxs as jsxs18 } from "react/jsx-runtime";
1642
+ function Field({ label, hint, error, children }) {
1643
+ const id = useId6();
1644
+ const hintId = hint ? `${id}-hint` : undefined;
1645
+ const errorId = error ? `${id}-error` : undefined;
1646
+ const describedBy = [errorId, hintId].filter(Boolean).join(" ") || undefined;
1647
+ return /* @__PURE__ */ jsxs18("div", {
1648
+ className: "ja-field",
1649
+ children: [
1650
+ /* @__PURE__ */ jsx22("label", {
1651
+ className: "ja-field-label",
1652
+ htmlFor: id,
1653
+ children: label
1654
+ }),
1655
+ children({ id, "aria-describedby": describedBy, "aria-invalid": error ? true : undefined }),
1656
+ hint && /* @__PURE__ */ jsx22("p", {
1657
+ className: "ja-field-hint",
1658
+ id: hintId,
1659
+ children: hint
1660
+ }),
1661
+ error && /* @__PURE__ */ jsxs18("p", {
1662
+ className: "ja-field-error",
1663
+ id: errorId,
1664
+ role: "alert",
1665
+ children: [
1666
+ /* @__PURE__ */ jsx22("span", {
1667
+ className: "ja-error-mark",
1668
+ "aria-hidden": "true",
1669
+ children: "!"
1670
+ }),
1671
+ error
1672
+ ]
1673
+ })
1674
+ ]
1675
+ });
1676
+ }
1677
+ function TextInput({ label, hint, error, className, ...input }) {
1678
+ return /* @__PURE__ */ jsx22(Field, {
1679
+ label,
1680
+ hint,
1681
+ error,
1682
+ children: (ids) => /* @__PURE__ */ jsx22("input", {
1683
+ className: className ? `ja-input ${className}` : "ja-input",
1684
+ ...ids,
1685
+ ...input
1686
+ })
1687
+ });
1688
+ }
1689
+ function TextArea({ label, hint, error, className, ...input }) {
1690
+ return /* @__PURE__ */ jsx22(Field, {
1691
+ label,
1692
+ hint,
1693
+ error,
1694
+ children: (ids) => /* @__PURE__ */ jsx22("textarea", {
1695
+ className: className ? `ja-input ${className}` : "ja-input",
1696
+ rows: 3,
1697
+ ...ids,
1698
+ ...input
1699
+ })
1700
+ });
1701
+ }
1702
+ function Select({
1703
+ label,
1704
+ hint,
1705
+ error,
1706
+ options,
1707
+ className,
1708
+ ...select
1709
+ }) {
1710
+ return /* @__PURE__ */ jsx22(Field, {
1711
+ label,
1712
+ hint,
1713
+ error,
1714
+ children: (ids) => /* @__PURE__ */ jsxs18("span", {
1715
+ className: "ja-select-wrap",
1716
+ children: [
1717
+ /* @__PURE__ */ jsx22("select", {
1718
+ className: className ? `ja-select ${className}` : "ja-select",
1719
+ ...ids,
1720
+ ...select,
1721
+ children: options.map((option) => /* @__PURE__ */ jsx22("option", {
1722
+ value: option.value,
1723
+ children: option.label
1724
+ }, option.value))
1725
+ }),
1726
+ /* @__PURE__ */ jsx22(icons.chevronDown, {})
1727
+ ]
1728
+ })
1729
+ });
1730
+ }
1731
+ function Checkbox({
1732
+ label,
1733
+ hint,
1734
+ className,
1735
+ ...input
1736
+ }) {
1737
+ const id = useId6();
1738
+ return /* @__PURE__ */ jsxs18("div", {
1739
+ className: className ? `ja-check ${className}` : "ja-check",
1740
+ children: [
1741
+ /* @__PURE__ */ jsx22("input", {
1742
+ type: "checkbox",
1743
+ id,
1744
+ "aria-describedby": hint ? `${id}-hint` : undefined,
1745
+ ...input
1746
+ }),
1747
+ /* @__PURE__ */ jsxs18("label", {
1748
+ htmlFor: id,
1749
+ children: [
1750
+ label,
1751
+ hint && /* @__PURE__ */ jsx22("small", {
1752
+ id: `${id}-hint`,
1753
+ className: "ja-field-hint",
1754
+ children: hint
1755
+ })
1756
+ ]
1757
+ })
1758
+ ]
1759
+ });
1760
+ }
1761
+ function Switch({
1762
+ label,
1763
+ hint,
1764
+ checked,
1765
+ onChange,
1766
+ disabled
1767
+ }) {
1768
+ const id = useId6();
1769
+ return /* @__PURE__ */ jsxs18("div", {
1770
+ className: "ja-switch-row",
1771
+ children: [
1772
+ /* @__PURE__ */ jsxs18("span", {
1773
+ children: [
1774
+ /* @__PURE__ */ jsx22("span", {
1775
+ id: `${id}-label`,
1776
+ children: label
1777
+ }),
1778
+ hint && /* @__PURE__ */ jsx22("small", {
1779
+ id: `${id}-hint`,
1780
+ className: "ja-field-hint",
1781
+ children: hint
1782
+ })
1783
+ ]
1784
+ }),
1785
+ /* @__PURE__ */ jsx22("button", {
1786
+ type: "button",
1787
+ role: "switch",
1788
+ className: "ja-switch",
1789
+ "aria-checked": checked,
1790
+ "aria-labelledby": `${id}-label`,
1791
+ "aria-describedby": hint ? `${id}-hint` : undefined,
1792
+ disabled,
1793
+ onClick: () => onChange(!checked),
1794
+ children: /* @__PURE__ */ jsx22("span", {
1795
+ "aria-hidden": "true"
1796
+ })
1797
+ })
1798
+ ]
1799
+ });
1800
+ }
1801
+ // src/admin/forms/ConfirmDialog.tsx
1802
+ import { useEffect as useEffect4, useId as useId7, useRef as useRef3 } from "react";
1803
+ import { jsx as jsx23, jsxs as jsxs19 } from "react/jsx-runtime";
1804
+ function ConfirmDialog({
1805
+ open,
1806
+ title,
1807
+ description,
1808
+ confirmLabel,
1809
+ cancelLabel = "Cancel",
1810
+ danger = false,
1811
+ busy = false,
1812
+ onConfirm,
1813
+ onCancel,
1814
+ children
1815
+ }) {
1816
+ const ref = useRef3(null);
1817
+ const titleId = useId7();
1818
+ const descriptionId = useId7();
1819
+ useEffect4(() => {
1820
+ const dialog = ref.current;
1821
+ if (!dialog)
1822
+ return;
1823
+ if (open && !dialog.open)
1824
+ dialog.showModal();
1825
+ if (!open && dialog.open)
1826
+ dialog.close();
1827
+ }, [open]);
1828
+ return /* @__PURE__ */ jsx23("dialog", {
1829
+ ref,
1830
+ className: "ja-dialog",
1831
+ "aria-labelledby": titleId,
1832
+ "aria-describedby": description ? descriptionId : undefined,
1833
+ onCancel: (event) => {
1834
+ event.preventDefault();
1835
+ if (!busy)
1836
+ onCancel();
1837
+ },
1838
+ onClick: (event) => {
1839
+ if (event.target === ref.current && !busy)
1840
+ onCancel();
1841
+ },
1842
+ children: /* @__PURE__ */ jsxs19("form", {
1843
+ method: "dialog",
1844
+ className: "ja-dialog-box",
1845
+ onSubmit: (event) => {
1846
+ event.preventDefault();
1847
+ if (!busy)
1848
+ onConfirm();
1849
+ },
1850
+ children: [
1851
+ /* @__PURE__ */ jsx23("h2", {
1852
+ id: titleId,
1853
+ className: "ja-tile-title",
1854
+ children: title
1855
+ }),
1856
+ description && /* @__PURE__ */ jsx23("p", {
1857
+ id: descriptionId,
1858
+ className: "ja-dialog-text",
1859
+ children: description
1860
+ }),
1861
+ children,
1862
+ /* @__PURE__ */ jsxs19("div", {
1863
+ className: "ja-dialog-actions",
1864
+ children: [
1865
+ /* @__PURE__ */ jsx23(Button, {
1866
+ variant: "quiet",
1867
+ onClick: onCancel,
1868
+ disabled: busy,
1869
+ children: cancelLabel
1870
+ }),
1871
+ /* @__PURE__ */ jsx23(Button, {
1872
+ type: "submit",
1873
+ variant: danger ? "danger" : "primary",
1874
+ "aria-disabled": busy || undefined,
1875
+ children: busy ? `${confirmLabel}…` : confirmLabel
1876
+ })
1877
+ ]
1878
+ })
1879
+ ]
1880
+ })
1881
+ });
1882
+ }
1883
+ // src/admin/forms/People.tsx
1884
+ import { useState as useState6 } from "react";
1885
+ import { jsx as jsx24, jsxs as jsxs20, Fragment as Fragment7 } from "react/jsx-runtime";
1886
+ function RolePicker({ name, roles, value, onChange, confirm, disabled }) {
1887
+ const [pending, setPending] = useState6(null);
1888
+ const [busy, setBusy] = useState6(false);
1889
+ const apply = async (role) => {
1890
+ setBusy(true);
1891
+ try {
1892
+ await onChange(role);
1893
+ } finally {
1894
+ setBusy(false);
1895
+ setPending(null);
1896
+ }
1897
+ };
1898
+ const label = (role) => roles.find((r) => r.value === role)?.label ?? role;
1899
+ return /* @__PURE__ */ jsxs20(Fragment7, {
1900
+ children: [
1901
+ /* @__PURE__ */ jsxs20("span", {
1902
+ className: "ja-select-wrap ja-select-inline",
1903
+ children: [
1904
+ /* @__PURE__ */ jsx24("select", {
1905
+ className: "ja-select",
1906
+ "aria-label": `Role for ${name}`,
1907
+ value,
1908
+ disabled: disabled || busy,
1909
+ onChange: (event) => {
1910
+ const role = event.target.value;
1911
+ if (confirm?.[role])
1912
+ setPending(role);
1913
+ else
1914
+ apply(role);
1915
+ },
1916
+ children: roles.map((role) => /* @__PURE__ */ jsx24("option", {
1917
+ value: role.value,
1918
+ children: role.label
1919
+ }, role.value))
1920
+ }),
1921
+ /* @__PURE__ */ jsx24(icons.chevronDown, {})
1922
+ ]
1923
+ }),
1924
+ pending && /* @__PURE__ */ jsx24(ConfirmDialog, {
1925
+ open: true,
1926
+ title: `Make ${name} ${articleFor(label(pending))} ${label(pending)}?`,
1927
+ description: confirm?.[pending],
1928
+ confirmLabel: `Make ${name} ${articleFor(label(pending))} ${label(pending)}`,
1929
+ busy,
1930
+ onConfirm: () => void apply(pending),
1931
+ onCancel: () => setPending(null)
1932
+ })
1933
+ ]
1934
+ });
1935
+ }
1936
+ function articleFor(word) {
1937
+ return /^[aeiou]/i.test(word) ? "an" : "a";
1938
+ }
1939
+ function BanControl({ name, suspended, onSuspend, onRestore }) {
1940
+ const [open, setOpen] = useState6(false);
1941
+ const [reason, setReason] = useState6("");
1942
+ const [busy, setBusy] = useState6(false);
1943
+ const run = async (action) => {
1944
+ setBusy(true);
1945
+ try {
1946
+ await action();
1947
+ setOpen(false);
1948
+ setReason("");
1949
+ } finally {
1950
+ setBusy(false);
1951
+ }
1952
+ };
1953
+ if (suspended)
1954
+ return /* @__PURE__ */ jsx24("button", {
1955
+ type: "button",
1956
+ className: "ja-row-action",
1957
+ "aria-label": `Restore ${name}`,
1958
+ disabled: busy,
1959
+ onClick: () => void run(onRestore),
1960
+ children: "Restore"
1961
+ });
1962
+ return /* @__PURE__ */ jsxs20(Fragment7, {
1963
+ children: [
1964
+ /* @__PURE__ */ jsx24("button", {
1965
+ type: "button",
1966
+ className: "ja-row-action",
1967
+ "data-variant": "danger",
1968
+ "aria-label": `Suspend ${name}`,
1969
+ onClick: () => setOpen(true),
1970
+ children: "Suspend"
1971
+ }),
1972
+ /* @__PURE__ */ jsx24(ConfirmDialog, {
1973
+ open,
1974
+ danger: true,
1975
+ title: `Suspend ${name}?`,
1976
+ description: "They are signed out at once and can't sign in until someone restores them.",
1977
+ confirmLabel: `Suspend ${name}`,
1978
+ busy,
1979
+ onConfirm: () => void run(() => onSuspend(reason.trim())),
1980
+ onCancel: () => setOpen(false),
1981
+ children: /* @__PURE__ */ jsx24(TextArea, {
1982
+ label: "Reason (optional)",
1983
+ hint: "Only admins see it.",
1984
+ value: reason,
1985
+ maxLength: 200,
1986
+ onChange: (e) => setReason(e.target.value)
1987
+ })
1988
+ })
1989
+ ]
1990
+ });
1991
+ }
1992
+ // src/admin/blocks/BarChart.tsx
1993
+ import { useId as useId8, useState as useState7 } from "react";
1994
+ import { jsx as jsx25, jsxs as jsxs21, Fragment as Fragment8 } from "react/jsx-runtime";
1995
+ function barLayout(groups, perGroup, width, gap = 0.28) {
1996
+ const group = width / Math.max(groups, 1);
1997
+ const inner = group * (1 - gap);
1998
+ const bar = inner / perGroup;
1999
+ return { group, bar, offset: (group - inner) / 2 };
2000
+ }
2001
+ function BarChart({ labels, series, label, height = 180, format = (v) => v.toLocaleString("en-US") }) {
2002
+ const id = useId8();
2003
+ const width = 400;
2004
+ const max = Math.max(1, ...series.flatMap((s) => s.values));
2005
+ const { group, bar, offset } = barLayout(labels.length, series.length, width);
2006
+ const fills = ["var(--brand)", "color-mix(in oklab, var(--brand) 32%, var(--tile))"];
2007
+ const [active, setActive] = useState7(null);
2008
+ const barHeight = (value) => Math.max(0, value) / max * (height - 4);
2009
+ const groupTop = (g) => height - Math.max(...series.map((s) => barHeight(s.values[g] ?? 0)));
2010
+ return /* @__PURE__ */ jsxs21("figure", {
2011
+ className: "ja-chart",
2012
+ children: [
2013
+ series.length === 2 && /* @__PURE__ */ jsx25("div", {
2014
+ className: "ja-legend",
2015
+ "aria-hidden": "true",
2016
+ children: series.map((s, i) => /* @__PURE__ */ jsxs21("span", {
2017
+ children: [
2018
+ /* @__PURE__ */ jsx25("i", {
2019
+ style: { background: fills[i] }
2020
+ }),
2021
+ s.label
2022
+ ]
2023
+ }, s.label))
2024
+ }),
2025
+ /* @__PURE__ */ jsxs21("div", {
2026
+ className: "ja-chart-plot",
2027
+ children: [
2028
+ /* @__PURE__ */ jsx25("svg", {
2029
+ viewBox: `0 0 ${width} ${height}`,
2030
+ preserveAspectRatio: "none",
2031
+ width: "100%",
2032
+ height,
2033
+ role: "img",
2034
+ "aria-label": label,
2035
+ children: labels.map((name, g) => series.map((s, i) => {
2036
+ const value = s.values[g] ?? 0;
2037
+ const h = barHeight(value);
2038
+ return /* @__PURE__ */ jsx25("rect", {
2039
+ x: g * group + offset + i * bar + 1,
2040
+ y: height - h,
2041
+ width: Math.max(1, bar - 2),
2042
+ height: h,
2043
+ rx: Math.min(6, bar / 3),
2044
+ fill: fills[i],
2045
+ opacity: active === null || active === g ? 1 : 0.45
2046
+ }, `${id}-${name}-${s.label}`);
2047
+ }))
2048
+ }),
2049
+ /* @__PURE__ */ jsx25(ChartPoints, {
2050
+ names: labels.map((name, g) => `${name}: ${series.map((s) => series.length > 1 ? `${s.label} ${format(s.values[g] ?? 0)}` : format(s.values[g] ?? 0)).join(", ")}`),
2051
+ centers: labels.map((_, g) => (g + 0.5) * group * 100 / width),
2052
+ width: group * 100 / width,
2053
+ active,
2054
+ onActive: setActive,
2055
+ tipTop: (g) => groupTop(g) / height * 100,
2056
+ tip: (g) => /* @__PURE__ */ jsxs21(Fragment8, {
2057
+ children: [
2058
+ /* @__PURE__ */ jsx25("span", {
2059
+ children: labels[g]
2060
+ }),
2061
+ series.map((s, i) => /* @__PURE__ */ jsxs21("strong", {
2062
+ children: [
2063
+ series.length > 1 && /* @__PURE__ */ jsx25("i", {
2064
+ style: { background: fills[i] }
2065
+ }),
2066
+ format(s.values[g] ?? 0)
2067
+ ]
2068
+ }, s.label))
2069
+ ]
2070
+ })
2071
+ })
2072
+ ]
2073
+ }),
2074
+ /* @__PURE__ */ jsx25("div", {
2075
+ className: "ja-chart-labels ja-bar-labels",
2076
+ "aria-hidden": "true",
2077
+ children: labels.map((name) => /* @__PURE__ */ jsx25("span", {
2078
+ children: name
2079
+ }, name))
2080
+ }),
2081
+ /* @__PURE__ */ jsx25("div", {
2082
+ className: "ja-sr",
2083
+ children: /* @__PURE__ */ jsxs21("table", {
2084
+ children: [
2085
+ /* @__PURE__ */ jsx25("caption", {
2086
+ children: label
2087
+ }),
2088
+ /* @__PURE__ */ jsx25("thead", {
2089
+ children: /* @__PURE__ */ jsxs21("tr", {
2090
+ children: [
2091
+ /* @__PURE__ */ jsx25("td", {}),
2092
+ series.map((s) => /* @__PURE__ */ jsx25("th", {
2093
+ scope: "col",
2094
+ children: s.label
2095
+ }, s.label))
2096
+ ]
2097
+ })
2098
+ }),
2099
+ /* @__PURE__ */ jsx25("tbody", {
2100
+ children: labels.map((name, g) => /* @__PURE__ */ jsxs21("tr", {
2101
+ children: [
2102
+ /* @__PURE__ */ jsx25("th", {
2103
+ scope: "row",
2104
+ children: name
2105
+ }),
2106
+ series.map((s) => /* @__PURE__ */ jsx25("td", {
2107
+ children: format(s.values[g] ?? 0)
2108
+ }, s.label))
2109
+ ]
2110
+ }, name))
2111
+ })
2112
+ ]
2113
+ })
2114
+ })
2115
+ ]
2116
+ });
2117
+ }
2118
+ export {
2119
+ ActivityFeed,
2120
+ AdminShell,
2121
+ Avatar,
2122
+ AvatarStack,
2123
+ BanControl,
2124
+ BarChart,
2125
+ Bento,
2126
+ Button,
2127
+ Checkbox,
2128
+ ConfirmDialog,
2129
+ DataTable,
2130
+ DeltaText,
2131
+ Dock,
2132
+ Field,
2133
+ FilterTabs,
2134
+ HeroChartTile,
2135
+ IconButton,
2136
+ LineChart,
2137
+ Meter,
2138
+ PAGE_SIZES,
2139
+ PEOPLE_STATUS,
2140
+ PageHeader,
2141
+ PageSize,
2142
+ Pagination,
2143
+ PersonCell,
2144
+ RolePicker,
2145
+ RowAction,
2146
+ SegmentedControl,
2147
+ Select,
2148
+ Sidebar,
2149
+ StatTile,
2150
+ StatusBadge,
2151
+ Switch,
2152
+ TextArea,
2153
+ TextInput,
2154
+ ThemeToggle,
2155
+ Tile,
2156
+ TopSearch,
2157
+ byNumber,
2158
+ byText,
2159
+ contrastRatio,
2160
+ icons,
2161
+ initials,
2162
+ inkOn,
2163
+ nextSort,
2164
+ plainLink,
2165
+ sortRows,
2166
+ useAdminTheme,
2167
+ useToast
2168
+ };