admin-lib-cms 1.0.5

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.mjs ADDED
@@ -0,0 +1,2223 @@
1
+ "use client";
2
+ import {
3
+ generateEmailTemplate
4
+ } from "./chunk-CQW7KMB2.mjs";
5
+
6
+ // src/provider.tsx
7
+ import {
8
+ createContext,
9
+ useCallback,
10
+ useContext,
11
+ useEffect,
12
+ useMemo,
13
+ useRef,
14
+ useState
15
+ } from "react";
16
+ import { jsx } from "react/jsx-runtime";
17
+ var CmsContext = createContext(null);
18
+ function useCmsContext() {
19
+ const ctx = useContext(CmsContext);
20
+ if (!ctx) throw new Error("useCms must be used inside <CmsProvider>");
21
+ return ctx;
22
+ }
23
+ function useCmsOptional() {
24
+ return useContext(CmsContext);
25
+ }
26
+ function CmsProvider({ config, adapter, children, iconMap }) {
27
+ const [overrides, setOverrides] = useState({});
28
+ const [savedOverrides, setSavedOverrides] = useState({});
29
+ const [selectedId, setSelectedIdRaw] = useState(null);
30
+ const [editMode, setEditMode] = useState(false);
31
+ const [collectionChangedAt, setCollectionChangedAt] = useState(0);
32
+ const registryRef = useRef(/* @__PURE__ */ new Map());
33
+ useEffect(() => {
34
+ if (typeof window === "undefined" || typeof BroadcastChannel === "undefined") return;
35
+ const bc = new BroadcastChannel("admin-cms:collection-changed");
36
+ bc.onmessage = () => setCollectionChangedAt(Date.now());
37
+ return () => bc.close();
38
+ }, []);
39
+ const notifyCollectionChanged = useCallback(() => {
40
+ setCollectionChangedAt(Date.now());
41
+ if (typeof BroadcastChannel !== "undefined") {
42
+ const bc = new BroadcastChannel("admin-cms:collection-changed");
43
+ bc.postMessage({ at: Date.now() });
44
+ bc.close();
45
+ }
46
+ }, []);
47
+ useEffect(() => {
48
+ if (typeof window === "undefined") return;
49
+ const params = new URLSearchParams(window.location.search);
50
+ if (params.get("__cms") === "edit") setEditMode(true);
51
+ }, []);
52
+ useEffect(() => {
53
+ let cancelled = false;
54
+ adapter.getOverrides().then((o) => {
55
+ if (cancelled) return;
56
+ setOverrides(o);
57
+ setSavedOverrides(o);
58
+ });
59
+ return () => {
60
+ cancelled = true;
61
+ };
62
+ }, [adapter]);
63
+ useEffect(() => {
64
+ if (!editMode || typeof window === "undefined") return;
65
+ const parent = window.parent;
66
+ if (!parent || parent === window) return;
67
+ const send = (msg) => parent.postMessage({ __cms: true, ...msg }, "*");
68
+ send({ type: "cms:ready" });
69
+ const onMsg = (e) => {
70
+ const data = e.data;
71
+ if (!data || !data.__cms) return;
72
+ if (data.type === "cms:set-override") {
73
+ setOverrides((prev) => ({ ...prev, [data.id]: data.value }));
74
+ } else if (data.type === "cms:set-all-overrides") {
75
+ setOverrides(data.overrides);
76
+ }
77
+ };
78
+ window.addEventListener("message", onMsg);
79
+ return () => window.removeEventListener("message", onMsg);
80
+ }, [editMode]);
81
+ const setSelectedId = useCallback(
82
+ (id) => {
83
+ setSelectedIdRaw(id);
84
+ if (editMode && typeof window !== "undefined" && window.parent && window.parent !== window) {
85
+ window.parent.postMessage(
86
+ { __cms: true, type: "cms:select", id },
87
+ "*"
88
+ );
89
+ }
90
+ },
91
+ [editMode]
92
+ );
93
+ const registerEditable = useCallback((meta) => {
94
+ registryRef.current.set(meta.id, meta);
95
+ if (typeof window !== "undefined" && window.parent && window.parent !== window) {
96
+ window.parent.postMessage(
97
+ {
98
+ __cms: true,
99
+ type: "cms:register",
100
+ items: Array.from(registryRef.current.values())
101
+ },
102
+ "*"
103
+ );
104
+ }
105
+ }, []);
106
+ const unregisterEditable = useCallback((id) => {
107
+ registryRef.current.delete(id);
108
+ if (typeof window !== "undefined" && window.parent && window.parent !== window) {
109
+ window.parent.postMessage(
110
+ {
111
+ __cms: true,
112
+ type: "cms:register",
113
+ items: Array.from(registryRef.current.values())
114
+ },
115
+ "*"
116
+ );
117
+ }
118
+ }, []);
119
+ const setOverride = useCallback((id, value2) => {
120
+ setOverrides((prev) => ({ ...prev, [id]: value2 }));
121
+ }, []);
122
+ const save = useCallback(async () => {
123
+ await adapter.setOverrides(overrides);
124
+ setSavedOverrides(overrides);
125
+ }, [adapter, overrides]);
126
+ const reset = useCallback(
127
+ async (id) => {
128
+ if (id) {
129
+ setOverrides((prev) => {
130
+ const next = { ...prev };
131
+ delete next[id];
132
+ return next;
133
+ });
134
+ } else {
135
+ setOverrides({});
136
+ }
137
+ },
138
+ []
139
+ );
140
+ const isDirty = useMemo(
141
+ () => JSON.stringify(overrides) !== JSON.stringify(savedOverrides),
142
+ [overrides, savedOverrides]
143
+ );
144
+ const getRegistered = useCallback(
145
+ () => Array.from(registryRef.current.values()),
146
+ []
147
+ );
148
+ const value = useMemo(() => ({
149
+ config,
150
+ adapter,
151
+ overrides,
152
+ editMode,
153
+ selectedId,
154
+ setSelectedId,
155
+ setOverride,
156
+ registerEditable,
157
+ unregisterEditable,
158
+ getRegistered,
159
+ save,
160
+ reset,
161
+ isDirty,
162
+ iconMap,
163
+ uploadImage: adapter.uploadImage?.bind(adapter),
164
+ collectionChangedAt,
165
+ notifyCollectionChanged
166
+ }), [config, adapter, overrides, editMode, selectedId, setSelectedId, setOverride, registerEditable, unregisterEditable, getRegistered, save, reset, isDirty, iconMap, collectionChangedAt, notifyCollectionChanged]);
167
+ return /* @__PURE__ */ jsx(CmsContext.Provider, { value, children });
168
+ }
169
+ function useSubmit(formId) {
170
+ const ctx = useContext(CmsContext);
171
+ return async (data) => {
172
+ const submission = {
173
+ id: crypto.randomUUID(),
174
+ formId,
175
+ submittedAt: (/* @__PURE__ */ new Date()).toISOString(),
176
+ data,
177
+ read: false
178
+ };
179
+ if (ctx?.adapter) {
180
+ await ctx.adapter.saveSubmission(submission);
181
+ } else {
182
+ const KEY = "admin-cms:submissions";
183
+ const list = (() => {
184
+ try {
185
+ return JSON.parse(localStorage.getItem(KEY) ?? "[]");
186
+ } catch {
187
+ return [];
188
+ }
189
+ })();
190
+ list.unshift(submission);
191
+ localStorage.setItem(KEY, JSON.stringify(list));
192
+ }
193
+ };
194
+ }
195
+
196
+ // src/editable.tsx
197
+ import { createElement, useEffect as useEffect2 } from "react";
198
+ import { jsx as jsx2 } from "react/jsx-runtime";
199
+ function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength) {
200
+ const ctx = useCmsOptional();
201
+ useEffect2(() => {
202
+ if (!ctx) return;
203
+ ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength });
204
+ return () => ctx.unregisterEditable(id);
205
+ }, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength]);
206
+ return ctx;
207
+ }
208
+ function editableClasses(active, selected) {
209
+ if (!active) return "";
210
+ return [
211
+ "outline-dashed outline-2 outline-offset-2 cursor-pointer transition-colors",
212
+ selected ? "outline-blue-500 bg-blue-500/5" : "outline-blue-400/60 hover:outline-blue-500"
213
+ ].join(" ");
214
+ }
215
+ function EditableText({
216
+ id,
217
+ label,
218
+ section,
219
+ pageId,
220
+ children,
221
+ as = "span",
222
+ className
223
+ }) {
224
+ const ctx = useRegister(id, "text", label, section, pageId, children);
225
+ const value = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? String(ctx.overrides[id] ?? "") : children;
226
+ const active = !!ctx?.editMode;
227
+ const selected = ctx?.selectedId === id;
228
+ const onClick = (e) => {
229
+ if (!active || !ctx) return;
230
+ e.preventDefault();
231
+ e.stopPropagation();
232
+ ctx.setSelectedId(id);
233
+ };
234
+ return createElement(
235
+ as,
236
+ {
237
+ className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
238
+ "data-cms-id": id,
239
+ onClick: active ? onClick : void 0
240
+ },
241
+ value
242
+ );
243
+ }
244
+ function EditableImage({
245
+ id,
246
+ label,
247
+ section,
248
+ pageId,
249
+ src,
250
+ alt,
251
+ className,
252
+ width,
253
+ height
254
+ }) {
255
+ const ctx = useRegister(id, "image", label, section, pageId, src);
256
+ const value = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? String(ctx.overrides[id] ?? src) : src;
257
+ const active = !!ctx?.editMode;
258
+ const selected = ctx?.selectedId === id;
259
+ const onClick = (e) => {
260
+ if (!active || !ctx) return;
261
+ e.preventDefault();
262
+ e.stopPropagation();
263
+ ctx.setSelectedId(id);
264
+ };
265
+ return /* @__PURE__ */ jsx2(
266
+ "img",
267
+ {
268
+ src: value,
269
+ alt,
270
+ width,
271
+ height,
272
+ "data-cms-id": id,
273
+ onClick: active ? onClick : void 0,
274
+ className: [className, editableClasses(active, selected)].filter(Boolean).join(" ")
275
+ }
276
+ );
277
+ }
278
+ function EditableLink({
279
+ id,
280
+ label,
281
+ section,
282
+ pageId,
283
+ href,
284
+ children,
285
+ className
286
+ }) {
287
+ const ctx = useRegister(id, "link", label, section, pageId, { href, text: children });
288
+ const override = ctx?.overrides[id];
289
+ const hrefValue = override?.href ?? href;
290
+ const textValue = override?.text ?? children;
291
+ const active = !!ctx?.editMode;
292
+ const selected = ctx?.selectedId === id;
293
+ const onClick = (e) => {
294
+ if (!active || !ctx) return;
295
+ e.preventDefault();
296
+ e.stopPropagation();
297
+ ctx.setSelectedId(id);
298
+ };
299
+ return /* @__PURE__ */ jsx2(
300
+ "a",
301
+ {
302
+ href: hrefValue,
303
+ "data-cms-id": id,
304
+ onClick: active ? onClick : void 0,
305
+ className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
306
+ children: textValue
307
+ }
308
+ );
309
+ }
310
+ function EditableList({
311
+ id,
312
+ label,
313
+ section,
314
+ pageId,
315
+ initialItems,
316
+ renderItem,
317
+ itemSchema,
318
+ fixedLength,
319
+ className,
320
+ listClassName
321
+ }) {
322
+ const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength);
323
+ const rawValue = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? ctx.overrides[id] : initialItems;
324
+ const value = Array.isArray(rawValue) ? rawValue : initialItems;
325
+ const active = !!ctx?.editMode;
326
+ const selected = ctx?.selectedId === id;
327
+ const onClick = (e) => {
328
+ if (!active || !ctx) return;
329
+ e.preventDefault();
330
+ e.stopPropagation();
331
+ ctx.setSelectedId(id);
332
+ };
333
+ return /* @__PURE__ */ jsx2(
334
+ "div",
335
+ {
336
+ "data-cms-id": id,
337
+ onClick: active ? onClick : void 0,
338
+ className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
339
+ children: /* @__PURE__ */ jsx2("div", { className: listClassName, children: value.map(renderItem) })
340
+ }
341
+ );
342
+ }
343
+
344
+ // src/admin/AdminApp.tsx
345
+ import { useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef2, useState as useState4 } from "react";
346
+ import {
347
+ FileText,
348
+ Boxes,
349
+ Settings as SettingsIcon,
350
+ Pencil,
351
+ Plus,
352
+ Trash2,
353
+ X,
354
+ Upload,
355
+ RotateCcw,
356
+ Monitor,
357
+ Tablet,
358
+ Smartphone,
359
+ PanelLeftClose,
360
+ PanelLeftOpen,
361
+ Search,
362
+ ChevronDown,
363
+ Inbox,
364
+ RefreshCw,
365
+ Eye,
366
+ EyeOff,
367
+ ChevronLeft,
368
+ ChevronRight,
369
+ SlidersHorizontal,
370
+ LogOut
371
+ } from "lucide-react";
372
+ import { CreditCard as CreditCard2 } from "lucide-react";
373
+
374
+ // src/subscription/SubscriptionProvider.tsx
375
+ import { createContext as createContext2, useContext as useContext2, useState as useState2, useCallback as useCallback2, useEffect as useEffect3 } from "react";
376
+ import { jsx as jsx3 } from "react/jsx-runtime";
377
+ var SubscriptionContext = createContext2(void 0);
378
+ function useSubscriptionContext() {
379
+ const ctx = useContext2(SubscriptionContext);
380
+ if (!ctx) {
381
+ throw new Error("useSubscriptionContext must be used within a SubscriptionProvider");
382
+ }
383
+ return ctx;
384
+ }
385
+ function useSubscription() {
386
+ return useSubscriptionContext();
387
+ }
388
+ function SubscriptionProvider({
389
+ children,
390
+ apiUrl,
391
+ projectId,
392
+ email
393
+ }) {
394
+ const [subscription, setSubscription] = useState2(null);
395
+ const [loading, setLoading] = useState2(true);
396
+ const [error, setError] = useState2(null);
397
+ const fetchSubscription = useCallback2(
398
+ async (silent = false) => {
399
+ if (!apiUrl || !projectId) {
400
+ setLoading(false);
401
+ return;
402
+ }
403
+ if (!silent) setLoading(true);
404
+ setError(null);
405
+ try {
406
+ const res = await fetch(`${apiUrl}/api/validate-subscription`, {
407
+ method: "POST",
408
+ headers: { "Content-Type": "application/json" },
409
+ body: JSON.stringify({ projectId })
410
+ });
411
+ if (!res.ok) throw new Error(`Server error: ${res.status}`);
412
+ const data = await res.json();
413
+ setSubscription({
414
+ subscriptionStatus: data.valid ? data.status : "inactive",
415
+ currentPeriodEnd: data.expiryDate,
416
+ customerEmail: email,
417
+ subscriptionId: data._id,
418
+ stripeCustomerId: data.stripeCustomerId,
419
+ stripePaymentLink: data.stripePaymentLink,
420
+ valid: data.valid
421
+ });
422
+ } catch (err) {
423
+ console.error("SubscriptionProvider Error:", err);
424
+ setError(err.message || "Failed to fetch subscription");
425
+ setSubscription({ subscriptionStatus: "active", valid: true });
426
+ } finally {
427
+ setLoading(false);
428
+ }
429
+ },
430
+ [apiUrl, projectId, email]
431
+ );
432
+ useEffect3(() => {
433
+ fetchSubscription();
434
+ const handleFocus = () => {
435
+ fetchSubscription(true);
436
+ };
437
+ window.addEventListener("focus", handleFocus);
438
+ let intervalId;
439
+ if (subscription && !subscription.valid) {
440
+ intervalId = setInterval(() => {
441
+ fetchSubscription(true);
442
+ }, 1e4);
443
+ }
444
+ return () => {
445
+ window.removeEventListener("focus", handleFocus);
446
+ if (intervalId) clearInterval(intervalId);
447
+ };
448
+ }, [fetchSubscription, subscription?.valid]);
449
+ const value = {
450
+ subscription,
451
+ loading,
452
+ error,
453
+ refetch: fetchSubscription,
454
+ isSubscriptionActive: subscription?.valid ?? true,
455
+ config: { apiUrl, projectId }
456
+ };
457
+ return /* @__PURE__ */ jsx3(SubscriptionContext.Provider, { value, children });
458
+ }
459
+
460
+ // src/subscription/SubscriptionPage.tsx
461
+ import { useState as useState3 } from "react";
462
+ import { CreditCard, ExternalLink, Settings, AlertTriangle, CheckCircle2 } from "lucide-react";
463
+ import { jsx as jsx4, jsxs } from "react/jsx-runtime";
464
+ function SubscriptionPage() {
465
+ const { subscription, loading, config } = useSubscription();
466
+ const [actionLoading, setActionLoading] = useState3(null);
467
+ const status = subscription?.subscriptionStatus || "inactive";
468
+ const isValid = subscription?.valid ?? false;
469
+ const handleSubscribe = () => {
470
+ if (!subscription?.stripePaymentLink) {
471
+ alert("No payment link found. Please contact support.");
472
+ return;
473
+ }
474
+ const raw = subscription.stripePaymentLink;
475
+ const url = raw.startsWith("http") ? raw : `https://buy.stripe.com/${raw}`;
476
+ window.open(url, "_blank");
477
+ };
478
+ const handleManageBilling = async () => {
479
+ if (!subscription?.stripeCustomerId) {
480
+ alert("No customer ID available. Please contact support.");
481
+ return;
482
+ }
483
+ setActionLoading("billing");
484
+ try {
485
+ const returnUrl = window.location.href;
486
+ const apiUrl = config.apiUrl || "https://dev-soft-admin-sigma.vercel.app";
487
+ const res = await fetch(`${apiUrl}/api/create-billing-session`, {
488
+ method: "POST",
489
+ headers: { "Content-Type": "application/json" },
490
+ body: JSON.stringify({
491
+ customerId: subscription.stripeCustomerId,
492
+ returnUrl
493
+ })
494
+ });
495
+ if (!res.ok) throw new Error(`Server error: ${res.status}`);
496
+ const data = await res.json();
497
+ if (data.url) {
498
+ window.open(data.url, "_blank");
499
+ } else {
500
+ alert("Could not create billing session.");
501
+ }
502
+ } catch (err) {
503
+ alert(`Portal failed: ${err.message}`);
504
+ } finally {
505
+ setActionLoading(null);
506
+ }
507
+ };
508
+ if (loading && !subscription) {
509
+ return /* @__PURE__ */ jsx4("div", { className: "flex h-full min-h-[500px] w-full items-center justify-center bg-slate-50", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-3 text-slate-500", children: [
510
+ /* @__PURE__ */ jsx4("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-indigo-200 border-t-indigo-600" }),
511
+ /* @__PURE__ */ jsx4("p", { className: "text-sm font-medium", children: "Verifying subscription..." })
512
+ ] }) });
513
+ }
514
+ return /* @__PURE__ */ jsx4("div", { className: "flex min-h-screen w-full flex-col items-center justify-center bg-slate-50 p-6", children: /* @__PURE__ */ jsxs("div", { className: "w-full max-w-md overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-xl", children: [
515
+ /* @__PURE__ */ jsxs("div", { className: `p-8 text-center ${isValid ? "bg-emerald-50" : "bg-rose-50"}`, children: [
516
+ /* @__PURE__ */ jsx4("div", { className: "mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-white shadow-sm", children: isValid ? /* @__PURE__ */ jsx4(CheckCircle2, { className: "h-8 w-8 text-emerald-500" }) : /* @__PURE__ */ jsx4(AlertTriangle, { className: "h-8 w-8 text-rose-500" }) }),
517
+ /* @__PURE__ */ jsx4("h2", { className: "text-2xl font-bold text-slate-900 tracking-tight", children: isValid ? "Subscription Active" : "Subscription Inactive" }),
518
+ /* @__PURE__ */ jsx4("p", { className: "mt-2 text-sm text-slate-600", children: isValid ? "Your subscription is currently active and in good standing." : "Your project requires an active subscription to access the administration panel." })
519
+ ] }),
520
+ /* @__PURE__ */ jsxs("div", { className: "p-8", children: [
521
+ /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
522
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between rounded-xl bg-slate-50 p-4 border border-slate-100", children: [
523
+ /* @__PURE__ */ jsx4("span", { className: "text-sm font-medium text-slate-500", children: "Status" }),
524
+ /* @__PURE__ */ jsx4("span", { className: `inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold capitalize ${isValid ? "bg-emerald-100 text-emerald-700" : "bg-rose-100 text-rose-700"}`, children: status })
525
+ ] }),
526
+ subscription?.currentPeriodEnd && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between rounded-xl bg-slate-50 p-4 border border-slate-100", children: [
527
+ /* @__PURE__ */ jsx4("span", { className: "text-sm font-medium text-slate-500", children: "Next Billing Date" }),
528
+ /* @__PURE__ */ jsx4("span", { className: "text-sm font-semibold text-slate-900", children: new Date(subscription.currentPeriodEnd).toLocaleDateString() })
529
+ ] })
530
+ ] }),
531
+ /* @__PURE__ */ jsxs("div", { className: "mt-8 space-y-3", children: [
532
+ !isValid && /* @__PURE__ */ jsxs(
533
+ "button",
534
+ {
535
+ onClick: handleSubscribe,
536
+ className: "group flex w-full items-center justify-center gap-2 rounded-xl bg-indigo-600 px-4 py-3.5 text-sm font-semibold text-white shadow-sm transition-all hover:bg-indigo-700 hover:shadow",
537
+ children: [
538
+ /* @__PURE__ */ jsx4(CreditCard, { className: "h-4 w-4" }),
539
+ "Pay Now to Restore Access",
540
+ /* @__PURE__ */ jsx4(ExternalLink, { className: "h-3.5 w-3.5 opacity-70 transition-transform group-hover:translate-x-0.5" })
541
+ ]
542
+ }
543
+ ),
544
+ /* @__PURE__ */ jsxs(
545
+ "button",
546
+ {
547
+ onClick: handleManageBilling,
548
+ disabled: actionLoading === "billing",
549
+ className: "group flex w-full items-center justify-center gap-2 rounded-xl border border-slate-200 bg-white px-4 py-3.5 text-sm font-semibold text-slate-700 shadow-sm transition-all hover:bg-slate-50 hover:text-slate-900 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 disabled:opacity-50",
550
+ children: [
551
+ actionLoading === "billing" ? /* @__PURE__ */ jsx4("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-slate-300 border-t-slate-600" }) : /* @__PURE__ */ jsx4(Settings, { className: "h-4 w-4 text-slate-400 group-hover:text-slate-600" }),
552
+ "Manage Billing & Invoices"
553
+ ]
554
+ }
555
+ )
556
+ ] })
557
+ ] })
558
+ ] }) });
559
+ }
560
+
561
+ // src/admin/AdminApp.tsx
562
+ import { Fragment, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
563
+ async function handleImageFile(file, onUrl, uploadImage) {
564
+ if (uploadImage) {
565
+ try {
566
+ const url = await uploadImage(file);
567
+ onUrl(url);
568
+ } catch (err) {
569
+ console.error("Image upload failed:", err);
570
+ }
571
+ return;
572
+ }
573
+ const reader = new FileReader();
574
+ reader.onload = (ev) => onUrl(ev.target?.result);
575
+ reader.readAsDataURL(file);
576
+ }
577
+ function AdminApp({ apiUrl, projectId, email }) {
578
+ if (projectId) {
579
+ return /* @__PURE__ */ jsx5(SubscriptionProvider, { apiUrl, projectId, email, children: /* @__PURE__ */ jsx5(AdminAppContent, {}) });
580
+ }
581
+ return /* @__PURE__ */ jsx5(AdminAppContent, {});
582
+ }
583
+ function AdminAppContent() {
584
+ const [section, setSection] = useState4("pages");
585
+ const ctx = useCmsContext();
586
+ let subscriptionCtx = null;
587
+ try {
588
+ subscriptionCtx = useSubscription();
589
+ } catch (e) {
590
+ }
591
+ const isSubscriptionActive = subscriptionCtx?.isSubscriptionActive ?? true;
592
+ if (!isSubscriptionActive) {
593
+ return /* @__PURE__ */ jsx5("div", { className: "flex flex-col lg:flex-row h-screen w-full overflow-hidden bg-slate-50 text-slate-900 font-sans selection:bg-indigo-100 selection:text-indigo-900", children: /* @__PURE__ */ jsx5(SubscriptionPage, {}) });
594
+ }
595
+ return /* @__PURE__ */ jsxs2("div", { className: "flex flex-col lg:flex-row h-screen w-full overflow-hidden bg-slate-50 text-slate-900 font-sans selection:bg-indigo-100 selection:text-indigo-900", children: [
596
+ /* @__PURE__ */ jsx5("div", { className: "lg:hidden flex items-center justify-between bg-white/80 backdrop-blur-xl border-b border-slate-200 px-4 py-3 shrink-0 z-20 relative", children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2", children: [
597
+ ctx.overrides?.["global-logo"] ? /* @__PURE__ */ jsx5("img", { src: String(ctx.overrides["global-logo"]), alt: "Logo", className: "h-5 w-auto object-contain" }) : /* @__PURE__ */ jsx5("div", { className: "w-2 h-2 rounded-full bg-indigo-500 shadow-[0_0_8px_rgba(99,102,241,0.8)]" }),
598
+ /* @__PURE__ */ jsx5("div", { className: "font-bold text-slate-900 tracking-tight", children: "Admin CMS" })
599
+ ] }) }),
600
+ /* @__PURE__ */ jsxs2("aside", { className: "flex w-full lg:w-64 shrink-0 flex-col border-b lg:border-b-0 lg:border-r border-slate-200 bg-white/80 backdrop-blur-xl shadow-sm z-10 overflow-hidden", children: [
601
+ /* @__PURE__ */ jsxs2("div", { className: "hidden lg:block border-b border-slate-200 px-6 py-5 bg-white/50", children: [
602
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2 mb-1", children: [
603
+ ctx.overrides?.["global-logo"] ? /* @__PURE__ */ jsx5("img", { src: String(ctx.overrides["global-logo"]), alt: "Logo", className: "h-5 w-auto object-contain" }) : /* @__PURE__ */ jsx5("div", { className: "w-2 h-2 rounded-full bg-indigo-500 shadow-[0_0_8px_rgba(99,102,241,0.8)]" }),
604
+ /* @__PURE__ */ jsx5("div", { className: "text-xs font-bold uppercase tracking-widest text-slate-500", children: "Admin CMS" })
605
+ ] }),
606
+ /* @__PURE__ */ jsx5("div", { className: "truncate font-bold text-lg text-slate-900", children: ctx.config.siteName ?? "Site Administration" })
607
+ ] }),
608
+ /* @__PURE__ */ jsxs2("nav", { className: "flex flex-row lg:flex-col overflow-x-auto lg:overflow-visible space-x-2 lg:space-x-0 lg:space-y-1.5 p-3 lg:p-4 text-sm font-medium hide-scrollbar", children: [
609
+ /* @__PURE__ */ jsx5(
610
+ SideItem,
611
+ {
612
+ active: section === "pages",
613
+ onClick: () => setSection("pages"),
614
+ icon: /* @__PURE__ */ jsx5(FileText, { className: "h-4 w-4 shrink-0" }),
615
+ children: "Pages"
616
+ }
617
+ ),
618
+ /* @__PURE__ */ jsx5(
619
+ SideItem,
620
+ {
621
+ active: section === "collections",
622
+ onClick: () => setSection("collections"),
623
+ icon: /* @__PURE__ */ jsx5(Boxes, { className: "h-4 w-4 shrink-0" }),
624
+ children: "Collections"
625
+ }
626
+ ),
627
+ /* @__PURE__ */ jsx5(
628
+ SideItem,
629
+ {
630
+ active: section === "submissions",
631
+ onClick: () => setSection("submissions"),
632
+ icon: /* @__PURE__ */ jsx5(Inbox, { className: "h-4 w-4 shrink-0" }),
633
+ children: "Data"
634
+ }
635
+ ),
636
+ /* @__PURE__ */ jsx5(
637
+ SideItem,
638
+ {
639
+ active: section === "config",
640
+ onClick: () => setSection("config"),
641
+ icon: /* @__PURE__ */ jsx5(SlidersHorizontal, { className: "h-4 w-4 shrink-0" }),
642
+ children: "Config"
643
+ }
644
+ ),
645
+ /* @__PURE__ */ jsx5(
646
+ SideItem,
647
+ {
648
+ active: section === "settings",
649
+ onClick: () => setSection("settings"),
650
+ icon: /* @__PURE__ */ jsx5(SettingsIcon, { className: "h-4 w-4 shrink-0" }),
651
+ children: "Settings"
652
+ }
653
+ ),
654
+ subscriptionCtx && /* @__PURE__ */ jsx5(
655
+ SideItem,
656
+ {
657
+ active: section === "subscription",
658
+ onClick: () => setSection("subscription"),
659
+ icon: /* @__PURE__ */ jsx5(CreditCard2, { className: "h-4 w-4 shrink-0" }),
660
+ children: "Subscription"
661
+ }
662
+ )
663
+ ] }),
664
+ /* @__PURE__ */ jsxs2("div", { className: "hidden lg:block mt-auto border-t border-slate-200 p-4 bg-slate-50/50", children: [
665
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between text-xs text-slate-500 mb-4", children: [
666
+ /* @__PURE__ */ jsx5("span", { children: "Storage Adapter" }),
667
+ /* @__PURE__ */ jsx5("span", { className: "font-semibold px-2 py-0.5 rounded-full bg-slate-200 text-slate-700", children: ctx.adapter.name })
668
+ ] }),
669
+ /* @__PURE__ */ jsxs2(
670
+ "button",
671
+ {
672
+ onClick: async () => {
673
+ await fetch("/api/admin/auth?action=logout", { method: "POST" });
674
+ window.location.href = "/admin/login";
675
+ },
676
+ className: "flex items-center justify-center gap-2 w-full px-3 py-2 text-sm font-medium text-red-600 bg-red-50 hover:bg-red-100 rounded-lg transition-colors",
677
+ children: [
678
+ /* @__PURE__ */ jsx5(LogOut, { className: "w-4 h-4" }),
679
+ "Logout"
680
+ ]
681
+ }
682
+ )
683
+ ] })
684
+ ] }),
685
+ /* @__PURE__ */ jsxs2("main", { className: "flex-1 overflow-hidden relative flex flex-col", children: [
686
+ section === "pages" && /* @__PURE__ */ jsx5(PagesSection, {}),
687
+ section === "collections" && /* @__PURE__ */ jsx5(CollectionsSection, {}),
688
+ section === "submissions" && /* @__PURE__ */ jsx5(SubmissionsSection, {}),
689
+ section === "config" && /* @__PURE__ */ jsx5(ConfigSection, {}),
690
+ section === "settings" && /* @__PURE__ */ jsx5(SettingsSection, {}),
691
+ section === "subscription" && /* @__PURE__ */ jsx5(SubscriptionPage, {})
692
+ ] })
693
+ ] });
694
+ }
695
+ function SideItem({
696
+ active,
697
+ onClick,
698
+ icon,
699
+ children
700
+ }) {
701
+ return /* @__PURE__ */ jsxs2(
702
+ "button",
703
+ {
704
+ onClick,
705
+ className: `flex items-center gap-2 lg:gap-3 rounded-lg px-4 lg:px-3 py-2 lg:py-2.5 text-left transition-all duration-200 whitespace-nowrap ${active ? "bg-indigo-600 text-white shadow-md shadow-indigo-200 lg:translate-x-1" : "text-slate-600 hover:bg-slate-100 hover:text-slate-900"}`,
706
+ children: [
707
+ /* @__PURE__ */ jsx5("span", { className: active ? "text-indigo-100" : "text-slate-400", children: icon }),
708
+ /* @__PURE__ */ jsx5("span", { className: "inline", children })
709
+ ]
710
+ }
711
+ );
712
+ }
713
+ function PagesSection() {
714
+ const ctx = useCmsContext();
715
+ const [selected, setSelected] = useState4(
716
+ ctx.config.pages[0] ?? null
717
+ );
718
+ const [showList, setShowList] = useState4(true);
719
+ return /* @__PURE__ */ jsxs2("div", { className: "flex flex-col lg:flex-row h-full", children: [
720
+ showList && /* @__PURE__ */ jsxs2("div", { className: "w-full lg:w-72 shrink-0 border-b lg:border-b-0 lg:border-r border-slate-200 bg-white/50 p-3 lg:p-4 overflow-x-auto lg:overflow-y-auto hide-scrollbar", children: [
721
+ /* @__PURE__ */ jsx5("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500 hidden lg:block", children: "Pages" }),
722
+ /* @__PURE__ */ jsxs2("ul", { className: "flex flex-row lg:flex-col space-x-2 lg:space-x-0 lg:space-y-1", children: [
723
+ ctx.config.pages.map((p) => /* @__PURE__ */ jsx5("li", { className: "shrink-0 w-32 lg:w-full", children: /* @__PURE__ */ jsx5(
724
+ "button",
725
+ {
726
+ onClick: () => setSelected(p),
727
+ className: `w-full rounded-lg px-3 py-2.5 text-left text-sm transition-all duration-200 ${selected?.id === p.id ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
728
+ children: /* @__PURE__ */ jsx5("div", { className: `truncate ${selected?.id === p.id ? "text-slate-900" : "text-slate-700"}`, children: p.name })
729
+ }
730
+ ) }, p.id)),
731
+ ctx.config.pages.length === 0 && /* @__PURE__ */ jsx5("li", { className: "px-3 py-6 text-center text-sm text-slate-500 bg-slate-50 rounded-lg border border-dashed border-slate-200 w-full", children: "No pages registered." })
732
+ ] })
733
+ ] }),
734
+ /* @__PURE__ */ jsx5("div", { className: "flex-1 overflow-hidden bg-slate-50/50 flex flex-col", children: selected ? /* @__PURE__ */ jsx5(
735
+ PageEditor,
736
+ {
737
+ page: selected,
738
+ showList,
739
+ onToggleList: () => setShowList(!showList)
740
+ }
741
+ ) : /* @__PURE__ */ jsx5("div", { className: "grid h-full place-items-center text-sm text-slate-500", children: "Select a page to edit its content." }) })
742
+ ] });
743
+ }
744
+ function PageEditor({ page, showList, onToggleList }) {
745
+ const ctx = useCmsContext();
746
+ const iframeRef = useRef2(null);
747
+ const [registered, setRegistered] = useState4([]);
748
+ const [selectedId, setSelectedId] = useState4(null);
749
+ const [preview, setPreview] = useState4(false);
750
+ const src = useMemo2(
751
+ () => `${page.path}${preview ? "" : "?__cms=edit"}`,
752
+ [page.path, preview]
753
+ );
754
+ useEffect4(() => {
755
+ const onMsg = (e) => {
756
+ if (e.source !== iframeRef.current?.contentWindow) return;
757
+ const d = e.data;
758
+ if (!d || !d.__cms) return;
759
+ if (d.type === "cms:register" && d.items) {
760
+ setRegistered(d.items);
761
+ } else if (d.type === "cms:select") {
762
+ setSelectedId(d.id ?? null);
763
+ } else if (d.type === "cms:ready") {
764
+ iframeRef.current?.contentWindow?.postMessage(
765
+ { __cms: true, type: "cms:set-all-overrides", overrides: ctx.overrides },
766
+ "*"
767
+ );
768
+ }
769
+ };
770
+ window.addEventListener("message", onMsg);
771
+ return () => window.removeEventListener("message", onMsg);
772
+ }, [ctx.overrides]);
773
+ useEffect4(() => {
774
+ setRegistered([]);
775
+ setSelectedId(null);
776
+ }, [page.id]);
777
+ const updateOverride = useCallback3(
778
+ (id, value) => {
779
+ ctx.setOverride(id, value);
780
+ iframeRef.current?.contentWindow?.postMessage(
781
+ { __cms: true, type: "cms:set-override", id, value },
782
+ "*"
783
+ );
784
+ },
785
+ [ctx]
786
+ );
787
+ const selectedMeta = registered.find((r) => r.id === selectedId) ?? null;
788
+ const [viewMode, setViewMode] = useState4("desktop");
789
+ return /* @__PURE__ */ jsxs2("div", { className: "flex h-full flex-col", children: [
790
+ /* @__PURE__ */ jsxs2("div", { className: "flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 border-b border-slate-200 bg-white/80 backdrop-blur px-4 py-3 shadow-sm z-10 shrink-0", children: [
791
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2 text-sm shrink-0", children: [
792
+ /* @__PURE__ */ jsx5("button", { onClick: onToggleList, className: "text-slate-400 hover:text-slate-700 p-1 hidden lg:block", title: "Toggle Pages Menu", children: showList ? /* @__PURE__ */ jsx5(PanelLeftClose, { className: "w-5 h-5" }) : /* @__PURE__ */ jsx5(PanelLeftOpen, { className: "w-5 h-5" }) }),
793
+ /* @__PURE__ */ jsx5("span", { className: "font-bold text-slate-800 text-sm md:text-base", children: page.name }),
794
+ /* @__PURE__ */ jsx5("span", { className: "text-slate-300 hidden sm:inline", children: "|" }),
795
+ /* @__PURE__ */ jsx5("span", { className: "text-slate-500 font-mono text-[10px] md:text-xs bg-slate-100 px-2 py-1 rounded hidden sm:inline-block", children: page.path })
796
+ ] }),
797
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2 overflow-x-auto w-full sm:w-auto pb-1 sm:pb-0 hide-scrollbar shrink-0", children: [
798
+ /* @__PURE__ */ jsxs2("div", { className: "flex bg-slate-100/80 p-0.5 rounded-lg mr-2 shrink-0", children: [
799
+ /* @__PURE__ */ jsx5("button", { onClick: () => setViewMode("desktop"), className: `p-1.5 rounded-md transition-all ${viewMode === "desktop" ? "bg-white shadow-sm text-indigo-600" : "text-slate-500 hover:text-slate-800"}`, title: "Desktop View", children: /* @__PURE__ */ jsx5(Monitor, { className: "w-4 h-4" }) }),
800
+ /* @__PURE__ */ jsx5("button", { onClick: () => setViewMode("tablet"), className: `p-1.5 rounded-md transition-all ${viewMode === "tablet" ? "bg-white shadow-sm text-indigo-600" : "text-slate-500 hover:text-slate-800"}`, title: "Tablet View", children: /* @__PURE__ */ jsx5(Tablet, { className: "w-4 h-4" }) }),
801
+ /* @__PURE__ */ jsx5("button", { onClick: () => setViewMode("mobile"), className: `p-1.5 rounded-md transition-all ${viewMode === "mobile" ? "bg-white shadow-sm text-indigo-600" : "text-slate-500 hover:text-slate-800"}`, title: "Mobile View", children: /* @__PURE__ */ jsx5(Smartphone, { className: "w-4 h-4" }) })
802
+ ] }),
803
+ /* @__PURE__ */ jsxs2(
804
+ "button",
805
+ {
806
+ onClick: () => setPreview((v) => !v),
807
+ className: "inline-flex items-center gap-1.5 rounded-lg border border-slate-200 px-3 py-1.5 text-xs font-semibold text-slate-700 hover:bg-slate-50 hover:text-slate-900 transition-colors bg-white shadow-sm shrink-0",
808
+ children: [
809
+ preview ? /* @__PURE__ */ jsx5(Pencil, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ jsx5(Monitor, { className: "h-3.5 w-3.5" }),
810
+ preview ? "Edit" : "Preview"
811
+ ]
812
+ }
813
+ ),
814
+ /* @__PURE__ */ jsxs2(
815
+ "a",
816
+ {
817
+ href: page.path,
818
+ target: "_blank",
819
+ rel: "noreferrer",
820
+ className: "inline-flex items-center gap-1.5 rounded-lg border border-slate-200 px-3 py-1.5 text-xs font-semibold text-slate-700 hover:bg-slate-50 hover:text-slate-900 transition-colors bg-white shadow-sm shrink-0",
821
+ children: [
822
+ /* @__PURE__ */ jsx5(Upload, { className: "h-3.5 w-3.5" }),
823
+ "Open"
824
+ ]
825
+ }
826
+ ),
827
+ /* @__PURE__ */ jsxs2(
828
+ "button",
829
+ {
830
+ onClick: () => ctx.reset(),
831
+ disabled: !ctx.isDirty,
832
+ className: "inline-flex items-center gap-1.5 rounded-lg border border-slate-200 px-3 py-1.5 text-xs font-semibold text-slate-700 hover:bg-slate-50 hover:text-slate-900 disabled:opacity-50 transition-colors bg-white shadow-sm shrink-0",
833
+ children: [
834
+ /* @__PURE__ */ jsx5(X, { className: "h-3.5 w-3.5" }),
835
+ "Discard"
836
+ ]
837
+ }
838
+ ),
839
+ /* @__PURE__ */ jsxs2(
840
+ "button",
841
+ {
842
+ onClick: () => ctx.save(),
843
+ disabled: !ctx.isDirty,
844
+ className: "inline-flex items-center gap-1.5 rounded-lg bg-indigo-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-indigo-700 disabled:opacity-50 transition-colors shadow-sm shrink-0",
845
+ children: [
846
+ /* @__PURE__ */ jsx5(Boxes, { className: "h-3.5 w-3.5" }),
847
+ "Save"
848
+ ]
849
+ }
850
+ )
851
+ ] })
852
+ ] }),
853
+ /* @__PURE__ */ jsxs2("div", { className: "flex flex-col lg:flex-row flex-1 overflow-hidden", children: [
854
+ /* @__PURE__ */ jsx5("div", { className: "flex-1 overflow-hidden bg-slate-100/80 p-2 md:p-4 lg:p-6 flex flex-col items-center", children: /* @__PURE__ */ jsx5("div", { className: `flex-1 rounded-xl overflow-hidden border border-slate-200 bg-white shadow-lg ring-1 ring-slate-900/5 min-h-[300px] transition-all duration-300 w-full ${viewMode === "mobile" ? "max-w-[375px]" : viewMode === "tablet" ? "max-w-[768px]" : "w-full"}`, children: /* @__PURE__ */ jsx5(
855
+ "iframe",
856
+ {
857
+ ref: iframeRef,
858
+ src,
859
+ title: page.name,
860
+ className: "h-full w-full bg-white"
861
+ },
862
+ src
863
+ ) }) }),
864
+ /* @__PURE__ */ jsxs2("aside", { className: "w-full lg:w-80 shrink-0 overflow-y-auto border-t lg:border-t-0 lg:border-l border-slate-200 bg-white shadow-[-4px_0_15px_-3px_rgba(0,0,0,0.05)] z-10 max-h-[40vh] lg:max-h-none hide-scrollbar", children: [
865
+ /* @__PURE__ */ jsxs2("div", { className: "sticky top-0 bg-white/90 backdrop-blur border-b border-slate-200 px-5 py-3 md:py-4 z-10", children: [
866
+ /* @__PURE__ */ jsxs2("div", { className: "text-xs font-bold uppercase tracking-widest text-slate-500 flex justify-between items-center", children: [
867
+ /* @__PURE__ */ jsx5("span", { children: selectedMeta ? "Edit Field" : "Editable Elements" }),
868
+ selectedMeta && /* @__PURE__ */ jsx5("button", { onClick: () => setSelectedId(null), className: "lg:hidden text-slate-400 hover:text-slate-700", children: "Close" })
869
+ ] }),
870
+ !selectedMeta && /* @__PURE__ */ jsx5("p", { className: "text-[10px] md:text-xs text-slate-400 mt-1", children: "Select an element on the left to edit it." })
871
+ ] }),
872
+ selectedMeta ? /* @__PURE__ */ jsx5(
873
+ FieldEditor,
874
+ {
875
+ meta: selectedMeta,
876
+ value: ctx.overrides[selectedMeta.id] ?? selectedMeta.defaultValue,
877
+ onChange: (v) => updateOverride(selectedMeta.id, v),
878
+ onReset: () => {
879
+ ctx.reset(selectedMeta.id);
880
+ iframeRef.current?.contentWindow?.postMessage(
881
+ {
882
+ __cms: true,
883
+ type: "cms:set-override",
884
+ id: selectedMeta.id,
885
+ value: selectedMeta.defaultValue
886
+ },
887
+ "*"
888
+ );
889
+ },
890
+ onClose: () => setSelectedId(null)
891
+ }
892
+ ) : /* @__PURE__ */ jsx5(
893
+ SectionAccordion,
894
+ {
895
+ registered,
896
+ onSelect: (id) => {
897
+ setSelectedId(id);
898
+ iframeRef.current?.contentWindow?.postMessage(
899
+ { __cms: true, type: "cms:select", id },
900
+ "*"
901
+ );
902
+ }
903
+ }
904
+ )
905
+ ] })
906
+ ] })
907
+ ] });
908
+ }
909
+ function SectionAccordion({
910
+ registered,
911
+ onSelect
912
+ }) {
913
+ const [expanded, setExpanded] = useState4({});
914
+ if (registered.length === 0) {
915
+ return /* @__PURE__ */ jsxs2("div", { className: "px-4 py-8 text-center text-sm text-slate-500", children: [
916
+ /* @__PURE__ */ jsx5("div", { className: "w-12 h-12 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-3", children: /* @__PURE__ */ jsx5(Pencil, { className: "h-5 w-5 text-slate-400" }) }),
917
+ "No editable fields detected on this page."
918
+ ] });
919
+ }
920
+ const groups = {};
921
+ for (const m of registered) {
922
+ const key = m.section || "Unsectioned";
923
+ if (!groups[key]) groups[key] = [];
924
+ groups[key].push(m);
925
+ }
926
+ const sectionNames = Object.keys(groups).filter((n) => n !== "Unsectioned");
927
+ const unsectionedFields = groups["Unsectioned"] || [];
928
+ const toggle = (name) => setExpanded((prev) => ({ ...prev, [name]: !prev[name] }));
929
+ return /* @__PURE__ */ jsxs2("div", { className: "p-2 space-y-3", children: [
930
+ unsectionedFields.length > 0 && /* @__PURE__ */ jsx5("ul", { className: "divide-y divide-slate-100 bg-white rounded-lg border border-slate-200 overflow-hidden shadow-sm", children: unsectionedFields.map((m) => /* @__PURE__ */ jsx5(FieldListItem, { meta: m, onSelect }, m.id)) }),
931
+ sectionNames.map((sectionName) => {
932
+ const isOpen = expanded[sectionName] ?? false;
933
+ const fields = groups[sectionName];
934
+ return /* @__PURE__ */ jsxs2("div", { className: "rounded-lg border border-slate-200 overflow-hidden", children: [
935
+ /* @__PURE__ */ jsxs2(
936
+ "button",
937
+ {
938
+ onClick: () => toggle(sectionName),
939
+ className: "flex w-full items-center justify-between px-3 py-2.5 bg-slate-50/80 hover:bg-slate-100 transition-colors text-left",
940
+ children: [
941
+ /* @__PURE__ */ jsxs2("span", { className: "flex items-center gap-2", children: [
942
+ /* @__PURE__ */ jsx5("span", { className: "font-semibold text-sm text-slate-800", children: sectionName }),
943
+ /* @__PURE__ */ jsx5("span", { className: "text-[10px] font-mono text-slate-400 bg-slate-200/70 px-1.5 py-0.5 rounded-full", children: fields.length })
944
+ ] }),
945
+ /* @__PURE__ */ jsx5(
946
+ "svg",
947
+ {
948
+ className: `h-4 w-4 text-slate-400 transition-transform duration-200 ${isOpen ? "rotate-180" : ""}`,
949
+ fill: "none",
950
+ viewBox: "0 0 24 24",
951
+ stroke: "currentColor",
952
+ strokeWidth: 2,
953
+ children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M19 9l-7 7-7-7" })
954
+ }
955
+ )
956
+ ]
957
+ }
958
+ ),
959
+ isOpen && /* @__PURE__ */ jsx5("ul", { className: "divide-y divide-slate-100 bg-white", children: fields.map((m) => /* @__PURE__ */ jsx5(FieldListItem, { meta: m, onSelect }, m.id)) })
960
+ ] }, sectionName);
961
+ })
962
+ ] });
963
+ }
964
+ function FieldListItem({ meta, onSelect }) {
965
+ return /* @__PURE__ */ jsx5("li", { className: "p-1 list-none", children: /* @__PURE__ */ jsxs2(
966
+ "button",
967
+ {
968
+ onClick: () => onSelect(meta.id),
969
+ className: "flex w-full items-center justify-between gap-2 rounded-md px-3 py-2.5 text-left hover:bg-slate-50 group transition-colors",
970
+ children: [
971
+ /* @__PURE__ */ jsxs2("span", { className: "overflow-hidden", children: [
972
+ /* @__PURE__ */ jsx5("span", { className: "block font-medium text-slate-800 text-sm truncate", children: meta.label ?? meta.id }),
973
+ /* @__PURE__ */ jsxs2("span", { className: "block text-[10px] md:text-xs text-slate-400 truncate mt-0.5 font-mono", children: [
974
+ meta.type,
975
+ " ",
976
+ /* @__PURE__ */ jsx5("span", { className: "text-slate-300 mx-1", children: "\xB7" }),
977
+ " ",
978
+ meta.id
979
+ ] })
980
+ ] }),
981
+ /* @__PURE__ */ jsx5(Pencil, { className: "h-4 w-4 text-slate-300 group-hover:text-indigo-500 transition-colors shrink-0" })
982
+ ]
983
+ }
984
+ ) });
985
+ }
986
+ function FieldEditor({
987
+ meta,
988
+ value,
989
+ onChange,
990
+ onReset,
991
+ onClose
992
+ }) {
993
+ const ctx = useCmsContext();
994
+ return /* @__PURE__ */ jsxs2("div", { className: "p-5 animate-in slide-in-from-right-4 duration-200", children: [
995
+ /* @__PURE__ */ jsxs2("div", { className: "mb-5", children: [
996
+ /* @__PURE__ */ jsx5("div", { className: "inline-flex items-center gap-1.5 px-2 py-1 rounded bg-indigo-50 text-indigo-700 text-[10px] font-bold uppercase tracking-wider mb-2", children: meta.type }),
997
+ /* @__PURE__ */ jsx5("div", { className: "font-bold text-slate-900 text-lg leading-tight", children: meta.label ?? meta.id }),
998
+ /* @__PURE__ */ jsx5("div", { className: "text-xs font-mono text-slate-400 mt-1", children: meta.id })
999
+ ] }),
1000
+ /* @__PURE__ */ jsxs2("div", { className: "space-y-4", children: [
1001
+ meta.type === "text" && /* @__PURE__ */ jsx5(
1002
+ "input",
1003
+ {
1004
+ type: "text",
1005
+ value: String(value ?? ""),
1006
+ onChange: (e) => onChange(e.target.value),
1007
+ className: "w-full rounded-xl border border-slate-200 px-4 py-3 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
1008
+ }
1009
+ ),
1010
+ meta.type === "textarea" && /* @__PURE__ */ jsx5(
1011
+ "textarea",
1012
+ {
1013
+ value: String(value ?? ""),
1014
+ onChange: (e) => onChange(e.target.value),
1015
+ rows: 5,
1016
+ className: "w-full rounded-xl border border-slate-200 px-4 py-3 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all resize-y"
1017
+ }
1018
+ ),
1019
+ meta.type === "image" && /* @__PURE__ */ jsxs2("div", { className: "space-y-3", children: [
1020
+ /* @__PURE__ */ jsxs2("div", { className: "flex gap-2", children: [
1021
+ /* @__PURE__ */ jsx5(
1022
+ "input",
1023
+ {
1024
+ type: "url",
1025
+ value: String(value ?? ""),
1026
+ onChange: (e) => onChange(e.target.value),
1027
+ placeholder: "https://...",
1028
+ className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
1029
+ }
1030
+ ),
1031
+ /* @__PURE__ */ jsxs2("label", { className: "flex-shrink-0 cursor-pointer rounded-xl bg-slate-100 px-4 py-2.5 text-sm font-medium text-slate-700 hover:bg-slate-200 transition-colors border border-slate-200 flex items-center justify-center", children: [
1032
+ "Upload",
1033
+ /* @__PURE__ */ jsx5(
1034
+ "input",
1035
+ {
1036
+ type: "file",
1037
+ accept: "image/*",
1038
+ className: "hidden",
1039
+ onChange: (e) => {
1040
+ const file = e.target.files?.[0];
1041
+ if (file) {
1042
+ void handleImageFile(file, onChange, ctx.uploadImage);
1043
+ }
1044
+ }
1045
+ }
1046
+ )
1047
+ ] })
1048
+ ] }),
1049
+ value ? /* @__PURE__ */ jsxs2("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group", children: [
1050
+ /* @__PURE__ */ jsx5(
1051
+ "img",
1052
+ {
1053
+ src: String(value),
1054
+ alt: "",
1055
+ className: "max-h-48 w-full object-contain rounded-lg"
1056
+ }
1057
+ ),
1058
+ /* @__PURE__ */ jsx5("div", { className: "absolute inset-0 bg-black/40 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity", children: /* @__PURE__ */ jsx5("span", { className: "text-white text-xs font-medium px-2 py-1 bg-black/50 rounded backdrop-blur", children: "Preview" }) })
1059
+ ] }) : null
1060
+ ] }),
1061
+ meta.type === "link" && /* @__PURE__ */ jsxs2("div", { className: "space-y-4 bg-slate-50 p-4 rounded-xl border border-slate-100", children: [
1062
+ /* @__PURE__ */ jsxs2("label", { className: "block", children: [
1063
+ /* @__PURE__ */ jsx5("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "Link Text" }),
1064
+ /* @__PURE__ */ jsx5(
1065
+ "input",
1066
+ {
1067
+ value: value?.text ?? "",
1068
+ onChange: (e) => onChange({ ...value, text: e.target.value }),
1069
+ className: "mt-1.5 w-full rounded-lg border border-slate-200 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
1070
+ }
1071
+ )
1072
+ ] }),
1073
+ /* @__PURE__ */ jsxs2("label", { className: "block", children: [
1074
+ /* @__PURE__ */ jsx5("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "URL Target" }),
1075
+ /* @__PURE__ */ jsx5(
1076
+ "input",
1077
+ {
1078
+ value: value?.href ?? "",
1079
+ onChange: (e) => onChange({ ...value, href: e.target.value }),
1080
+ placeholder: "https:// or /path",
1081
+ className: "mt-1.5 w-full rounded-lg border border-slate-200 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
1082
+ }
1083
+ )
1084
+ ] })
1085
+ ] }),
1086
+ meta.type === "color" && /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-3 bg-slate-50 p-2 rounded-xl border border-slate-100", children: [
1087
+ /* @__PURE__ */ jsx5(
1088
+ "input",
1089
+ {
1090
+ type: "color",
1091
+ value: String(value ?? "#000000"),
1092
+ onChange: (e) => onChange(e.target.value),
1093
+ className: "h-10 w-16 cursor-pointer rounded bg-transparent border-0 p-0"
1094
+ }
1095
+ ),
1096
+ /* @__PURE__ */ jsx5(
1097
+ "input",
1098
+ {
1099
+ type: "text",
1100
+ value: String(value ?? "#000000"),
1101
+ onChange: (e) => onChange(e.target.value),
1102
+ className: "flex-1 rounded-lg border border-slate-200 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none"
1103
+ }
1104
+ )
1105
+ ] }),
1106
+ meta.type === "richtext" && /* @__PURE__ */ jsx5(
1107
+ "textarea",
1108
+ {
1109
+ value: String(value ?? ""),
1110
+ onChange: (e) => onChange(e.target.value),
1111
+ rows: 10,
1112
+ className: "w-full rounded-xl border border-slate-200 px-4 py-3 font-mono text-xs text-slate-700 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all resize-y"
1113
+ }
1114
+ ),
1115
+ meta.type === "list" && /* @__PURE__ */ jsxs2("div", { className: "space-y-4", children: [
1116
+ (Array.isArray(value) ? value : []).map((item, idx) => /* @__PURE__ */ jsxs2("div", { className: "flex gap-3 items-start bg-slate-50 p-3 rounded-xl border border-slate-100 relative group", children: [
1117
+ /* @__PURE__ */ jsx5("div", { className: "flex-1 space-y-3 w-full", children: meta.itemSchema ? meta.itemSchema.map((schemaField) => /* @__PURE__ */ jsxs2("div", { children: [
1118
+ /* @__PURE__ */ jsx5("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1119
+ schemaField.type === "icon" ? /* @__PURE__ */ jsx5(
1120
+ SearchableSelect,
1121
+ {
1122
+ value: String(item?.[schemaField.key] ?? ""),
1123
+ options: schemaField.options ?? [],
1124
+ placeholder: "Search icon...",
1125
+ iconMap: ctx.iconMap,
1126
+ onChange: (val) => {
1127
+ const arr = Array.isArray(value) ? [...value] : [];
1128
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1129
+ onChange(arr);
1130
+ }
1131
+ }
1132
+ ) : schemaField.type === "textarea" ? /* @__PURE__ */ jsx5(
1133
+ "textarea",
1134
+ {
1135
+ rows: 3,
1136
+ value: String(item?.[schemaField.key] ?? ""),
1137
+ onChange: (e) => {
1138
+ const arr = Array.isArray(value) ? [...value] : [];
1139
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1140
+ onChange(arr);
1141
+ },
1142
+ className: "w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
1143
+ }
1144
+ ) : schemaField.type === "boolean" ? /* @__PURE__ */ jsxs2("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1145
+ /* @__PURE__ */ jsx5(
1146
+ "input",
1147
+ {
1148
+ type: "checkbox",
1149
+ checked: !!item?.[schemaField.key],
1150
+ onChange: (e) => {
1151
+ const arr = Array.isArray(value) ? [...value] : [];
1152
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1153
+ onChange(arr);
1154
+ },
1155
+ className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
1156
+ }
1157
+ ),
1158
+ /* @__PURE__ */ jsx5("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
1159
+ ] }) : /* @__PURE__ */ jsx5(
1160
+ "input",
1161
+ {
1162
+ type: "text",
1163
+ value: String(item?.[schemaField.key] ?? ""),
1164
+ onChange: (e) => {
1165
+ const arr = Array.isArray(value) ? [...value] : [];
1166
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1167
+ onChange(arr);
1168
+ },
1169
+ className: "w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
1170
+ }
1171
+ )
1172
+ ] }, schemaField.key)) : /* @__PURE__ */ jsx5(
1173
+ "input",
1174
+ {
1175
+ type: "text",
1176
+ value: String(item),
1177
+ onChange: (e) => {
1178
+ const arr = Array.isArray(value) ? [...value] : [];
1179
+ arr[idx] = e.target.value;
1180
+ onChange(arr);
1181
+ },
1182
+ className: "w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
1183
+ }
1184
+ ) }),
1185
+ !meta.fixedLength && /* @__PURE__ */ jsx5(
1186
+ "button",
1187
+ {
1188
+ onClick: () => {
1189
+ const arr = Array.isArray(value) ? [...value] : [];
1190
+ arr.splice(idx, 1);
1191
+ onChange(arr);
1192
+ },
1193
+ className: "p-1.5 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors absolute top-2 right-2 opacity-0 group-hover:opacity-100",
1194
+ children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
1195
+ }
1196
+ )
1197
+ ] }, idx)),
1198
+ !meta.fixedLength && /* @__PURE__ */ jsxs2(
1199
+ "button",
1200
+ {
1201
+ onClick: () => {
1202
+ const arr = Array.isArray(value) ? [...value] : [];
1203
+ if (meta.itemSchema) {
1204
+ const newItem = {};
1205
+ meta.itemSchema.forEach((s) => {
1206
+ newItem[s.key] = "";
1207
+ });
1208
+ arr.push(newItem);
1209
+ } else {
1210
+ arr.push("New Item");
1211
+ }
1212
+ onChange(arr);
1213
+ },
1214
+ className: "flex items-center justify-center w-full gap-1.5 text-sm font-medium text-indigo-600 hover:text-indigo-700 px-2 py-2.5 rounded-lg border border-dashed border-indigo-200 hover:bg-indigo-50 hover:border-indigo-300 transition-colors",
1215
+ children: [
1216
+ /* @__PURE__ */ jsx5(Plus, { className: "w-4 h-4" }),
1217
+ " Add Item"
1218
+ ]
1219
+ }
1220
+ )
1221
+ ] }),
1222
+ " "
1223
+ ] }),
1224
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between pt-6 mt-6 border-t border-slate-100", children: [
1225
+ /* @__PURE__ */ jsxs2(
1226
+ "button",
1227
+ {
1228
+ onClick: onReset,
1229
+ className: "inline-flex items-center gap-1.5 text-xs font-medium text-slate-500 hover:text-slate-900 transition-colors",
1230
+ children: [
1231
+ /* @__PURE__ */ jsx5(RotateCcw, { className: "h-3.5 w-3.5" }),
1232
+ " Reset Default"
1233
+ ]
1234
+ }
1235
+ ),
1236
+ /* @__PURE__ */ jsx5(
1237
+ "button",
1238
+ {
1239
+ onClick: onClose,
1240
+ className: "rounded-lg bg-slate-100 px-4 py-2 text-xs font-bold text-slate-700 hover:bg-slate-200 transition-colors",
1241
+ children: "Done"
1242
+ }
1243
+ )
1244
+ ] })
1245
+ ] });
1246
+ }
1247
+ function CollectionsSection() {
1248
+ const ctx = useCmsContext();
1249
+ const collections = ctx.config.collections ?? [];
1250
+ const [selected, setSelected] = useState4(
1251
+ collections[0] ?? null
1252
+ );
1253
+ const [counts, setCounts] = useState4({});
1254
+ useEffect4(() => {
1255
+ collections.forEach((c) => {
1256
+ ctx.adapter.listEntries(c.id).then((entries) => {
1257
+ setCounts((prev) => ({ ...prev, [c.id]: entries.length }));
1258
+ });
1259
+ });
1260
+ }, [ctx.adapter, collections]);
1261
+ return /* @__PURE__ */ jsxs2("div", { className: "flex h-full bg-slate-50", children: [
1262
+ /* @__PURE__ */ jsxs2("div", { className: "w-72 shrink-0 border-r border-slate-200 bg-white/50 p-4", children: [
1263
+ /* @__PURE__ */ jsx5("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500", children: "Collections" }),
1264
+ /* @__PURE__ */ jsxs2("ul", { className: "space-y-1", children: [
1265
+ collections.map((c) => /* @__PURE__ */ jsx5("li", { children: /* @__PURE__ */ jsxs2(
1266
+ "button",
1267
+ {
1268
+ onClick: () => setSelected(c),
1269
+ className: `w-full rounded-lg px-3 py-2.5 text-left text-sm transition-all duration-200 ${selected?.id === c.id ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
1270
+ children: [
1271
+ /* @__PURE__ */ jsx5("div", { className: selected?.id === c.id ? "text-slate-900" : "text-slate-700", children: c.name }),
1272
+ /* @__PURE__ */ jsxs2("div", { className: `text-xs mt-0.5 ${selected?.id === c.id ? "text-indigo-500" : "text-slate-400"}`, children: [
1273
+ counts[c.id] ?? 0,
1274
+ " items"
1275
+ ] })
1276
+ ]
1277
+ }
1278
+ ) }, c.id)),
1279
+ collections.length === 0 && /* @__PURE__ */ jsx5("li", { className: "px-3 py-6 text-center text-sm text-slate-500 bg-slate-50 rounded-lg border border-dashed border-slate-200", children: "No collections registered." })
1280
+ ] })
1281
+ ] }),
1282
+ /* @__PURE__ */ jsxs2("div", { className: "flex-1 overflow-auto p-8 relative", children: [
1283
+ /* @__PURE__ */ jsx5("div", { className: "absolute inset-0 bg-grid-slate-100 [mask-image:linear-gradient(0deg,white,rgba(255,255,255,0.6))] -z-10 pointer-events-none" }),
1284
+ selected ? /* @__PURE__ */ jsx5(CollectionEditor, { collection: selected }, selected.id) : /* @__PURE__ */ jsx5("div", { className: "grid h-full place-items-center text-sm text-slate-500", children: "Select a collection to manage its entries." })
1285
+ ] })
1286
+ ] });
1287
+ }
1288
+ function CollectionEditor({ collection }) {
1289
+ const ctx = useCmsContext();
1290
+ const [entries, setEntries] = useState4([]);
1291
+ const [editing, setEditing] = useState4(null);
1292
+ const [saving, setSaving] = useState4(false);
1293
+ const [deletingId, setDeletingId] = useState4(null);
1294
+ const [loadingEntries, setLoadingEntries] = useState4(true);
1295
+ const [draggedIdx, setDraggedIdx] = useState4(null);
1296
+ const [dragOverIdx, setDragOverIdx] = useState4(null);
1297
+ const load = useCallback3(() => {
1298
+ setLoadingEntries(true);
1299
+ ctx.adapter.listEntries(collection.id).then((res) => {
1300
+ const sorted = [...res].sort((a, b) => {
1301
+ const orderA = Number(a.order) || 0;
1302
+ const orderB = Number(b.order) || 0;
1303
+ return orderA - orderB;
1304
+ });
1305
+ setEntries(sorted);
1306
+ setLoadingEntries(false);
1307
+ }).catch(() => setLoadingEntries(false));
1308
+ }, [ctx.adapter, collection.id]);
1309
+ useEffect4(() => {
1310
+ load();
1311
+ }, [load]);
1312
+ const startNew = () => {
1313
+ const base = { id: crypto.randomUUID() };
1314
+ collection.fields.forEach((f) => {
1315
+ if (f.id === "order") {
1316
+ base[f.id] = entries.length;
1317
+ } else if (f.defaultValue !== void 0) {
1318
+ base[f.id] = f.defaultValue;
1319
+ } else {
1320
+ base[f.id] = f.type === "boolean" ? false : f.type === "number" ? 0 : "";
1321
+ }
1322
+ });
1323
+ setEditing(base);
1324
+ };
1325
+ const save = async () => {
1326
+ if (!editing) return;
1327
+ setSaving(true);
1328
+ try {
1329
+ await ctx.adapter.putEntry(collection.id, editing);
1330
+ ctx.notifyCollectionChanged();
1331
+ setEditing(null);
1332
+ load();
1333
+ } finally {
1334
+ setSaving(false);
1335
+ }
1336
+ };
1337
+ const remove = async (id) => {
1338
+ if (!confirm("Delete this entry forever?")) return;
1339
+ setDeletingId(id);
1340
+ try {
1341
+ await ctx.adapter.deleteEntry(collection.id, id);
1342
+ ctx.notifyCollectionChanged();
1343
+ load();
1344
+ } finally {
1345
+ setDeletingId(null);
1346
+ }
1347
+ };
1348
+ const onDragStart = (e, idx) => {
1349
+ setDraggedIdx(idx);
1350
+ e.dataTransfer.effectAllowed = "move";
1351
+ const target = e.target;
1352
+ target.style.opacity = "0.5";
1353
+ };
1354
+ const onDragOver = (e, idx) => {
1355
+ e.preventDefault();
1356
+ e.dataTransfer.dropEffect = "move";
1357
+ setDragOverIdx(idx);
1358
+ };
1359
+ const onDrop = async (e, dropIdx) => {
1360
+ e.preventDefault();
1361
+ if (draggedIdx === null || draggedIdx === dropIdx) {
1362
+ setDragOverIdx(null);
1363
+ return;
1364
+ }
1365
+ const newEntries = [...entries];
1366
+ const [draggedItem] = newEntries.splice(draggedIdx, 1);
1367
+ newEntries.splice(dropIdx, 0, draggedItem);
1368
+ setEntries(newEntries);
1369
+ setDragOverIdx(null);
1370
+ setDraggedIdx(null);
1371
+ for (let i = 0; i < newEntries.length; i++) {
1372
+ newEntries[i].order = i;
1373
+ await ctx.adapter.putEntry(collection.id, newEntries[i]);
1374
+ }
1375
+ };
1376
+ const onDragEnd = (e) => {
1377
+ const target = e.target;
1378
+ target.style.opacity = "1";
1379
+ setDraggedIdx(null);
1380
+ setDragOverIdx(null);
1381
+ };
1382
+ const visibleFields = collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order").slice(0, 5);
1383
+ return /* @__PURE__ */ jsxs2("div", { className: "mx-auto max-w-5xl", children: [
1384
+ /* @__PURE__ */ jsxs2("div", { className: "mb-8 flex items-center justify-between", children: [
1385
+ /* @__PURE__ */ jsxs2("div", { children: [
1386
+ /* @__PURE__ */ jsx5("h2", { className: "text-2xl font-bold text-slate-900 tracking-tight", children: collection.name }),
1387
+ collection.description && /* @__PURE__ */ jsx5("p", { className: "text-sm text-slate-500 mt-1", children: collection.description })
1388
+ ] }),
1389
+ /* @__PURE__ */ jsxs2(
1390
+ "button",
1391
+ {
1392
+ onClick: startNew,
1393
+ className: "inline-flex items-center gap-2 rounded-xl bg-indigo-600 px-4 py-2.5 text-sm font-bold text-white shadow-sm hover:bg-indigo-700 hover:shadow transition-all",
1394
+ children: [
1395
+ /* @__PURE__ */ jsx5(Plus, { className: "h-4 w-4" }),
1396
+ " New Entry"
1397
+ ]
1398
+ }
1399
+ )
1400
+ ] }),
1401
+ editing && /* @__PURE__ */ jsxs2("div", { className: "mb-8 rounded-2xl border border-indigo-100 bg-white p-6 shadow-xl shadow-indigo-100/50 animate-in fade-in slide-in-from-top-4", children: [
1402
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2 mb-6", children: [
1403
+ /* @__PURE__ */ jsx5("div", { className: "w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600", children: /* @__PURE__ */ jsx5(Pencil, { className: "w-4 h-4" }) }),
1404
+ /* @__PURE__ */ jsx5("h3", { className: "text-lg font-bold text-slate-900", children: "Edit Entry" })
1405
+ ] }),
1406
+ /* @__PURE__ */ jsx5("div", { className: "grid gap-5 md:grid-cols-2", children: collection.fields.filter((f) => f.id !== "order").map((f) => /* @__PURE__ */ jsxs2("label", { className: `block ${f.type === "richtext" ? "md:col-span-2" : ""}`, children: [
1407
+ /* @__PURE__ */ jsxs2("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
1408
+ f.label,
1409
+ /* @__PURE__ */ jsx5("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
1410
+ ] }),
1411
+ f.type === "boolean" ? /* @__PURE__ */ jsx5("div", { className: "mt-1 h-10 flex items-center", children: /* @__PURE__ */ jsx5(
1412
+ "input",
1413
+ {
1414
+ type: "checkbox",
1415
+ checked: !!editing[f.id],
1416
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.checked }),
1417
+ className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
1418
+ }
1419
+ ) }) : f.type === "number" ? /* @__PURE__ */ jsx5(
1420
+ "input",
1421
+ {
1422
+ type: "number",
1423
+ value: Number(editing[f.id] ?? 0),
1424
+ onChange: (e) => setEditing({ ...editing, [f.id]: Number(e.target.value) }),
1425
+ className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
1426
+ }
1427
+ ) : f.type === "richtext" ? /* @__PURE__ */ jsx5(
1428
+ "textarea",
1429
+ {
1430
+ value: String(editing[f.id] ?? ""),
1431
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
1432
+ rows: 4,
1433
+ className: "w-full rounded-xl border border-slate-200 px-4 py-3 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all font-mono text-xs"
1434
+ }
1435
+ ) : f.type === "icon" ? /* @__PURE__ */ jsx5(
1436
+ SearchableSelect,
1437
+ {
1438
+ value: String(editing[f.id] ?? ""),
1439
+ onChange: (val) => setEditing({ ...editing, [f.id]: val }),
1440
+ options: f.options || [],
1441
+ placeholder: `Search ${f.label.toLowerCase()}...`,
1442
+ iconMap: ctx.iconMap
1443
+ }
1444
+ ) : f.type === "select" ? /* @__PURE__ */ jsxs2("div", { children: [
1445
+ /* @__PURE__ */ jsx5(
1446
+ "input",
1447
+ {
1448
+ list: `${f.id}-list`,
1449
+ value: String(editing[f.id] ?? ""),
1450
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
1451
+ className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
1452
+ }
1453
+ ),
1454
+ /* @__PURE__ */ jsx5("datalist", { id: `${f.id}-list`, children: f.options?.map((opt) => {
1455
+ const val = typeof opt === "string" ? opt : opt.value;
1456
+ const lab = typeof opt === "string" ? opt : opt.label;
1457
+ return /* @__PURE__ */ jsx5("option", { value: val, children: lab }, val);
1458
+ }) })
1459
+ ] }) : f.type === "image" ? /* @__PURE__ */ jsxs2("div", { className: "space-y-3", children: [
1460
+ /* @__PURE__ */ jsxs2("div", { className: "flex gap-2", children: [
1461
+ /* @__PURE__ */ jsx5(
1462
+ "input",
1463
+ {
1464
+ type: "url",
1465
+ value: String(editing[f.id] ?? ""),
1466
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
1467
+ placeholder: "https://...",
1468
+ className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
1469
+ }
1470
+ ),
1471
+ /* @__PURE__ */ jsxs2("label", { className: "flex-shrink-0 cursor-pointer rounded-xl bg-slate-100 px-4 py-2.5 text-sm font-medium text-slate-700 hover:bg-slate-200 transition-colors border border-slate-200 flex items-center justify-center", children: [
1472
+ "Upload",
1473
+ /* @__PURE__ */ jsx5(
1474
+ "input",
1475
+ {
1476
+ type: "file",
1477
+ accept: "image/*",
1478
+ className: "hidden",
1479
+ onChange: (e) => {
1480
+ const file = e.target.files?.[0];
1481
+ if (file) {
1482
+ void handleImageFile(
1483
+ file,
1484
+ (url) => setEditing({ ...editing, [f.id]: url }),
1485
+ ctx.uploadImage
1486
+ );
1487
+ }
1488
+ }
1489
+ }
1490
+ )
1491
+ ] })
1492
+ ] }),
1493
+ editing[f.id] ? /* @__PURE__ */ jsx5("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: /* @__PURE__ */ jsx5(
1494
+ "img",
1495
+ {
1496
+ src: String(editing[f.id]),
1497
+ alt: "",
1498
+ className: "w-full h-auto max-h-48 object-contain rounded-lg"
1499
+ }
1500
+ ) }) : null
1501
+ ] }) : f.type === "password" ? /* @__PURE__ */ jsx5(
1502
+ PasswordField,
1503
+ {
1504
+ value: String(editing[f.id] ?? ""),
1505
+ onChange: (val) => setEditing({ ...editing, [f.id]: val })
1506
+ }
1507
+ ) : /* @__PURE__ */ jsx5(
1508
+ "input",
1509
+ {
1510
+ value: String(editing[f.id] ?? ""),
1511
+ onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
1512
+ className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
1513
+ }
1514
+ )
1515
+ ] }, f.id)) }),
1516
+ /* @__PURE__ */ jsxs2("div", { className: "mt-8 flex justify-end gap-3 pt-5 border-t border-slate-100", children: [
1517
+ /* @__PURE__ */ jsx5(
1518
+ "button",
1519
+ {
1520
+ onClick: () => setEditing(null),
1521
+ disabled: saving,
1522
+ className: "rounded-xl px-5 py-2.5 text-sm font-semibold text-slate-600 hover:bg-slate-100 transition-colors disabled:opacity-50",
1523
+ children: "Cancel"
1524
+ }
1525
+ ),
1526
+ /* @__PURE__ */ jsx5(
1527
+ "button",
1528
+ {
1529
+ onClick: save,
1530
+ disabled: saving,
1531
+ className: "inline-flex items-center gap-2 rounded-xl bg-slate-900 px-6 py-2.5 text-sm font-bold text-white shadow-sm hover:bg-slate-800 hover:shadow transition-all disabled:opacity-60",
1532
+ children: saving ? /* @__PURE__ */ jsxs2(Fragment, { children: [
1533
+ /* @__PURE__ */ jsxs2("svg", { className: "animate-spin h-4 w-4 text-white", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
1534
+ /* @__PURE__ */ jsx5("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
1535
+ /* @__PURE__ */ jsx5("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
1536
+ ] }),
1537
+ "Saving..."
1538
+ ] }) : "Save Entry"
1539
+ }
1540
+ )
1541
+ ] })
1542
+ ] }),
1543
+ /* @__PURE__ */ jsx5("div", { className: "overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm", children: /* @__PURE__ */ jsxs2("table", { className: "w-full text-sm text-left", children: [
1544
+ /* @__PURE__ */ jsx5("thead", { className: "bg-slate-50/80 border-b border-slate-200", children: /* @__PURE__ */ jsxs2("tr", { children: [
1545
+ visibleFields.map((f) => /* @__PURE__ */ jsx5("th", { className: "px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider", children: f.label }, f.id)),
1546
+ /* @__PURE__ */ jsx5("th", { className: "px-6 py-4 text-right text-xs font-bold text-slate-500 uppercase tracking-wider", children: "Actions" })
1547
+ ] }) }),
1548
+ /* @__PURE__ */ jsx5("tbody", { className: "divide-y divide-slate-100", children: loadingEntries ? (
1549
+ // Loading skeleton rows
1550
+ Array.from({ length: 3 }).map((_, i) => /* @__PURE__ */ jsxs2("tr", { children: [
1551
+ visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4", children: /* @__PURE__ */ jsx5("div", { className: "h-4 bg-slate-100 rounded animate-pulse", style: { width: `${60 + i * 13 % 30}%` } }) }, f.id)),
1552
+ /* @__PURE__ */ jsx5("td", { className: "px-6 py-4", children: /* @__PURE__ */ jsx5("div", { className: "h-4 w-16 bg-slate-100 rounded animate-pulse ml-auto" }) })
1553
+ ] }, i))
1554
+ ) : /* @__PURE__ */ jsxs2(Fragment, { children: [
1555
+ entries.map((e, idx) => /* @__PURE__ */ jsxs2(
1556
+ "tr",
1557
+ {
1558
+ draggable: true,
1559
+ onDragStart: (evt) => onDragStart(evt, idx),
1560
+ onDragOver: (evt) => onDragOver(evt, idx),
1561
+ onDrop: (evt) => onDrop(evt, idx),
1562
+ onDragEnd,
1563
+ className: `hover:bg-slate-50/50 transition-colors group cursor-grab active:cursor-grabbing ${deletingId === e.id ? "opacity-50" : ""} ${dragOverIdx === idx ? "border-t-2 border-t-indigo-500" : ""}`,
1564
+ children: [
1565
+ visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-slate-100 text-slate-500 text-xs font-bold", children: "No" }) : f.type === "image" && e[f.id] ? /* @__PURE__ */ jsx5("img", { src: String(e[f.id]), alt: "", className: "h-8 w-8 object-cover rounded shadow-sm ring-1 ring-slate-200" }) : f.type === "image" ? /* @__PURE__ */ jsx5("div", { className: "h-8 w-8 rounded bg-slate-100 ring-1 ring-slate-200/50 flex items-center justify-center text-slate-300", children: /* @__PURE__ */ jsx5("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" }) }) }) : String(e[f.id] ?? "") }, f.id)),
1566
+ /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-right", children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-end gap-2 opacity-0 group-hover:opacity-100 transition-opacity", children: [
1567
+ /* @__PURE__ */ jsx5("div", { className: "p-2 text-slate-300 cursor-grab active:cursor-grabbing", title: "Drag to reorder", children: /* @__PURE__ */ jsx5("svg", { width: "15", height: "15", viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "w-4 h-4", children: /* @__PURE__ */ jsx5("path", { d: "M5.5 3C6.32843 3 7 3.67157 7 4.5C7 5.32843 6.32843 6 5.5 6C4.67157 6 4 5.32843 4 4.5C4 3.67157 4.67157 3 5.5 3ZM9.5 3C10.3284 3 11 3.67157 11 4.5C11 5.32843 10.3284 6 9.5 6C8.67157 6 8 5.32843 8 4.5C8 3.67157 8.67157 3 9.5 3ZM5.5 7.5C6.32843 7.5 7 8.17157 7 9C7 9.82843 6.32843 10.5 5.5 10.5C4.67157 10.5 4 9.82843 4 9C4 8.17157 4.67157 7.5 5.5 7.5ZM9.5 7.5C10.3284 7.5 11 8.17157 11 9C11 9.82843 10.3284 10.5 9.5 10.5C8.67157 10.5 8 9.82843 8 9C8 8.17157 8.67157 7.5 9.5 7.5ZM5.5 12C6.32843 12 7 12.6716 7 13.5C7 14.3284 6.32843 15 5.5 15C4.67157 15 4 14.3284 4 13.5C4 12.6716 4.67157 12 5.5 12ZM9.5 12C10.3284 12 11 12.6716 11 13.5C11 14.3284 10.3284 15 9.5 15C8.67157 15 8 14.3284 8 13.5C8 12.6716 8.67157 12 9.5 12Z", fill: "currentColor", fillRule: "evenodd", clipRule: "evenodd" }) }) }),
1568
+ /* @__PURE__ */ jsx5(
1569
+ "button",
1570
+ {
1571
+ onClick: () => setEditing(e),
1572
+ className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
1573
+ title: "Edit",
1574
+ children: /* @__PURE__ */ jsx5(Pencil, { className: "h-4 w-4" })
1575
+ }
1576
+ ),
1577
+ /* @__PURE__ */ jsx5(
1578
+ "button",
1579
+ {
1580
+ onClick: () => remove(e.id),
1581
+ disabled: deletingId === e.id,
1582
+ className: "p-2 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors disabled:opacity-50",
1583
+ title: "Delete",
1584
+ children: deletingId === e.id ? /* @__PURE__ */ jsxs2("svg", { className: "animate-spin h-4 w-4", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
1585
+ /* @__PURE__ */ jsx5("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
1586
+ /* @__PURE__ */ jsx5("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
1587
+ ] }) : /* @__PURE__ */ jsx5(Trash2, { className: "h-4 w-4" })
1588
+ }
1589
+ )
1590
+ ] }) })
1591
+ ]
1592
+ },
1593
+ e.id
1594
+ )),
1595
+ entries.length === 0 && /* @__PURE__ */ jsx5("tr", { children: /* @__PURE__ */ jsx5(
1596
+ "td",
1597
+ {
1598
+ colSpan: visibleFields.length + 1,
1599
+ className: "px-6 py-12 text-center text-slate-500",
1600
+ children: /* @__PURE__ */ jsxs2("div", { className: "flex flex-col items-center justify-center", children: [
1601
+ /* @__PURE__ */ jsx5(Boxes, { className: "h-10 w-10 text-slate-300 mb-3" }),
1602
+ /* @__PURE__ */ jsx5("p", { children: 'No entries yet. Click "New Entry" to create one.' })
1603
+ ] })
1604
+ }
1605
+ ) })
1606
+ ] }) })
1607
+ ] }) })
1608
+ ] });
1609
+ }
1610
+ var PAGE_SIZE = 10;
1611
+ function SubmissionsSection() {
1612
+ const ctx = useCmsContext();
1613
+ const [submissions, setSubmissions] = useState4([]);
1614
+ const [loading, setLoading] = useState4(false);
1615
+ const [selectedFormId, setSelectedFormId] = useState4(null);
1616
+ const load = useCallback3(async () => {
1617
+ setLoading(true);
1618
+ const all = await ctx.adapter.listSubmissions();
1619
+ setSubmissions(all);
1620
+ setLoading(false);
1621
+ }, [ctx.adapter]);
1622
+ useEffect4(() => {
1623
+ load();
1624
+ }, [load]);
1625
+ const formIds = Array.from(new Set(submissions.map((s) => s.formId)));
1626
+ useEffect4(() => {
1627
+ if (!selectedFormId && formIds.length > 0) {
1628
+ setSelectedFormId(formIds[0]);
1629
+ }
1630
+ }, [formIds, selectedFormId]);
1631
+ return /* @__PURE__ */ jsxs2("div", { className: "flex h-full bg-slate-50", children: [
1632
+ /* @__PURE__ */ jsxs2("div", { className: "w-72 shrink-0 border-r border-slate-200 bg-white/50 p-4", children: [
1633
+ /* @__PURE__ */ jsx5("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500", children: "Data Collections" }),
1634
+ /* @__PURE__ */ jsxs2("ul", { className: "space-y-1", children: [
1635
+ formIds.map((id) => /* @__PURE__ */ jsx5("li", { children: /* @__PURE__ */ jsxs2(
1636
+ "button",
1637
+ {
1638
+ onClick: () => setSelectedFormId(id),
1639
+ className: `w-full rounded-lg px-3 py-2.5 text-left text-sm transition-all duration-200 ${selectedFormId === id ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
1640
+ children: [
1641
+ /* @__PURE__ */ jsx5("div", { className: selectedFormId === id ? "text-slate-900" : "text-slate-700 capitalize", children: id }),
1642
+ /* @__PURE__ */ jsxs2("div", { className: `text-xs mt-0.5 ${selectedFormId === id ? "text-indigo-500" : "text-slate-400"}`, children: [
1643
+ submissions.filter((s) => s.formId === id).length,
1644
+ " items"
1645
+ ] })
1646
+ ]
1647
+ }
1648
+ ) }, id)),
1649
+ formIds.length === 0 && /* @__PURE__ */ jsx5("li", { className: "px-3 py-6 text-center text-sm text-slate-500 bg-slate-50 rounded-lg border border-dashed border-slate-200", children: "No data collected." })
1650
+ ] })
1651
+ ] }),
1652
+ /* @__PURE__ */ jsxs2("div", { className: "flex-1 overflow-auto p-8 relative", children: [
1653
+ /* @__PURE__ */ jsx5("div", { className: "absolute inset-0 bg-grid-slate-100 [mask-image:linear-gradient(0deg,white,rgba(255,255,255,0.6))] -z-10 pointer-events-none" }),
1654
+ selectedFormId ? /* @__PURE__ */ jsx5(
1655
+ SubmissionsList,
1656
+ {
1657
+ formId: selectedFormId,
1658
+ submissions: submissions.filter((s) => s.formId === selectedFormId),
1659
+ onLoad: load,
1660
+ loading
1661
+ },
1662
+ selectedFormId
1663
+ ) : /* @__PURE__ */ jsx5("div", { className: "grid h-full place-items-center text-sm text-slate-500", children: "Select a collection to view entries." })
1664
+ ] })
1665
+ ] });
1666
+ }
1667
+ function SubmissionsList({ formId, submissions, onLoad, loading }) {
1668
+ const ctx = useCmsContext();
1669
+ const [search, setSearch] = useState4("");
1670
+ const [page, setPage] = useState4(1);
1671
+ const [detail, setDetail] = useState4(null);
1672
+ const filtered = submissions.filter((s) => {
1673
+ const q = search.toLowerCase();
1674
+ if (!q) return true;
1675
+ return s.submittedAt.includes(q) || Object.values(s.data).some((v) => String(v).toLowerCase().includes(q));
1676
+ });
1677
+ const totalPages = Math.max(1, Math.ceil(filtered.length / PAGE_SIZE));
1678
+ const paginated = filtered.slice((page - 1) * PAGE_SIZE, page * PAGE_SIZE);
1679
+ const openDetail = async (s) => {
1680
+ setDetail(s);
1681
+ if (!s.read) {
1682
+ await ctx.adapter.markSubmissionRead(s.id);
1683
+ onLoad();
1684
+ }
1685
+ };
1686
+ const deleteOne = async (id) => {
1687
+ if (!confirm("Delete this entry?")) return;
1688
+ await ctx.adapter.deleteSubmission(id);
1689
+ if (detail?.id === id) setDetail(null);
1690
+ onLoad();
1691
+ };
1692
+ const unreadCount = submissions.filter((s) => !s.read).length;
1693
+ const formatDate = (iso) => {
1694
+ try {
1695
+ return new Intl.DateTimeFormat("en-US", { dateStyle: "medium", timeStyle: "short" }).format(new Date(iso));
1696
+ } catch {
1697
+ return iso;
1698
+ }
1699
+ };
1700
+ if (detail) {
1701
+ return /* @__PURE__ */ jsxs2("div", { className: "mx-auto w-full max-w-2xl", children: [
1702
+ /* @__PURE__ */ jsxs2(
1703
+ "button",
1704
+ {
1705
+ onClick: () => setDetail(null),
1706
+ className: "mb-6 inline-flex items-center gap-2 text-sm font-medium text-slate-600 hover:text-slate-900 transition-colors",
1707
+ children: [
1708
+ /* @__PURE__ */ jsx5(ChevronLeft, { className: "h-4 w-4" }),
1709
+ " Back to list"
1710
+ ]
1711
+ }
1712
+ ),
1713
+ /* @__PURE__ */ jsxs2("div", { className: "rounded-2xl border border-slate-200 bg-white shadow-sm overflow-hidden", children: [
1714
+ /* @__PURE__ */ jsx5("div", { className: "px-8 py-6 border-b border-slate-100 bg-slate-50/50", children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between", children: [
1715
+ /* @__PURE__ */ jsxs2("div", { children: [
1716
+ /* @__PURE__ */ jsx5("span", { className: "inline-flex items-center gap-1.5 rounded-full bg-indigo-100 px-3 py-1 text-xs font-bold text-indigo-700 mb-2 capitalize", children: detail.formId }),
1717
+ /* @__PURE__ */ jsx5("p", { className: "text-xs text-slate-400", children: formatDate(detail.submittedAt) })
1718
+ ] }),
1719
+ /* @__PURE__ */ jsx5(
1720
+ "button",
1721
+ {
1722
+ onClick: () => deleteOne(detail.id),
1723
+ className: "p-2 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors",
1724
+ title: "Delete",
1725
+ children: /* @__PURE__ */ jsx5(Trash2, { className: "h-4 w-4" })
1726
+ }
1727
+ )
1728
+ ] }) }),
1729
+ /* @__PURE__ */ jsx5("div", { className: "px-8 py-6 divide-y divide-slate-100", children: Object.entries(detail.data).map(([key, val]) => /* @__PURE__ */ jsxs2("div", { className: "py-4 grid grid-cols-[160px_1fr] gap-4", children: [
1730
+ /* @__PURE__ */ jsx5("dt", { className: "text-xs font-bold uppercase tracking-wide text-slate-400 pt-0.5", children: key }),
1731
+ /* @__PURE__ */ jsx5("dd", { className: "text-sm text-slate-800 whitespace-pre-wrap", children: String(val ?? "\u2014") })
1732
+ ] }, key)) })
1733
+ ] })
1734
+ ] });
1735
+ }
1736
+ return /* @__PURE__ */ jsxs2("div", { className: "mx-auto w-full max-w-5xl flex flex-col h-full gap-6", children: [
1737
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between", children: [
1738
+ /* @__PURE__ */ jsxs2("div", { children: [
1739
+ /* @__PURE__ */ jsxs2("h2", { className: "text-2xl font-bold text-slate-900 tracking-tight flex items-center gap-3 capitalize", children: [
1740
+ formId,
1741
+ unreadCount > 0 && /* @__PURE__ */ jsx5("span", { className: "inline-flex h-6 min-w-[24px] items-center justify-center rounded-full bg-indigo-600 px-2 text-xs font-bold text-white", children: unreadCount })
1742
+ ] }),
1743
+ /* @__PURE__ */ jsx5("p", { className: "text-sm text-slate-500 mt-1", children: "Data received for this collection." })
1744
+ ] }),
1745
+ /* @__PURE__ */ jsxs2(
1746
+ "button",
1747
+ {
1748
+ onClick: onLoad,
1749
+ disabled: loading,
1750
+ className: "inline-flex items-center gap-2 rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm font-semibold text-slate-700 shadow-sm hover:bg-slate-50 transition-colors disabled:opacity-50",
1751
+ children: [
1752
+ /* @__PURE__ */ jsx5(RefreshCw, { className: `h-4 w-4 ${loading ? "animate-spin" : ""}` }),
1753
+ " Refresh"
1754
+ ]
1755
+ }
1756
+ )
1757
+ ] }),
1758
+ /* @__PURE__ */ jsxs2("div", { className: "relative", children: [
1759
+ /* @__PURE__ */ jsx5(Search, { className: "absolute left-4 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" }),
1760
+ /* @__PURE__ */ jsx5(
1761
+ "input",
1762
+ {
1763
+ value: search,
1764
+ onChange: (e) => {
1765
+ setSearch(e.target.value);
1766
+ setPage(1);
1767
+ },
1768
+ placeholder: `Search ${formId}...`,
1769
+ className: "w-full rounded-xl border border-slate-200 bg-white py-2.5 pl-11 pr-4 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 outline-none transition-all"
1770
+ }
1771
+ )
1772
+ ] }),
1773
+ /* @__PURE__ */ jsx5("div", { className: "flex-1 overflow-auto rounded-2xl border border-slate-200 bg-white shadow-sm", children: /* @__PURE__ */ jsxs2("table", { className: "w-full text-sm text-left", children: [
1774
+ /* @__PURE__ */ jsx5("thead", { className: "bg-slate-50/80 border-b border-slate-200 sticky top-0", children: /* @__PURE__ */ jsxs2("tr", { children: [
1775
+ /* @__PURE__ */ jsx5("th", { className: "px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider", children: "Summary" }),
1776
+ /* @__PURE__ */ jsx5("th", { className: "px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider", children: "Received" }),
1777
+ /* @__PURE__ */ jsx5("th", { className: "px-6 py-4 text-right text-xs font-bold text-slate-500 uppercase tracking-wider", children: "Actions" })
1778
+ ] }) }),
1779
+ /* @__PURE__ */ jsxs2("tbody", { className: "divide-y divide-slate-100", children: [
1780
+ paginated.map((s) => {
1781
+ const firstVal = Object.values(s.data)[0];
1782
+ const preview = firstVal ? String(firstVal).slice(0, 60) : "\u2014";
1783
+ return /* @__PURE__ */ jsxs2(
1784
+ "tr",
1785
+ {
1786
+ className: `hover:bg-slate-50/50 transition-colors group cursor-pointer ${!s.read ? "bg-indigo-50/40" : ""}`,
1787
+ onClick: () => openDetail(s),
1788
+ children: [
1789
+ /* @__PURE__ */ jsxs2("td", { className: "px-6 py-4", children: [
1790
+ /* @__PURE__ */ jsx5("span", { className: "text-slate-600 max-w-[400px] truncate block", children: preview }),
1791
+ !s.read && /* @__PURE__ */ jsx5("span", { className: "ml-2 inline-block h-2 w-2 rounded-full bg-indigo-500" })
1792
+ ] }),
1793
+ /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-slate-500 whitespace-nowrap", children: formatDate(s.submittedAt) }),
1794
+ /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-right", onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-opacity", children: [
1795
+ /* @__PURE__ */ jsx5(
1796
+ "button",
1797
+ {
1798
+ onClick: () => openDetail(s),
1799
+ className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
1800
+ title: "View detail",
1801
+ children: /* @__PURE__ */ jsx5(Eye, { className: "h-4 w-4" })
1802
+ }
1803
+ ),
1804
+ /* @__PURE__ */ jsx5(
1805
+ "button",
1806
+ {
1807
+ onClick: () => deleteOne(s.id),
1808
+ className: "p-2 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors",
1809
+ title: "Delete",
1810
+ children: /* @__PURE__ */ jsx5(Trash2, { className: "h-4 w-4" })
1811
+ }
1812
+ )
1813
+ ] }) })
1814
+ ]
1815
+ },
1816
+ s.id
1817
+ );
1818
+ }),
1819
+ paginated.length === 0 && /* @__PURE__ */ jsx5("tr", { children: /* @__PURE__ */ jsx5("td", { colSpan: 3, className: "px-6 py-16 text-center", children: /* @__PURE__ */ jsxs2("div", { className: "flex flex-col items-center gap-3 text-slate-400", children: [
1820
+ /* @__PURE__ */ jsx5(Inbox, { className: "h-12 w-12 text-slate-200" }),
1821
+ /* @__PURE__ */ jsx5("p", { className: "text-sm font-medium", children: search ? "No matches." : "No data yet." })
1822
+ ] }) }) })
1823
+ ] })
1824
+ ] }) }),
1825
+ totalPages > 1 && /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between text-sm text-slate-500", children: [
1826
+ /* @__PURE__ */ jsxs2("span", { children: [
1827
+ filtered.length,
1828
+ " item",
1829
+ filtered.length !== 1 ? "s" : ""
1830
+ ] }),
1831
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2", children: [
1832
+ /* @__PURE__ */ jsx5(
1833
+ "button",
1834
+ {
1835
+ onClick: () => setPage((p) => Math.max(1, p - 1)),
1836
+ disabled: page === 1,
1837
+ className: "p-2 rounded-lg hover:bg-slate-100 disabled:opacity-30 transition-colors",
1838
+ children: /* @__PURE__ */ jsx5(ChevronLeft, { className: "h-4 w-4" })
1839
+ }
1840
+ ),
1841
+ /* @__PURE__ */ jsxs2("span", { className: "font-medium text-slate-700", children: [
1842
+ "Page ",
1843
+ page,
1844
+ " of ",
1845
+ totalPages
1846
+ ] }),
1847
+ /* @__PURE__ */ jsx5(
1848
+ "button",
1849
+ {
1850
+ onClick: () => setPage((p) => Math.min(totalPages, p + 1)),
1851
+ disabled: page === totalPages,
1852
+ className: "p-2 rounded-lg hover:bg-slate-100 disabled:opacity-30 transition-colors",
1853
+ children: /* @__PURE__ */ jsx5(ChevronRight, { className: "h-4 w-4" })
1854
+ }
1855
+ )
1856
+ ] })
1857
+ ] })
1858
+ ] });
1859
+ }
1860
+ function SettingsSection() {
1861
+ const ctx = useCmsContext();
1862
+ return /* @__PURE__ */ jsx5("div", { className: "flex h-full bg-slate-50 p-8 overflow-y-auto", children: /* @__PURE__ */ jsxs2("div", { className: "mx-auto w-full max-w-2xl space-y-8", children: [
1863
+ /* @__PURE__ */ jsxs2("div", { children: [
1864
+ /* @__PURE__ */ jsx5("h2", { className: "text-2xl font-bold text-slate-900 tracking-tight", children: "System Settings" }),
1865
+ /* @__PURE__ */ jsx5("p", { className: "text-sm text-slate-500 mt-1", children: "Current configuration and statistics for your CMS instance." })
1866
+ ] }),
1867
+ /* @__PURE__ */ jsxs2("div", { className: "rounded-2xl border border-slate-200 bg-white shadow-sm overflow-hidden", children: [
1868
+ /* @__PURE__ */ jsx5("div", { className: "px-6 py-4 border-b border-slate-100 bg-slate-50/50", children: /* @__PURE__ */ jsx5("h3", { className: "font-bold text-slate-800", children: "Configuration Snapshot" }) }),
1869
+ /* @__PURE__ */ jsxs2("dl", { className: "divide-y divide-slate-100 text-sm", children: [
1870
+ /* @__PURE__ */ jsx5(Row, { label: "Site Name", value: ctx.config.siteName ?? "\u2014" }),
1871
+ /* @__PURE__ */ jsx5(Row, { label: "Active Storage Adapter", value: ctx.adapter.name, highlight: true }),
1872
+ /* @__PURE__ */ jsx5(Row, { label: "Registered Pages", value: String(ctx.config.pages.length) }),
1873
+ /* @__PURE__ */ jsx5(
1874
+ Row,
1875
+ {
1876
+ label: "Defined Collections",
1877
+ value: String(ctx.config.collections?.length ?? 0)
1878
+ }
1879
+ ),
1880
+ /* @__PURE__ */ jsx5(
1881
+ Row,
1882
+ {
1883
+ label: "Editable Fields (Current Page)",
1884
+ value: String(ctx.getRegistered().length)
1885
+ }
1886
+ ),
1887
+ /* @__PURE__ */ jsx5(
1888
+ Row,
1889
+ {
1890
+ label: "Unsaved Changes",
1891
+ value: ctx.isDirty ? "Yes (Needs saving)" : "No (All synced)",
1892
+ status: ctx.isDirty ? "warning" : "success"
1893
+ }
1894
+ )
1895
+ ] })
1896
+ ] })
1897
+ ] }) });
1898
+ }
1899
+ function ConfigSection() {
1900
+ const ctx = useCmsContext();
1901
+ const globals = ctx.config.globals ?? [];
1902
+ const [selectedGroupId, setSelectedGroupId] = useState4(
1903
+ globals[0]?.id ?? null
1904
+ );
1905
+ const selectedGroup = globals.find((g) => g.id === selectedGroupId) ?? null;
1906
+ const updateOverride = useCallback3(
1907
+ (id, value) => {
1908
+ ctx.setOverride(id, value);
1909
+ },
1910
+ [ctx]
1911
+ );
1912
+ return /* @__PURE__ */ jsxs2("div", { className: "flex flex-col lg:flex-row h-full", children: [
1913
+ /* @__PURE__ */ jsxs2("div", { className: "w-full lg:w-72 shrink-0 border-b lg:border-b-0 lg:border-r border-slate-200 bg-white/50 p-3 lg:p-4 overflow-x-auto lg:overflow-y-auto hide-scrollbar", children: [
1914
+ /* @__PURE__ */ jsx5("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500 hidden lg:block", children: "Configuration Groups" }),
1915
+ /* @__PURE__ */ jsxs2("ul", { className: "flex flex-row lg:flex-col space-x-2 lg:space-x-0 lg:space-y-1", children: [
1916
+ globals.map((g) => /* @__PURE__ */ jsx5("li", { className: "shrink-0 w-32 lg:w-full", children: /* @__PURE__ */ jsx5(
1917
+ "button",
1918
+ {
1919
+ onClick: () => setSelectedGroupId(g.id),
1920
+ className: `w-full rounded-lg px-3 py-2.5 text-left text-sm transition-all duration-200 ${selectedGroupId === g.id ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
1921
+ children: /* @__PURE__ */ jsx5("div", { className: `truncate ${selectedGroupId === g.id ? "text-slate-900" : "text-slate-700"}`, children: g.label })
1922
+ }
1923
+ ) }, g.id)),
1924
+ globals.length === 0 && /* @__PURE__ */ jsx5("li", { className: "px-3 py-6 text-center text-sm text-slate-500 bg-slate-50 rounded-lg border border-dashed border-slate-200 w-full", children: "No global configurations." })
1925
+ ] })
1926
+ ] }),
1927
+ /* @__PURE__ */ jsx5("div", { className: "flex-1 overflow-auto bg-slate-50 p-6 lg:p-10 relative", children: /* @__PURE__ */ jsxs2("div", { className: "mx-auto w-full max-w-2xl", children: [
1928
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between mb-8", children: [
1929
+ /* @__PURE__ */ jsxs2("div", { children: [
1930
+ /* @__PURE__ */ jsx5("h2", { className: "text-2xl font-bold text-slate-900 tracking-tight", children: "Configuration" }),
1931
+ /* @__PURE__ */ jsx5("p", { className: "text-sm text-slate-500 mt-1", children: "Edit global content like headers and footers." })
1932
+ ] }),
1933
+ /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-2", children: [
1934
+ /* @__PURE__ */ jsxs2(
1935
+ "button",
1936
+ {
1937
+ onClick: () => ctx.reset(),
1938
+ disabled: !ctx.isDirty,
1939
+ className: "inline-flex items-center gap-1.5 rounded-lg border border-slate-200 px-3 py-1.5 text-xs font-semibold text-slate-700 hover:bg-slate-50 hover:text-slate-900 disabled:opacity-50 transition-colors bg-white shadow-sm",
1940
+ children: [
1941
+ /* @__PURE__ */ jsx5(X, { className: "h-3.5 w-3.5" }),
1942
+ "Discard"
1943
+ ]
1944
+ }
1945
+ ),
1946
+ /* @__PURE__ */ jsxs2(
1947
+ "button",
1948
+ {
1949
+ onClick: () => ctx.save(),
1950
+ disabled: !ctx.isDirty,
1951
+ className: "inline-flex items-center gap-1.5 rounded-lg bg-indigo-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-indigo-700 disabled:opacity-50 transition-colors shadow-sm",
1952
+ children: [
1953
+ /* @__PURE__ */ jsx5(Boxes, { className: "h-3.5 w-3.5" }),
1954
+ "Save"
1955
+ ]
1956
+ }
1957
+ )
1958
+ ] })
1959
+ ] }),
1960
+ selectedGroup ? /* @__PURE__ */ jsxs2("div", { className: "space-y-4", children: [
1961
+ /* @__PURE__ */ jsx5("h3", { className: "font-bold text-slate-800 text-lg", children: selectedGroup.label }),
1962
+ /* @__PURE__ */ jsx5("div", { className: "rounded-2xl border border-slate-200 bg-white shadow-sm overflow-hidden divide-y divide-slate-100", children: selectedGroup.fields.map((field) => /* @__PURE__ */ jsx5("div", { className: "p-4", children: /* @__PURE__ */ jsx5(
1963
+ FieldEditor,
1964
+ {
1965
+ meta: field,
1966
+ value: ctx.overrides[field.id] ?? field.defaultValue,
1967
+ onChange: (v) => updateOverride(field.id, v),
1968
+ onReset: () => ctx.reset(field.id),
1969
+ onClose: () => {
1970
+ }
1971
+ }
1972
+ ) }, field.id)) })
1973
+ ] }) : /* @__PURE__ */ jsxs2("div", { className: "flex flex-col items-center justify-center p-16 text-center border-2 border-dashed border-slate-200 rounded-2xl bg-white/50", children: [
1974
+ /* @__PURE__ */ jsx5(SettingsIcon, { className: "w-12 h-12 text-slate-300 mb-4" }),
1975
+ /* @__PURE__ */ jsx5("p", { className: "text-slate-500 font-medium", children: "Select a setting group on the left to edit." })
1976
+ ] })
1977
+ ] }) })
1978
+ ] });
1979
+ }
1980
+ function Row({
1981
+ label,
1982
+ value,
1983
+ highlight,
1984
+ status
1985
+ }) {
1986
+ return /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between px-6 py-4 hover:bg-slate-50/50 transition-colors", children: [
1987
+ /* @__PURE__ */ jsx5("dt", { className: "text-slate-500 font-medium", children: label }),
1988
+ /* @__PURE__ */ jsx5("dd", { className: `font-semibold ${highlight ? "text-indigo-600 bg-indigo-50 px-2 py-0.5 rounded" : status === "warning" ? "text-amber-600" : status === "success" ? "text-emerald-600" : "text-slate-900"}`, children: value })
1989
+ ] });
1990
+ }
1991
+ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
1992
+ const [open, setOpen] = useState4(false);
1993
+ const [search, setSearch] = useState4("");
1994
+ const filtered = options.filter((o) => o.toLowerCase().includes(search.toLowerCase()));
1995
+ const capped = filtered.slice(0, 80);
1996
+ const SelectedIcon = iconMap && value ? iconMap[value] : null;
1997
+ return /* @__PURE__ */ jsxs2("div", { className: "relative", children: [
1998
+ /* @__PURE__ */ jsxs2(
1999
+ "button",
2000
+ {
2001
+ type: "button",
2002
+ onClick: () => {
2003
+ setOpen(!open);
2004
+ setSearch("");
2005
+ },
2006
+ className: "w-full flex items-center justify-between rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800 shadow-sm hover:border-slate-300 focus:border-indigo-500 bg-white transition-colors",
2007
+ children: [
2008
+ /* @__PURE__ */ jsxs2("span", { className: "flex items-center gap-2 truncate", children: [
2009
+ SelectedIcon && /* @__PURE__ */ jsx5(SelectedIcon, { className: "w-4 h-4 text-indigo-600 shrink-0" }),
2010
+ /* @__PURE__ */ jsx5("span", { className: "truncate", children: value || placeholder || "Select..." })
2011
+ ] }),
2012
+ /* @__PURE__ */ jsx5(ChevronDown, { className: `w-4 h-4 text-slate-400 transition-transform shrink-0 ${open ? "rotate-180" : ""}` })
2013
+ ]
2014
+ }
2015
+ ),
2016
+ open && /* @__PURE__ */ jsxs2(Fragment, { children: [
2017
+ /* @__PURE__ */ jsx5("div", { className: "fixed inset-0 z-[100]", onClick: () => setOpen(false) }),
2018
+ /* @__PURE__ */ jsxs2("div", { className: "absolute z-[101] mt-1 w-full rounded-xl border border-slate-200 bg-white shadow-2xl max-h-72 flex flex-col overflow-hidden animate-in fade-in slide-in-from-top-1 duration-150", children: [
2019
+ /* @__PURE__ */ jsxs2("div", { className: "p-2 border-b border-slate-100 flex items-center gap-2", children: [
2020
+ /* @__PURE__ */ jsx5(Search, { className: "w-4 h-4 text-slate-400 shrink-0" }),
2021
+ /* @__PURE__ */ jsx5(
2022
+ "input",
2023
+ {
2024
+ autoFocus: true,
2025
+ type: "text",
2026
+ className: "w-full text-sm outline-none bg-transparent text-slate-800 placeholder:text-slate-400",
2027
+ placeholder: "Type to search\u2026",
2028
+ value: search,
2029
+ onChange: (e) => setSearch(e.target.value)
2030
+ }
2031
+ ),
2032
+ search && /* @__PURE__ */ jsx5("span", { className: "text-[10px] font-bold text-slate-400 bg-slate-100 px-1.5 py-0.5 rounded-full shrink-0 tabular-nums", children: filtered.length })
2033
+ ] }),
2034
+ /* @__PURE__ */ jsxs2("div", { className: "overflow-y-auto flex-1 p-1", children: [
2035
+ filtered.length === 0 && /* @__PURE__ */ jsxs2("div", { className: "p-4 text-xs text-slate-500 text-center", children: [
2036
+ 'No results for "',
2037
+ search,
2038
+ '"'
2039
+ ] }),
2040
+ capped.map((opt) => {
2041
+ const OptIcon = iconMap ? iconMap[opt] : null;
2042
+ return /* @__PURE__ */ jsxs2(
2043
+ "button",
2044
+ {
2045
+ type: "button",
2046
+ className: `w-full flex items-center gap-2.5 text-left px-2.5 py-1.5 text-sm rounded-lg transition-colors ${value === opt ? "bg-indigo-50 text-indigo-700 font-medium" : "text-slate-700 hover:bg-slate-50"}`,
2047
+ onClick: () => {
2048
+ onChange(opt);
2049
+ setOpen(false);
2050
+ },
2051
+ children: [
2052
+ OptIcon && /* @__PURE__ */ jsx5("span", { className: "w-5 h-5 flex items-center justify-center rounded bg-slate-100 shrink-0", children: /* @__PURE__ */ jsx5(OptIcon, { className: "w-3.5 h-3.5" }) }),
2053
+ /* @__PURE__ */ jsx5("span", { className: "truncate", children: opt })
2054
+ ]
2055
+ },
2056
+ opt
2057
+ );
2058
+ }),
2059
+ filtered.length > 80 && /* @__PURE__ */ jsxs2("div", { className: "px-3 py-2 text-[10px] text-slate-400 text-center border-t border-slate-100 mt-1", children: [
2060
+ "Showing 80 of ",
2061
+ filtered.length,
2062
+ " \u2014 type to narrow results"
2063
+ ] })
2064
+ ] })
2065
+ ] })
2066
+ ] })
2067
+ ] });
2068
+ }
2069
+ function PasswordField({ value, onChange }) {
2070
+ const [show, setShow] = useState4(false);
2071
+ const isHash = value.startsWith("$2a$") || value.startsWith("$2b$");
2072
+ const [displayValue, setDisplayValue] = useState4(isHash ? "" : value);
2073
+ const [pristine, setPristine] = useState4(isHash);
2074
+ return /* @__PURE__ */ jsxs2("div", { className: "relative", children: [
2075
+ /* @__PURE__ */ jsx5(
2076
+ "input",
2077
+ {
2078
+ type: show ? "text" : "password",
2079
+ value: pristine ? "" : displayValue,
2080
+ onChange: (e) => {
2081
+ setPristine(false);
2082
+ setDisplayValue(e.target.value);
2083
+ onChange(e.target.value);
2084
+ },
2085
+ placeholder: pristine ? "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022 (unchanged)" : "Enter new password",
2086
+ className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all pr-10"
2087
+ }
2088
+ ),
2089
+ /* @__PURE__ */ jsx5(
2090
+ "button",
2091
+ {
2092
+ type: "button",
2093
+ onClick: () => setShow(!show),
2094
+ className: "absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 transition-colors",
2095
+ children: show ? /* @__PURE__ */ jsx5(EyeOff, { className: "w-4 h-4" }) : /* @__PURE__ */ jsx5(Eye, { className: "w-4 h-4" })
2096
+ }
2097
+ )
2098
+ ] });
2099
+ }
2100
+
2101
+ // src/admin/AdminLogin.tsx
2102
+ import { useState as useState5, useEffect as useEffect5 } from "react";
2103
+ import { Lock, UserPlus } from "lucide-react";
2104
+ import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
2105
+ function AdminLogin({
2106
+ authApiRoute = "/api/admin/auth",
2107
+ redirectRoute = "/admin"
2108
+ }) {
2109
+ const [email, setEmail] = useState5("");
2110
+ const [password, setPassword] = useState5("");
2111
+ const [error, setError] = useState5("");
2112
+ const [loading, setLoading] = useState5(false);
2113
+ const [view, setView] = useState5("checking");
2114
+ useEffect5(() => {
2115
+ fetch(authApiRoute).then((res) => res.json()).then((data) => {
2116
+ if (data.hasUsers) {
2117
+ setView("login");
2118
+ } else {
2119
+ setView("register");
2120
+ }
2121
+ }).catch((err) => {
2122
+ console.error("Failed to check auth state:", err);
2123
+ setError("Unable to connect to authentication server.");
2124
+ setView("login");
2125
+ });
2126
+ }, [authApiRoute]);
2127
+ const handleSubmit = async (e) => {
2128
+ e.preventDefault();
2129
+ setLoading(true);
2130
+ setError("");
2131
+ try {
2132
+ const url = new URL(authApiRoute, window.location.origin);
2133
+ url.searchParams.set("action", view);
2134
+ const res = await fetch(url.toString(), {
2135
+ method: "POST",
2136
+ headers: { "Content-Type": "application/json" },
2137
+ body: JSON.stringify({ email, password })
2138
+ });
2139
+ if (!res.ok) {
2140
+ const data = await res.json();
2141
+ throw new Error(data.error || "Authentication failed");
2142
+ }
2143
+ window.location.href = redirectRoute;
2144
+ } catch (err) {
2145
+ setError(err.message || "An unexpected error occurred");
2146
+ setLoading(false);
2147
+ }
2148
+ };
2149
+ if (view === "checking") {
2150
+ return /* @__PURE__ */ jsx6("div", { className: "min-h-screen flex items-center justify-center bg-slate-50 p-4", children: /* @__PURE__ */ jsxs3("svg", { className: "animate-spin h-8 w-8 text-indigo-600", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
2151
+ /* @__PURE__ */ jsx6("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
2152
+ /* @__PURE__ */ jsx6("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })
2153
+ ] }) });
2154
+ }
2155
+ return /* @__PURE__ */ jsx6("div", { className: "min-h-screen flex items-center justify-center bg-slate-50 p-4", children: /* @__PURE__ */ jsxs3("div", { className: "max-w-md w-full bg-white rounded-2xl shadow-xl border border-slate-100 overflow-hidden", children: [
2156
+ /* @__PURE__ */ jsxs3("div", { className: "p-8", children: [
2157
+ /* @__PURE__ */ jsx6("div", { className: "w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mx-auto mb-6", children: view === "register" ? /* @__PURE__ */ jsx6(UserPlus, { className: "w-6 h-6 text-indigo-600" }) : /* @__PURE__ */ jsx6(Lock, { className: "w-6 h-6 text-indigo-600" }) }),
2158
+ /* @__PURE__ */ jsx6("h1", { className: "text-2xl font-bold text-slate-900 text-center mb-2", children: view === "register" ? "Create Admin Account" : "Admin Login" }),
2159
+ /* @__PURE__ */ jsx6("p", { className: "text-sm text-slate-500 text-center mb-8", children: view === "register" ? "No admin users found. Create the first admin account to get started." : "Sign in to manage your content." }),
2160
+ error && /* @__PURE__ */ jsx6("div", { className: "mb-6 bg-red-50 text-red-700 p-3 rounded-lg text-sm border border-red-100", children: error }),
2161
+ /* @__PURE__ */ jsxs3("form", { onSubmit: handleSubmit, className: "space-y-5", children: [
2162
+ /* @__PURE__ */ jsxs3("div", { children: [
2163
+ /* @__PURE__ */ jsx6("label", { className: "block text-sm font-medium text-slate-700 mb-1.5", children: "Email Address" }),
2164
+ /* @__PURE__ */ jsx6(
2165
+ "input",
2166
+ {
2167
+ type: "email",
2168
+ required: true,
2169
+ value: email,
2170
+ onChange: (e) => setEmail(e.target.value),
2171
+ className: "w-full rounded-xl border border-slate-300 px-4 py-3 text-sm text-slate-900 focus:outline-none focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all shadow-sm",
2172
+ placeholder: "admin@example.com"
2173
+ }
2174
+ )
2175
+ ] }),
2176
+ /* @__PURE__ */ jsxs3("div", { children: [
2177
+ /* @__PURE__ */ jsx6("label", { className: "block text-sm font-medium text-slate-700 mb-1.5", children: "Password" }),
2178
+ /* @__PURE__ */ jsx6(
2179
+ "input",
2180
+ {
2181
+ type: "password",
2182
+ required: true,
2183
+ value: password,
2184
+ onChange: (e) => setPassword(e.target.value),
2185
+ className: "w-full rounded-xl border border-slate-300 px-4 py-3 text-sm text-slate-900 focus:outline-none focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all shadow-sm",
2186
+ placeholder: "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"
2187
+ }
2188
+ )
2189
+ ] }),
2190
+ /* @__PURE__ */ jsx6(
2191
+ "button",
2192
+ {
2193
+ type: "submit",
2194
+ disabled: loading,
2195
+ className: "w-full bg-indigo-600 text-white font-semibold rounded-xl px-4 py-3 hover:bg-indigo-700 focus:outline-none focus:ring-4 focus:ring-indigo-500/20 transition-all shadow-md disabled:opacity-70 flex justify-center items-center",
2196
+ children: loading ? /* @__PURE__ */ jsxs3("svg", { className: "animate-spin h-5 w-5 text-white", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
2197
+ /* @__PURE__ */ jsx6("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
2198
+ /* @__PURE__ */ jsx6("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })
2199
+ ] }) : view === "register" ? "Create Account" : "Sign In"
2200
+ }
2201
+ )
2202
+ ] })
2203
+ ] }),
2204
+ /* @__PURE__ */ jsx6("div", { className: "bg-slate-50 border-t border-slate-100 p-4 text-center text-xs text-slate-400", children: "Powered by Portable CMS" })
2205
+ ] }) });
2206
+ }
2207
+ export {
2208
+ AdminApp,
2209
+ AdminLogin,
2210
+ CmsProvider,
2211
+ EditableImage,
2212
+ EditableLink,
2213
+ EditableList,
2214
+ EditableText,
2215
+ SubscriptionPage,
2216
+ SubscriptionProvider,
2217
+ generateEmailTemplate,
2218
+ useCmsContext,
2219
+ useCmsOptional,
2220
+ useSubmit,
2221
+ useSubscription,
2222
+ useSubscriptionContext
2223
+ };