@chaibuilder/pages 0.4.18 → 0.4.19

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.
@@ -1,737 +0,0 @@
1
- import { jsx as e, jsxs as l, Fragment as z } from "react/jsx-runtime";
2
- import te, { useState as f, useMemo as be, useEffect as Z, useCallback as T, Suspense as Ae } from "react";
3
- import { mergeClasses as le } from "@chaibuilder/sdk";
4
- import { Button as m, Label as q, Textarea as Se, Input as Ce, Dialog as Ee, DialogContent as ke, DialogHeader as De, DialogTitle as Te, DialogDescription as Pe, DialogFooter as je } from "@chaibuilder/sdk/ui";
5
- import { find as ze, merge as Fe, pick as Ie, first as Ue } from "lodash-es";
6
- import { Loader as F, AlertCircle as $e, ChevronLeft as Be, Pencil as qe, Search as Le, Archive as Me, Film as Oe, ImageIcon as _e, Edit as Ke, Trash2 as Qe, Check as Ge, Upload as Re } from "lucide-react";
7
- import { useDropzone as Ve } from "react-dropzone";
8
- import { useQueryClient as K, useMutation as Q, useQuery as ie } from "@tanstack/react-query";
9
- import { toast as P } from "sonner";
10
- import { W as I, X as U, Y as v, Z as $ } from "./index-DOVQkWCn.js";
11
- const We = () => {
12
- const n = I(), a = K(), s = U();
13
- return Q({
14
- mutationFn: async ({
15
- file: i,
16
- folderId: o,
17
- name: r
18
- }) => s(n, {
19
- action: v.UPLOAD_ASSET,
20
- data: { file: i, folderId: o, name: r }
21
- }),
22
- onSuccess: (i) => {
23
- if (i != null && i.error)
24
- throw new Error(i == null ? void 0 : i.error);
25
- a.invalidateQueries({
26
- queryKey: [$, v.GET_ASSETS]
27
- }), P.success("Asset uploaded successfully");
28
- },
29
- onError: () => {
30
- P.error("Failed to upload asset");
31
- }
32
- });
33
- }, Ye = () => {
34
- const n = I(), a = K(), s = U();
35
- return Q({
36
- mutationFn: async (i) => s(n, {
37
- action: v.DELETE_ASSET,
38
- data: { id: i }
39
- }),
40
- onSuccess: (i) => {
41
- if (i != null && i.error)
42
- throw new Error(i == null ? void 0 : i.error);
43
- a.invalidateQueries({
44
- queryKey: [$, v.GET_ASSETS]
45
- }), P.success("Asset deleted successfully");
46
- },
47
- onError: () => {
48
- P.error("Failed to delete asset");
49
- }
50
- });
51
- }, He = () => {
52
- const n = I(), a = K(), s = U();
53
- return Q({
54
- mutationFn: async (i) => s(n, {
55
- action: v.UPDATE_ASSET,
56
- data: i
57
- }),
58
- onSuccess: (i) => {
59
- if (i != null && i.error)
60
- throw new Error(i == null ? void 0 : i.error);
61
- a.invalidateQueries({
62
- queryKey: [$, v.GET_ASSETS]
63
- }), P.success("Asset updated successfully");
64
- },
65
- onError: () => {
66
- P.error("Failed to update asset");
67
- }
68
- });
69
- }, Xe = (n = {}) => {
70
- const a = I(), s = U(), { search: i, page: o = 1, limit: r = 30 } = n;
71
- return ie({
72
- queryKey: [$, v.GET_ASSETS, i, o, r],
73
- queryFn: async () => {
74
- const x = await s(a, {
75
- action: v.GET_ASSETS,
76
- data: {
77
- search: i,
78
- page: o,
79
- limit: r
80
- }
81
- });
82
- return x.page = o, x.limit = r, x;
83
- },
84
- staleTime: 1e3 * 60 * 5,
85
- retry: 1
86
- });
87
- }, Ze = (n) => {
88
- const a = I(), s = U();
89
- return ie({
90
- queryKey: [$, v.GET_ASSET, n],
91
- queryFn: async () => n ? await s(a, {
92
- action: v.GET_ASSET,
93
- data: { id: n }
94
- }) : null,
95
- staleTime: 1e3 * 60 * 5,
96
- retry: 1
97
- });
98
- };
99
- function Je(n) {
100
- const a = isNaN(n) ? 0 : typeof n == "number" ? n : parseInt(n);
101
- return a ? a < 1024 ? `${a.toFixed(2)} B` : a < 1024 * 1024 ? `${(a / 1024).toFixed(2)} KB` : `${(a / (1024 * 1024)).toFixed(2)} MB` : "0 B";
102
- }
103
- function J(n) {
104
- if (!n) return "N/A";
105
- const a = new Date(n);
106
- return new Intl.DateTimeFormat("en-US", {
107
- month: "short",
108
- day: "numeric",
109
- year: "numeric",
110
- hour: "2-digit",
111
- minute: "2-digit"
112
- }).format(a);
113
- }
114
- function ee(n, a) {
115
- let s = n, i = a == null ? void 0 : a.description;
116
- return (!i || typeof i != "string") && (i = ""), (!s || typeof s != "string") && (s = ""), s !== i;
117
- }
118
- const et = ({
119
- assetId: n,
120
- onBack: a,
121
- onEdit: s,
122
- onSave: i,
123
- isSaving: o
124
- }) => {
125
- var p, A, S;
126
- const { data: r, isLoading: x, isError: N } = Ze(n || ""), [g, u] = f("");
127
- return te.useEffect(() => {
128
- r != null && r.description && u(r.description);
129
- }, [r]), x ? /* @__PURE__ */ e("div", { className: "flex-1 flex items-center justify-center", children: /* @__PURE__ */ e(F, { className: "h-8 w-8 animate-spin" }) }) : N || !(r != null && r.id) ? /* @__PURE__ */ e("div", { className: "flex-1 flex items-center justify-center", children: /* @__PURE__ */ l("div", { className: "text-center max-w-md mx-auto p-6", children: [
130
- /* @__PURE__ */ e("div", { className: "flex justify-center mb-4", children: /* @__PURE__ */ e($e, { className: "h-12 w-12 text-gray-400" }) }),
131
- /* @__PURE__ */ e("h3", { className: "text-lg font-medium text-gray-900 mb-2", children: "No Asset Found" }),
132
- /* @__PURE__ */ e("p", { className: "text-sm text-gray-500 mb-6", children: N ? "There was an error loading the asset. Please try again later." : "The asset you're looking for doesn't exist or has been removed." }),
133
- /* @__PURE__ */ l("div", { className: "flex justify-center gap-4", children: [
134
- /* @__PURE__ */ e(m, { variant: "outline", onClick: a, children: "Back to Assets" }),
135
- N && /* @__PURE__ */ e(
136
- m,
137
- {
138
- variant: "default",
139
- onClick: () => window.location.reload(),
140
- children: "Try Again"
141
- }
142
- )
143
- ] })
144
- ] }) }) : /* @__PURE__ */ l("div", { className: "flex-1 flex flex-col gap-y-4 overflow-hidden", children: [
145
- /* @__PURE__ */ l("div", { className: "flex items-center justify-between", children: [
146
- /* @__PURE__ */ l(
147
- m,
148
- {
149
- variant: "outline",
150
- size: "sm",
151
- onClick: a,
152
- disabled: o,
153
- children: [
154
- /* @__PURE__ */ e(Be, { className: "h-4 w-4" }),
155
- "Back to Assets"
156
- ]
157
- }
158
- ),
159
- /* @__PURE__ */ l("div", { className: "flex gap-2", children: [
160
- /* @__PURE__ */ e(m, { variant: "outline", onClick: a, disabled: o, children: "Cancel" }),
161
- /* @__PURE__ */ l(
162
- m,
163
- {
164
- variant: "default",
165
- onClick: () => s(r),
166
- disabled: o,
167
- children: [
168
- /* @__PURE__ */ e(qe, { className: "h-4 w-4" }),
169
- "Edit Image"
170
- ]
171
- }
172
- )
173
- ] })
174
- ] }),
175
- /* @__PURE__ */ l("div", { className: "grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden", children: [
176
- /* @__PURE__ */ e("div", { className: "relative h-[calc(80vh-200px)] w-full flex items-start justify-center", children: /* @__PURE__ */ e(
177
- "img",
178
- {
179
- src: `${r.url}?v=${((p = r.metadata) == null ? void 0 : p.updatedAt) || r.createdAt}`,
180
- alt: r.name,
181
- className: "w-full h-full object-contain rounded-lg max-h-max max-w-max shadow-2xl shadow-black/30"
182
- }
183
- ) }),
184
- /* @__PURE__ */ l("div", { className: "space-y-6", children: [
185
- /* @__PURE__ */ l("div", { className: "grid gap-3 border rounded-md pt-2 bg-gray-100", children: [
186
- /* @__PURE__ */ e(q, { className: "w-full text-center", children: "Details" }),
187
- /* @__PURE__ */ e("div", { className: "grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white", children: [
188
- { label: "File Name", value: r.name },
189
- { label: "Type", value: r.type, capitalize: !0 },
190
- {
191
- label: "Format",
192
- value: ((A = r.metadata) == null ? void 0 : A.format) || r.type,
193
- capitalize: !0
194
- },
195
- {
196
- label: "Size",
197
- value: Je(r.size)
198
- },
199
- {
200
- label: "Dimensions",
201
- value: `${r.width || 0} × ${r.height || 0}`
202
- },
203
- {
204
- label: "Created",
205
- value: J(r.createdAt)
206
- },
207
- {
208
- label: "Updated",
209
- value: J(
210
- ((S = r.metadata) == null ? void 0 : S.updatedAt) || r.createdAt
211
- )
212
- }
213
- ].map((c) => /* @__PURE__ */ l("div", { className: "flex items-center gap-2", children: [
214
- /* @__PURE__ */ e(q, { className: "w-max text-left px-2 w-1/4 font-normal text-gray-700", children: c.label }),
215
- ":",
216
- /* @__PURE__ */ e(
217
- "div",
218
- {
219
- className: "w-max text-left font-medium text-gray-900" + c.capitalize ? " capitalize" : "",
220
- children: c.value
221
- }
222
- )
223
- ] }, c.label)) })
224
- ] }),
225
- r.usedOn && r.usedOn.length > 0 && /* @__PURE__ */ l("div", { className: "grid gap-3", children: [
226
- /* @__PURE__ */ e(q, { children: "Used On" }),
227
- /* @__PURE__ */ e("div", { className: "grid grid-cols-1 gap-2 text-sm border rounded-md p-2", children: r.usedOn.map((c, h) => /* @__PURE__ */ l("div", { className: "flex items-center gap-2", children: [
228
- /* @__PURE__ */ e("div", { className: "w-max text-left font-medium text-gray-900", children: c.name }),
229
- /* @__PURE__ */ l("div", { className: "text-gray-500", children: [
230
- "(",
231
- c.slug,
232
- ")"
233
- ] })
234
- ] }, h)) })
235
- ] }),
236
- /* @__PURE__ */ l("div", { className: "grid gap-3 border rounded-md pt-2 bg-gray-100 relative", children: [
237
- /* @__PURE__ */ e(q, { className: "w-full text-center", children: "Description" }),
238
- /* @__PURE__ */ e(
239
- Se,
240
- {
241
- id: "description",
242
- value: g,
243
- placeholder: "Enter a description for the asset",
244
- onChange: (c) => u(c.target.value),
245
- rows: 3,
246
- disabled: o,
247
- className: "hover:border-black/40 bg-white"
248
- }
249
- ),
250
- /* @__PURE__ */ e("div", { className: "flex justify-end items-start absolute top-1.5 right-2", children: /* @__PURE__ */ e(
251
- "button",
252
- {
253
- type: "button",
254
- onClick: () => i(g),
255
- disabled: o || !ee(g, r),
256
- className: `py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${o || !ee(g, r) ? "opacity-50 cursor-not-allowed" : ""}`,
257
- children: o ? /* @__PURE__ */ l(z, { children: [
258
- /* @__PURE__ */ e(F, { className: "h-4 w-4 mr-2 animate-spin" }),
259
- "Saving..."
260
- ] }) : "Save"
261
- }
262
- ) })
263
- ] })
264
- ] })
265
- ] })
266
- ] });
267
- }, tt = te.lazy(() => import("./image-editor-CzFST20j.js"));
268
- function lt(n) {
269
- const a = isNaN(n) ? 0 : typeof n == "number" ? n : parseInt(n);
270
- return a ? a < 1024 ? `${a.toFixed(2)} B` : a < 1024 * 1024 ? `${(a / 1024).toFixed(2)} KB` : `${(a / (1024 * 1024)).toFixed(2)} MB` : "0 B";
271
- }
272
- const it = ({
273
- isUpdatingAsset: n,
274
- allowedTypes: a,
275
- maxFileSize: s,
276
- uploadAsset: i,
277
- isUploadingAsset: o
278
- }) => {
279
- const r = n || o, x = T(
280
- async (p) => new Promise((A, S) => {
281
- const c = p[0], h = new FileReader();
282
- h.readAsDataURL(c), h.onload = async () => {
283
- const j = await i({
284
- file: h.result,
285
- folderId: void 0,
286
- name: c.name
287
- });
288
- A(j);
289
- }, h.onerror = (j) => S(j);
290
- }),
291
- [i]
292
- ), { getRootProps: N, getInputProps: g, isDragActive: u } = Ve({
293
- onDrop: x,
294
- accept: {
295
- "image/*": a.includes("image") ? [] : []
296
- },
297
- maxSize: s * 1024 * 1024,
298
- disabled: n || o
299
- });
300
- return /* @__PURE__ */ e(
301
- "div",
302
- {
303
- className: `flex flex-col items-center justify-center w-full border-2 hover:border-black/50 border-dashed p-0 rounded-lg border-slate-300 py-2 h-[60px] ${r ? "opacity-90 bg-gray-100 pointer-events-none" : "hover:border-black/50 hover:bg-gray-100"}`,
304
- children: /* @__PURE__ */ l(
305
- "div",
306
- {
307
- ...N(),
308
- className: le(
309
- "rounded-lg text-center cursor-pointer w-full h-max flex flex-col items-center justify-center",
310
- u ? "border-primary bg-primary/5" : "border-muted-foreground/20"
311
- ),
312
- children: [
313
- /* @__PURE__ */ e("input", { ...g() }),
314
- r ? /* @__PURE__ */ e("div", { className: "flex flex-col items-center", children: /* @__PURE__ */ l("div", { className: "leading-tight flex items-center gap-2", children: [
315
- /* @__PURE__ */ e(
316
- "div",
317
- {
318
- className: "flex items-center justify-center rounded-full bg-indigo-100 p-2",
319
- children: /* @__PURE__ */ e(F, { className: "h-4 w-4 text-indigo-500 animate-spin" })
320
- }
321
- ),
322
- /* @__PURE__ */ l("div", { className: "text-left", children: [
323
- /* @__PURE__ */ e("div", { className: "font-medium", children: n ? "Updating file..." : "Uploading file..." }),
324
- /* @__PURE__ */ l("div", { className: "text-xs text-muted-foreground font-light", children: [
325
- "Please wait while we ",
326
- n ? "update" : "upload",
327
- " ",
328
- "your file..."
329
- ] })
330
- ] })
331
- ] }) }) : /* @__PURE__ */ e("div", { className: "flex flex-col items-center", children: /* @__PURE__ */ l("div", { className: "leading-tight flex items-center gap-2", children: [
332
- /* @__PURE__ */ e(
333
- "div",
334
- {
335
- className: "flex items-center justify-center rounded-full bg-indigo-100 p-2 border border-indigo-500",
336
- children: /* @__PURE__ */ e(Re, { className: "h-4 w-4 text-indigo-500" })
337
- }
338
- ),
339
- /* @__PURE__ */ l("div", { className: "text-left", children: [
340
- /* @__PURE__ */ l("div", { className: "font-medium", children: [
341
- "Drop your file here or",
342
- " ",
343
- /* @__PURE__ */ e("span", { className: "text-indigo-500 cursor-pointer hover:underline", children: "browse" })
344
- ] }),
345
- /* @__PURE__ */ l("div", { className: "text-xs text-muted-foreground font-light", children: [
346
- /* @__PURE__ */ l("span", { className: "", children: [
347
- "Accepted file types:",
348
- " ",
349
- /* @__PURE__ */ e("span", { className: "capitalize text-indigo-400", children: a.join(", ") }),
350
- " & "
351
- ] }),
352
- /* @__PURE__ */ l("span", { children: [
353
- "Max file size:",
354
- " ",
355
- /* @__PURE__ */ l("span", { className: "capitalize text-indigo-400", children: [
356
- s,
357
- " MB"
358
- ] })
359
- ] })
360
- ] })
361
- ] })
362
- ] }) })
363
- ]
364
- }
365
- )
366
- }
367
- );
368
- };
369
- function ft({
370
- close: n,
371
- onSelect: a,
372
- mode: s = "image",
373
- assetId: i
374
- }) {
375
- const x = be(() => [s], [s]), [N, g] = f(null), [u, p] = f(null), [A, S] = f(null), [c, h] = f({ show: !1, file: "" }), [j, G] = f(!1), [ae, L] = f(
376
- i ? "details" : "grid"
377
- ), [M, re] = f(""), [B, ne] = f(""), [y, R] = f(1), [V] = f(30), [C, W] = f([]);
378
- Z(() => {
379
- i && (g(i), L("details"));
380
- }, [i]), Z(() => {
381
- const t = setTimeout(() => {
382
- re(B), R(1);
383
- }, 300);
384
- return () => clearTimeout(t);
385
- }, [B]);
386
- const { data: k, isLoading: Y } = Xe({
387
- search: M.toLowerCase().trim(),
388
- page: y,
389
- limit: V
390
- }), E = (k == null ? void 0 : k.assets) || [], se = (k == null ? void 0 : k.total) || 0, w = Math.ceil(se / V), O = y < w, _ = y > 1, ce = (E == null ? void 0 : E.length) > 0, { mutate: de } = Ye(), { mutate: H, isPending: oe } = We(), { mutate: X, isPending: ue } = He(), D = T(
391
- (t) => {
392
- t >= 1 && t <= w && R(t);
393
- },
394
- [w]
395
- ), me = T(() => {
396
- O && D(y + 1);
397
- }, [y, O, D]), he = T(() => {
398
- _ && D(y - 1);
399
- }, [y, _, D]), fe = (t) => {
400
- ne(t.target.value);
401
- }, ge = T(
402
- (t) => {
403
- W((d) => ze(d, { id: t.id }) ? [] : [t]);
404
- },
405
- [!1]
406
- ), pe = T(() => {
407
- W([]);
408
- }, []), ve = () => {
409
- C.length !== 0 && (a(
410
- Ie(Ue(C), [
411
- "id",
412
- "url",
413
- "width",
414
- "height",
415
- "description"
416
- ])
417
- ), n());
418
- }, xe = async (t) => {
419
- p(t);
420
- }, Ne = async () => {
421
- u && (S(u == null ? void 0 : u.id), await de(u.id, {
422
- onSuccess: () => {
423
- S(null), p(null);
424
- },
425
- onError: () => {
426
- S(null);
427
- }
428
- }), p(null));
429
- }, ye = (t) => {
430
- g(t.id), L("details");
431
- }, we = async (t, d) => {
432
- try {
433
- d ? (await H({
434
- file: t,
435
- folderId: void 0,
436
- name: c.name || ""
437
- }), h({ show: !1, file: "" })) : (await X({
438
- id: c.id || "",
439
- file: t
440
- }), h({ show: !1, file: "" }));
441
- } catch (b) {
442
- console.error("Error saving edited image:", b);
443
- }
444
- };
445
- return /* @__PURE__ */ l(z, { children: [
446
- /* @__PURE__ */ l("div", { className: "max-w-[1232px] max-h-[1232px] w-[80vw] h-[80vh] space-y-4 flex flex-col", children: [
447
- /* @__PURE__ */ e("h1", { className: "text-lg font-medium", children: "Digital Asset Manager" }),
448
- ae === "grid" ? /* @__PURE__ */ l(z, { children: [
449
- /* @__PURE__ */ e(
450
- it,
451
- {
452
- maxFileSize: 10,
453
- allowedTypes: x,
454
- uploadAsset: H,
455
- isUpdatingAsset: ue,
456
- isUploadingAsset: oe
457
- }
458
- ),
459
- /* @__PURE__ */ l("div", { className: "border p-2 rounded-lg flex-1 flex flex-col gap-y-3 overflow-hidden relative", children: [
460
- /* @__PURE__ */ l("div", { className: "flex items-center justify-between gap-3", children: [
461
- /* @__PURE__ */ l("div", { className: "relative w-1/2 ", children: [
462
- /* @__PURE__ */ e(
463
- Le,
464
- {
465
- strokeWidth: 3,
466
- className: `absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length > 0 ? "text-indigo-800" : ""}`
467
- }
468
- ),
469
- /* @__PURE__ */ e(
470
- Ce,
471
- {
472
- placeholder: "Search assets...",
473
- onChange: fe,
474
- value: B,
475
- className: "pl-8 hover:shadow-lg"
476
- }
477
- )
478
- ] }),
479
- C.length > 0 ? /* @__PURE__ */ e("div", { className: "flex justify-between items-center", children: /* @__PURE__ */ l("div", { className: "flex items-center gap-2", children: [
480
- C.length > 0 && /* @__PURE__ */ e(z, { children: /* @__PURE__ */ e(
481
- m,
482
- {
483
- variant: "outline",
484
- size: "sm",
485
- onClick: () => pe(),
486
- title: "Clear selection",
487
- children: "Clear"
488
- }
489
- ) }),
490
- /* @__PURE__ */ e(
491
- m,
492
- {
493
- size: "sm",
494
- onClick: ve,
495
- disabled: C.length === 0,
496
- children: "Select Asset"
497
- }
498
- )
499
- ] }) }) : null
500
- ] }),
501
- /* @__PURE__ */ e("div", { className: "flex-1 overflow-y-auto", children: Y ? /* @__PURE__ */ l("div", { className: "columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5", children: [
502
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
503
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
504
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
505
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
506
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
507
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
508
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
509
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
510
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
511
- /* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" })
512
- ] }) : !Y && !ce ? /* @__PURE__ */ l("div", { className: "flex flex-col items-center justify-center h-full border rounded-lg", children: [
513
- /* @__PURE__ */ e("div", { className: "text-muted-foreground", children: /* @__PURE__ */ e(Me, { className: "h-9 w-9 text-indigo-500" }) }),
514
- /* @__PURE__ */ e("div", { className: "text-muted-foreground text-lg", children: "No assets found" }),
515
- /* @__PURE__ */ e("div", { className: "text-muted-foreground text-sm", children: M.length > 0 ? "No assets found for your search: " + M : "Start uploading assets to get started" }),
516
- /* @__PURE__ */ e("br", {})
517
- ] }) : /* @__PURE__ */ e("div", { className: "flex flex-wrap gap-3 p-1", children: E == null ? void 0 : E.map((t) => /* @__PURE__ */ l(
518
- "div",
519
- {
520
- className: le(
521
- "relative cursor-pointer overflow-hidden transition-all rounded-lg border-2 group max-w-[180px] max-h-[180px] flex flex-col justify-between",
522
- C.some((d) => d.id === t.id) ? "border-4 border-blue-500" : "hover:border-black/50",
523
- A && (u == null ? void 0 : u.id) === t.id ? "opacity-50 pointer-events-none" : "",
524
- A === t.id ? "opacity-50 pointer-events-none" : ""
525
- ),
526
- onClick: () => ge(t),
527
- children: [
528
- /* @__PURE__ */ l("div", { className: "aspect-square relative overflow-hidden", children: [
529
- A === t.id ? /* @__PURE__ */ e("div", { className: "absolute inset-0 flex items-center justify-center bg-black/50", children: /* @__PURE__ */ e(F, { className: "h-8 w-8 animate-spin text-white" }) }) : null,
530
- t.type === "image" ? /* @__PURE__ */ e(
531
- "img",
532
- {
533
- src: `${t.thumbnailUrl || "/placeholder.svg"}?v=${(t == null ? void 0 : t.updatedAt) || t.createdAt}`,
534
- alt: t.name,
535
- className: "object-contain w-full h-full min-h-[80px]"
536
- }
537
- ) : /* @__PURE__ */ l("div", { className: "flex items-center justify-center h-full", children: [
538
- /* @__PURE__ */ e(Oe, { className: "h-12 w-12 text-muted-foreground" }),
539
- t.thumbnailUrl && /* @__PURE__ */ e(
540
- "img",
541
- {
542
- src: `${t.thumbnailUrl || "/placeholder.svg"}?v=${(t == null ? void 0 : t.updatedAt) || t.createdAt}`,
543
- alt: t.name,
544
- className: "absolute inset-0 object-cover w-full h-full"
545
- }
546
- )
547
- ] })
548
- ] }),
549
- /* @__PURE__ */ l("div", { className: "py-1 px-2", children: [
550
- /* @__PURE__ */ e("div", { className: "text-xs truncate", title: t.name, children: t.name }),
551
- /* @__PURE__ */ l("div", { className: "text-[10px] font-light text-muted-foreground flex items-center justify-between", children: [
552
- /* @__PURE__ */ e("span", { children: lt((t == null ? void 0 : t.size) || 0) }),
553
- /* @__PURE__ */ l("span", { children: [
554
- "Used on",
555
- " ",
556
- /* @__PURE__ */ l("span", { className: "font-normal", children: [
557
- (t == null ? void 0 : t.usedOnCount) || 0,
558
- " "
559
- ] }),
560
- (t == null ? void 0 : t.usedOnCount) === 1 ? "page" : "pages"
561
- ] })
562
- ] })
563
- ] }),
564
- /* @__PURE__ */ l("div", { className: "absolute inset-0 bg-black/80 border-white border-4 rounded-lg opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2", children: [
565
- /* @__PURE__ */ e(
566
- m,
567
- {
568
- variant: "secondary",
569
- size: "icon",
570
- className: "h-8 w-8 rounded-full",
571
- onClick: (d) => {
572
- d.stopPropagation(), ye(t);
573
- },
574
- children: /* @__PURE__ */ e(_e, { className: "h-4 w-4" })
575
- }
576
- ),
577
- /* @__PURE__ */ e(
578
- m,
579
- {
580
- variant: "secondary",
581
- size: "icon",
582
- className: "h-8 w-8 rounded-full",
583
- onClick: (d) => {
584
- d.stopPropagation(), h({
585
- id: t.id,
586
- show: !0,
587
- file: t.url,
588
- name: t.name
589
- });
590
- },
591
- children: /* @__PURE__ */ e(Ke, { className: "h-4 w-4" })
592
- }
593
- ),
594
- /* @__PURE__ */ e(
595
- m,
596
- {
597
- variant: "destructive",
598
- size: "icon",
599
- className: "h-8 w-8 rounded-full",
600
- onClick: (d) => {
601
- d.stopPropagation(), xe(t);
602
- },
603
- children: /* @__PURE__ */ e(Qe, { className: "h-4 w-4" })
604
- }
605
- )
606
- ] }),
607
- C.some((d) => d.id === t.id) && /* @__PURE__ */ e("div", { className: "absolute top-2 right-2 border border-white h-max rounded-full bg-blue-500 p-1", children: /* @__PURE__ */ e(
608
- Ge,
609
- {
610
- className: "w-3 h-3 text-white",
611
- strokeWidth: 5
612
- }
613
- ) })
614
- ]
615
- },
616
- t.id
617
- )) }) }),
618
- w > 1 && /* @__PURE__ */ e("div", { className: "absolute bottom-0 left-0 right-0 bg-white border-t p-4", children: /* @__PURE__ */ l("div", { className: "flex items-center justify-center space-x-2", children: [
619
- /* @__PURE__ */ e(
620
- m,
621
- {
622
- variant: "outline",
623
- size: "sm",
624
- onClick: he,
625
- disabled: !_,
626
- children: "Previous"
627
- }
628
- ),
629
- Array.from({ length: Math.min(5, w) }, (t, d) => {
630
- const b = d + 1;
631
- return /* @__PURE__ */ e(
632
- m,
633
- {
634
- variant: y === b ? "default" : "outline",
635
- size: "sm",
636
- onClick: () => D(b),
637
- children: b
638
- },
639
- b
640
- );
641
- }),
642
- w > 5 && /* @__PURE__ */ l(z, { children: [
643
- /* @__PURE__ */ e("span", { className: "text-muted-foreground", children: "..." }),
644
- /* @__PURE__ */ e(
645
- m,
646
- {
647
- variant: y === w ? "default" : "outline",
648
- size: "sm",
649
- onClick: () => D(w),
650
- children: w
651
- }
652
- )
653
- ] }),
654
- /* @__PURE__ */ e(
655
- m,
656
- {
657
- variant: "outline",
658
- size: "sm",
659
- onClick: me,
660
- disabled: !O,
661
- children: "Next"
662
- }
663
- )
664
- ] }) })
665
- ] })
666
- ] }) : /* @__PURE__ */ e(
667
- et,
668
- {
669
- assetId: N || i || "",
670
- onBack: () => {
671
- L("grid"), g(null);
672
- },
673
- onEdit: (t) => {
674
- h({
675
- id: t.id,
676
- show: !0,
677
- file: t.url,
678
- name: t.name
679
- });
680
- },
681
- onSave: async (t) => {
682
- if (N) {
683
- G(!0);
684
- try {
685
- const d = E.find((b) => b.id === N);
686
- d && await X(Fe(d, { description: t }));
687
- } finally {
688
- G(!1);
689
- }
690
- }
691
- },
692
- isSaving: j
693
- }
694
- )
695
- ] }),
696
- c.show && /* @__PURE__ */ e(
697
- Ae,
698
- {
699
- fallback: /* @__PURE__ */ e("div", { className: "absolute inset-0 flex items-center justify-center", children: /* @__PURE__ */ e(F, { className: "h-8 w-8 animate-spin" }) }),
700
- children: /* @__PURE__ */ e(
701
- tt,
702
- {
703
- imageUrl: c.file,
704
- onSave: we,
705
- onClose: () => h({ show: !1, file: "" }),
706
- defaultSavedImageName: c.name,
707
- isEditing: !!c.id
708
- }
709
- )
710
- }
711
- ),
712
- u && /* @__PURE__ */ e(
713
- Ee,
714
- {
715
- open: !!u,
716
- onOpenChange: () => p(null),
717
- children: /* @__PURE__ */ l(ke, { children: [
718
- /* @__PURE__ */ l(De, { children: [
719
- /* @__PURE__ */ e(Te, { children: "Delete Asset" }),
720
- /* @__PURE__ */ l(Pe, { children: [
721
- 'Are you sure you want to delete "',
722
- u.name,
723
- '"? This action cannot be undone.'
724
- ] })
725
- ] }),
726
- /* @__PURE__ */ l(je, { className: "gap-2 sm:gap-0", children: [
727
- /* @__PURE__ */ e(m, { variant: "outline", onClick: () => p(null), children: "Cancel" }),
728
- /* @__PURE__ */ e(m, { variant: "destructive", onClick: Ne, children: "Delete" })
729
- ] })
730
- ] })
731
- }
732
- )
733
- ] });
734
- }
735
- export {
736
- ft as default
737
- };