@chaibuilder/pages 0.4.13 → 0.4.15

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,7 +1,7 @@
1
1
  var ps = Object.defineProperty;
2
2
  var xs = (e, t, n) => t in e ? ps(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var qe = (e, t, n) => xs(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { s as Vn, m as Gn, b as R, d as rr, e as U, a as m, f as W, h as oe, S as B, c as D, i as we, u as $e, j as V, k as A, l as Ne, o as ut, P as zo, n as j, D as ws, t as q, p as Ft, q as ln, r as k, v as F, w as $s, x as Rt, y as Cs, z as Ss, A as wn, F as ks, B as Es, C as Ds, E as Kt, G as Ms, H as As, I as Fs, J as or, K as Kr, L as Ts, M as qt, $ as Ro, N as Br, O as Is, Q as Ps, R as zn, T as Ls, U as Os, V as qs } from "./index-HGE7qAuk.js";
4
+ import { s as Vn, m as Gn, b as R, d as rr, e as U, a as m, f as W, h as oe, S as B, c as D, i as we, u as $e, j as V, k as A, l as Ne, o as ut, P as zo, n as j, D as ws, t as q, p as Ft, q as ln, r as k, v as F, w as $s, x as Rt, y as Cs, z as Ss, A as wn, F as ks, B as Es, C as Ds, E as Kt, G as Ms, H as As, I as Fs, J as or, K as Kr, L as Ts, M as qt, $ as Ro, N as Br, O as Is, Q as Ps, R as zn, T as Ls, U as Os, V as qs } from "./index-BX7rKwIJ.js";
5
5
  var _s = (e) => e != null, zs = (e) => e.filter(_s);
6
6
  function Rs(e) {
7
7
  return (...t) => {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR-CeGZGu8R.cjs"),t=require("./index-GG8u_jcv.cjs");var s=c=>{const[r,o]=e.createLocalStorage({prefix:"TanstackQueryDevtools"}),l=t.getPreferredColorScheme(),a=t.createMemo(()=>{const n=r.theme_preference||e.THEME_PREFERENCE;return n!=="system"?n:l()});return t.createComponent(e.QueryDevtoolsContext.Provider,{value:c,get children(){return t.createComponent(e.PiPProvider,{localStore:r,setLocalStore:o,get children(){return t.createComponent(e.ThemeContext.Provider,{value:a,get children(){return t.createComponent(e.Devtools,{localStore:r,setLocalStore:o})}})}})}})},u=s;exports.default=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR-DpJr1_dV.cjs"),t=require("./index-Znkr81OE.cjs");var s=c=>{const[r,o]=e.createLocalStorage({prefix:"TanstackQueryDevtools"}),l=t.getPreferredColorScheme(),a=t.createMemo(()=>{const n=r.theme_preference||e.THEME_PREFERENCE;return n!=="system"?n:l()});return t.createComponent(e.QueryDevtoolsContext.Provider,{value:c,get children(){return t.createComponent(e.PiPProvider,{localStore:r,setLocalStore:o,get children(){return t.createComponent(e.ThemeContext.Provider,{value:a,get children(){return t.createComponent(e.Devtools,{localStore:r,setLocalStore:o})}})}})}})},u=s;exports.default=u;
@@ -1,5 +1,5 @@
1
- import { c, T as l, P as m, a as u, D as v, Q as i } from "./B4MFY5CR-BAaAGAXs.js";
2
- import { g as d, c as f, a as e } from "./index-HGE7qAuk.js";
1
+ import { c, T as l, P as m, a as u, D as v, Q as i } from "./B4MFY5CR-ogPfosvH.js";
2
+ import { g as d, c as f, a as e } from "./index-BX7rKwIJ.js";
3
3
  var p = (a) => {
4
4
  const [r, t] = c({
5
5
  prefix: "TanstackQueryDevtools"
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR-CeGZGu8R.cjs"),t=require("./index-GG8u_jcv.cjs");var u=o=>{const[r,n]=e.createLocalStorage({prefix:"TanstackQueryDevtools"}),c=t.getPreferredColorScheme(),a=t.createMemo(()=>{const l=r.theme_preference||e.THEME_PREFERENCE;return l!=="system"?l:c()});return t.createComponent(e.QueryDevtoolsContext.Provider,{value:o,get children(){return t.createComponent(e.PiPProvider,{disabled:!0,localStore:r,setLocalStore:n,get children(){return t.createComponent(e.ThemeContext.Provider,{value:a,get children(){return t.createComponent(e.ParentPanel,{get children(){return t.createComponent(e.ContentView,{localStore:r,setLocalStore:n,get onClose(){return o.onClose},showPanelViewOnly:!0})}})}})}})}})},i=u;exports.default=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR-DpJr1_dV.cjs"),t=require("./index-Znkr81OE.cjs");var u=o=>{const[r,n]=e.createLocalStorage({prefix:"TanstackQueryDevtools"}),c=t.getPreferredColorScheme(),a=t.createMemo(()=>{const l=r.theme_preference||e.THEME_PREFERENCE;return l!=="system"?l:c()});return t.createComponent(e.QueryDevtoolsContext.Provider,{value:o,get children(){return t.createComponent(e.PiPProvider,{disabled:!0,localStore:r,setLocalStore:n,get children(){return t.createComponent(e.ThemeContext.Provider,{value:a,get children(){return t.createComponent(e.ParentPanel,{get children(){return t.createComponent(e.ContentView,{localStore:r,setLocalStore:n,get onClose(){return o.onClose},showPanelViewOnly:!0})}})}})}})}})},i=u;exports.default=i;
@@ -1,5 +1,5 @@
1
- import { c as s, T as c, P as u, a as i, b as m, C as P, Q as d } from "./B4MFY5CR-BAaAGAXs.js";
2
- import { g as v, c as C, a as e } from "./index-HGE7qAuk.js";
1
+ import { c as s, T as c, P as u, a as i, b as m, C as P, Q as d } from "./B4MFY5CR-ogPfosvH.js";
2
+ import { g as v, c as C, a as e } from "./index-BX7rKwIJ.js";
3
3
  var h = (t) => {
4
4
  const [r, o] = s({
5
5
  prefix: "TanstackQueryDevtools"
@@ -7,7 +7,7 @@ import { Search as Qe, Film as Re, ImageIcon as Ke, Edit as Ge, Trash2 as Oe, Lo
7
7
  import { useDropzone as Ve } from "react-dropzone";
8
8
  import { useQueryClient as L, useMutation as q, useQuery as $e } from "@tanstack/react-query";
9
9
  import { toast as w } from "sonner";
10
- import { W as P, X as U, Y as f, Z as k } from "./index-HGE7qAuk.js";
10
+ import { W as P, X as U, Y as f, Z as k } from "./index-BX7rKwIJ.js";
11
11
  const He = () => {
12
12
  const l = P(), n = L(), r = U();
13
13
  return q({
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),L=require("@chaibuilder/sdk"),t=require("@chaibuilder/sdk/ui"),A=require("lodash-es"),x=require("lucide-react"),he=require("react-dropzone"),p=require("@tanstack/react-query"),N=require("sonner"),n=require("./index-GG8u_jcv.cjs"),xe=()=>{const i=n.useAssetsApiUrl(),r=p.useQueryClient(),o=n.useFetch();return p.useMutation({mutationFn:async({file:c,folderId:f,name:h})=>o(i,{action:n.ACTIONS.UPLOAD_ASSET,data:{file:c,folderId:f,name:h}}),onSuccess:()=>{r.invalidateQueries({queryKey:[n.QUERY_KEY_BASE,n.ACTIONS.GET_ASSETS]}),N.toast.success("Asset uploaded successfully")},onError:()=>{N.toast.error("Failed to upload asset")}})},ge=()=>{const i=n.useAssetsApiUrl(),r=p.useQueryClient(),o=n.useFetch();return p.useMutation({mutationFn:async c=>o(i,{action:n.ACTIONS.DELETE_ASSET,data:{id:c}}),onSuccess:()=>{r.invalidateQueries({queryKey:[n.QUERY_KEY_BASE,n.ACTIONS.GET_ASSETS]}),N.toast.success("Asset deleted successfully")},onError:()=>{N.toast.error("Failed to delete asset")}})},pe=()=>{const i=n.useAssetsApiUrl(),r=p.useQueryClient(),o=n.useFetch();return p.useMutation({mutationFn:async c=>o(i,{action:n.ACTIONS.UPDATE_ASSET,data:c}),onSuccess:()=>{r.invalidateQueries({queryKey:[n.QUERY_KEY_BASE,n.ACTIONS.GET_ASSETS]}),N.toast.success("Asset updated successfully")},onError:()=>{N.toast.error("Failed to update asset")}})},fe=(i={})=>{const r=n.useAssetsApiUrl(),o=n.useFetch(),{search:c,page:f=1,limit:h=30}=i;return p.useQuery({queryKey:[n.QUERY_KEY_BASE,n.ACTIONS.GET_ASSETS,c,f,h],queryFn:async()=>{const S=await o(r,{action:n.ACTIONS.GET_ASSETS,data:{search:c,page:f,limit:h}});return S.page=f,S.limit=h,S},retry:1})},je=a.lazy(()=>Promise.resolve().then(()=>require("./asset-metadata-editor-IRTgc3or.cjs"))),ve=a.lazy(()=>Promise.resolve().then(()=>require("./image-editor-DHmv5L8S.cjs")));function ye({close:i,onSelect:r,mode:o="image"}){const h=a.useMemo(()=>[o],[o]),[S,w]=a.useState("browse"),[k,B]=a.useState(null),[b,C]=a.useState(null),[j,D]=a.useState({show:!1,file:""}),[K,Y]=a.useState(""),[q,G]=a.useState(""),[d,z]=a.useState(1),[M]=a.useState(30),[g,_]=a.useState([]);a.useEffect(()=>{const s=setTimeout(()=>{Y(q),z(1)},300);return()=>clearTimeout(s)},[q]);const{data:v,isLoading:Q}=fe({search:K.toLowerCase().trim(),page:d,limit:M}),E=(v==null?void 0:v.assets)||[],V=(v==null?void 0:v.total)||0,u=Math.ceil(V/M),P=d<u,U=d>1,{mutate:O,isPending:$}=pe(),{mutate:F,isPending:H}=xe(),{mutate:J}=ge(),W=a.useRef(null),y=a.useCallback(s=>{s>=1&&s<=u&&z(s)},[u]),X=a.useCallback(()=>{P&&y(d+1)},[d,P,y]),Z=a.useCallback(()=>{U&&y(d-1)},[d,U,y]),ee=s=>{G(s.target.value)},se=a.useCallback(s=>{_(l=>A.find(l,{id:s.id})?[]:[s])},[!1]),te=a.useCallback(()=>{_([])},[]),ae=a.useCallback(async s=>new Promise((l,m)=>{const R=s[0],T=new FileReader;T.readAsDataURL(R),T.onload=async()=>{const I=await F({file:T.result,folderId:void 0,name:R.name},{onSuccess:()=>{w("browse")}});l(I)},T.onerror=I=>m(I)}),[F]),{getRootProps:le,getInputProps:ne,isDragActive:ie}=he.useDropzone({onDrop:ae,accept:{"image/*":h.includes("image")?[]:[]},maxSize:10*1024*1024}),re=()=>{g.length!==0&&(r(A.pick(A.first(g),["id","url","width","height","description"])),i())},oe=async s=>{C(s)},ce=async()=>{b&&(await J(b.id),C(null))},de=s=>{B(s)},ue=async(s,l)=>{await O(A.merge(s,A.pick(l,["id","description"]))),i()},me=async(s,l)=>{try{l?await F({file:s,folderId:void 0,name:j.name||""}):await O({id:j.id||"",file:s}),D({show:!1,file:""}),w("browse")}catch(m){console.error("Error saving edited image:",m)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"min-w-[700px] min-h-[600px] w-[900px] max-w-[900px]",children:[e.jsx("h1",{className:"text-lg font-medium pb-4",children:"Digital Asset Manager"}),e.jsxs(t.Tabs,{value:S,onValueChange:s=>w(s),className:"flex-1 flex flex-col h-full",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs(t.TabsList,{children:[e.jsx(t.TabsTrigger,{value:"browse",children:"Browse Assets"}),e.jsx(t.TabsTrigger,{value:"upload",children:"Upload"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[g.length>0&&e.jsx(e.Fragment,{children:e.jsx(t.Button,{variant:"outline",size:"sm",onClick:()=>te(),title:"Clear selection",children:"Clear"})}),e.jsx(t.Button,{size:"sm",onClick:re,disabled:g.length===0,children:"Select Asset"})]})]}),e.jsxs(t.TabsContent,{value:"browse",className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsxs("div",{className:"relative w-full",children:[e.jsx(x.Search,{className:"absolute left-2 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(t.Input,{placeholder:"Search assets...",onChange:ee,className:"pl-8"})]})}),Q&&E.length===0?e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[550px] p-1",children:[e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"})]}):E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center text-center p-12 h-[380px]",children:[e.jsxs("div",{className:"text-muted-foreground mb-2",children:[e.jsx("h3",{className:"text-gray-800 font-medium",children:"No assets to display"}),e.jsx("p",{className:"text-sm",children:"You haven't uploaded any assets yet. Start by uploading your first asset."})]}),e.jsx("div",{className:"flex gap-2 pt-4",children:e.jsx(t.Button,{size:"lg",onClick:()=>w("upload"),children:"Upload Assets"})})]}):e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{ref:W,className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[480px] p-1",children:[E.map(s=>e.jsx(t.Card,{className:L.mergeClasses("cursor-pointer overflow-hidden transition-all",g.some(l=>l.id===s.id)?"ring-2 ring-primary":"hover:ring-2 hover:ring-primary/20"),onClick:()=>se(s),children:e.jsxs(t.CardContent,{className:"p-0 relative group",children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden bg-muted",children:[s.type==="image"?e.jsx("img",{src:s.thumbnailUrl||"/placeholder.svg",alt:s.name,className:"object-cover w-full h-full min-h-[100px]"}):e.jsxs("div",{className:"flex items-center justify-center h-full",children:[e.jsx(x.Film,{className:"h-12 w-12 text-muted-foreground"}),s.thumbnailUrl&&e.jsx("img",{src:s.thumbnailUrl||"/placeholder.svg",alt:s.name,className:"absolute inset-0 object-cover w-full h-full"})]}),e.jsxs("div",{className:"absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2",children:[e.jsx(t.Button,{variant:"secondary",size:"icon",className:"h-8 w-8",onClick:l=>{l.stopPropagation(),de(s)},children:e.jsx(x.ImageIcon,{className:"h-4 w-4"})}),e.jsx(t.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 hidden",onClick:l=>{l.stopPropagation(),D({id:s.id,show:!0,file:s.url,name:s.name})},children:e.jsx(x.Edit,{className:"h-4 w-4"})}),e.jsx(t.Button,{variant:"destructive",size:"icon",className:"h-8 w-8",onClick:l=>{l.stopPropagation(),oe(s)},children:e.jsx(x.Trash2,{className:"h-4 w-4"})})]}),g.some(l=>l.id===s.id)&&e.jsx("div",{className:"absolute top-2 left-2",children:e.jsx("input",{type:"checkbox",checked:g.some(l=>l.id===s.id),readOnly:!0,className:"rounded-full"})})]}),e.jsxs("div",{className:"p-2",children:[e.jsx("div",{className:"text-sm font-medium truncate",title:s.name,children:s.name}),e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center justify-between",children:[e.jsx("span",{children:Ne((s==null?void 0:s.size)||0)}),e.jsx("span",{children:Se(s.createdAt)})]})]})]})},s.id)),Q&&E.length>0&&e.jsx("div",{className:"col-span-full flex justify-center py-4",children:e.jsx(x.Loader2,{className:"h-6 w-6 animate-spin text-muted-foreground"})})]}),u>1&&e.jsx("div",{className:"mt-4 flex justify-center border-t pt-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Button,{variant:"outline",size:"sm",onClick:Z,disabled:!U,children:"Previous"}),Array.from({length:Math.min(5,u)},(s,l)=>{const m=l+1;return e.jsx(t.Button,{variant:d===m?"default":"outline",size:"sm",onClick:()=>y(m),children:m},m)}),u>5&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground",children:"..."}),e.jsx(t.Button,{variant:d===u?"default":"outline",size:"sm",onClick:()=>y(u),children:u})]}),e.jsx(t.Button,{variant:"outline",size:"sm",onClick:X,disabled:!P,children:"Next"})]})})]})]}),e.jsx(t.TabsContent,{value:"upload",className:"flex-1 ",children:e.jsxs("div",{...le(),className:L.mergeClasses("border-2 border-dashed rounded-lg h-[380px] flex flex-col items-center justify-center text-center cursor-pointer hover:bg-gray-50",ie?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...ne()}),$||H?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(x.Loader2,{className:"h-12 w-12 text-primary animate-spin mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-1",children:"Uploading files..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait while your files are being processed."})]}):e.jsxs(e.Fragment,{children:[e.jsx(x.Upload,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-1",children:"Drag & drop files here"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"or click to browse your files"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("p",{children:["Accepted file types: ",h.join(", ")]}),e.jsxs("p",{children:["Maximum file size: ",10,"MB"]})]})]})]})})]})]}),k&&e.jsx(a.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(je,{asset:k,onSave:s=>ue(k,s),onCancel:()=>{B(null)}})}),j.show&&e.jsx(a.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(ve,{imageUrl:j.file,onSave:me,onClose:()=>D({show:!1,file:""}),defaultSavedImageName:j.name,isEditing:!!j.id})}),b&&e.jsx(t.Dialog,{open:!!b,onOpenChange:()=>C(null),children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Delete Asset"}),e.jsxs(t.DialogDescription,{children:['Are you sure you want to delete "',b.name,'"? This action cannot be undone.']})]}),e.jsxs(t.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(t.Button,{variant:"outline",onClick:()=>C(null),children:"Cancel"}),e.jsx(t.Button,{variant:"destructive",onClick:ce,children:"Delete"})]})]})})]})}function Ne(i){return i<1024?`${i.toFixed(2)} B`:i<1024*1024?`${(i/1024).toFixed(2)} KB`:`${(i/(1024*1024)).toFixed(2)} MB`}function Se(i){const r=new Date(i);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(r)}exports.default=ye;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("react"),L=require("@chaibuilder/sdk"),t=require("@chaibuilder/sdk/ui"),A=require("lodash-es"),x=require("lucide-react"),he=require("react-dropzone"),p=require("@tanstack/react-query"),N=require("sonner"),n=require("./index-Znkr81OE.cjs"),xe=()=>{const i=n.useAssetsApiUrl(),r=p.useQueryClient(),o=n.useFetch();return p.useMutation({mutationFn:async({file:c,folderId:f,name:h})=>o(i,{action:n.ACTIONS.UPLOAD_ASSET,data:{file:c,folderId:f,name:h}}),onSuccess:()=>{r.invalidateQueries({queryKey:[n.QUERY_KEY_BASE,n.ACTIONS.GET_ASSETS]}),N.toast.success("Asset uploaded successfully")},onError:()=>{N.toast.error("Failed to upload asset")}})},ge=()=>{const i=n.useAssetsApiUrl(),r=p.useQueryClient(),o=n.useFetch();return p.useMutation({mutationFn:async c=>o(i,{action:n.ACTIONS.DELETE_ASSET,data:{id:c}}),onSuccess:()=>{r.invalidateQueries({queryKey:[n.QUERY_KEY_BASE,n.ACTIONS.GET_ASSETS]}),N.toast.success("Asset deleted successfully")},onError:()=>{N.toast.error("Failed to delete asset")}})},pe=()=>{const i=n.useAssetsApiUrl(),r=p.useQueryClient(),o=n.useFetch();return p.useMutation({mutationFn:async c=>o(i,{action:n.ACTIONS.UPDATE_ASSET,data:c}),onSuccess:()=>{r.invalidateQueries({queryKey:[n.QUERY_KEY_BASE,n.ACTIONS.GET_ASSETS]}),N.toast.success("Asset updated successfully")},onError:()=>{N.toast.error("Failed to update asset")}})},fe=(i={})=>{const r=n.useAssetsApiUrl(),o=n.useFetch(),{search:c,page:f=1,limit:h=30}=i;return p.useQuery({queryKey:[n.QUERY_KEY_BASE,n.ACTIONS.GET_ASSETS,c,f,h],queryFn:async()=>{const S=await o(r,{action:n.ACTIONS.GET_ASSETS,data:{search:c,page:f,limit:h}});return S.page=f,S.limit=h,S},retry:1})},je=a.lazy(()=>Promise.resolve().then(()=>require("./asset-metadata-editor-IRTgc3or.cjs"))),ve=a.lazy(()=>Promise.resolve().then(()=>require("./image-editor-DHmv5L8S.cjs")));function ye({close:i,onSelect:r,mode:o="image"}){const h=a.useMemo(()=>[o],[o]),[S,w]=a.useState("browse"),[k,B]=a.useState(null),[b,C]=a.useState(null),[j,D]=a.useState({show:!1,file:""}),[K,Y]=a.useState(""),[q,G]=a.useState(""),[d,z]=a.useState(1),[M]=a.useState(30),[g,_]=a.useState([]);a.useEffect(()=>{const s=setTimeout(()=>{Y(q),z(1)},300);return()=>clearTimeout(s)},[q]);const{data:v,isLoading:Q}=fe({search:K.toLowerCase().trim(),page:d,limit:M}),E=(v==null?void 0:v.assets)||[],V=(v==null?void 0:v.total)||0,u=Math.ceil(V/M),P=d<u,U=d>1,{mutate:O,isPending:$}=pe(),{mutate:F,isPending:H}=xe(),{mutate:J}=ge(),W=a.useRef(null),y=a.useCallback(s=>{s>=1&&s<=u&&z(s)},[u]),X=a.useCallback(()=>{P&&y(d+1)},[d,P,y]),Z=a.useCallback(()=>{U&&y(d-1)},[d,U,y]),ee=s=>{G(s.target.value)},se=a.useCallback(s=>{_(l=>A.find(l,{id:s.id})?[]:[s])},[!1]),te=a.useCallback(()=>{_([])},[]),ae=a.useCallback(async s=>new Promise((l,m)=>{const R=s[0],T=new FileReader;T.readAsDataURL(R),T.onload=async()=>{const I=await F({file:T.result,folderId:void 0,name:R.name},{onSuccess:()=>{w("browse")}});l(I)},T.onerror=I=>m(I)}),[F]),{getRootProps:le,getInputProps:ne,isDragActive:ie}=he.useDropzone({onDrop:ae,accept:{"image/*":h.includes("image")?[]:[]},maxSize:10*1024*1024}),re=()=>{g.length!==0&&(r(A.pick(A.first(g),["id","url","width","height","description"])),i())},oe=async s=>{C(s)},ce=async()=>{b&&(await J(b.id),C(null))},de=s=>{B(s)},ue=async(s,l)=>{await O(A.merge(s,A.pick(l,["id","description"]))),i()},me=async(s,l)=>{try{l?await F({file:s,folderId:void 0,name:j.name||""}):await O({id:j.id||"",file:s}),D({show:!1,file:""}),w("browse")}catch(m){console.error("Error saving edited image:",m)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"min-w-[700px] min-h-[600px] w-[900px] max-w-[900px]",children:[e.jsx("h1",{className:"text-lg font-medium pb-4",children:"Digital Asset Manager"}),e.jsxs(t.Tabs,{value:S,onValueChange:s=>w(s),className:"flex-1 flex flex-col h-full",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs(t.TabsList,{children:[e.jsx(t.TabsTrigger,{value:"browse",children:"Browse Assets"}),e.jsx(t.TabsTrigger,{value:"upload",children:"Upload"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[g.length>0&&e.jsx(e.Fragment,{children:e.jsx(t.Button,{variant:"outline",size:"sm",onClick:()=>te(),title:"Clear selection",children:"Clear"})}),e.jsx(t.Button,{size:"sm",onClick:re,disabled:g.length===0,children:"Select Asset"})]})]}),e.jsxs(t.TabsContent,{value:"browse",className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsxs("div",{className:"relative w-full",children:[e.jsx(x.Search,{className:"absolute left-2 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(t.Input,{placeholder:"Search assets...",onChange:ee,className:"pl-8"})]})}),Q&&E.length===0?e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[550px] p-1",children:[e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"})]}):E.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center text-center p-12 h-[380px]",children:[e.jsxs("div",{className:"text-muted-foreground mb-2",children:[e.jsx("h3",{className:"text-gray-800 font-medium",children:"No assets to display"}),e.jsx("p",{className:"text-sm",children:"You haven't uploaded any assets yet. Start by uploading your first asset."})]}),e.jsx("div",{className:"flex gap-2 pt-4",children:e.jsx(t.Button,{size:"lg",onClick:()=>w("upload"),children:"Upload Assets"})})]}):e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{ref:W,className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[480px] p-1",children:[E.map(s=>e.jsx(t.Card,{className:L.mergeClasses("cursor-pointer overflow-hidden transition-all",g.some(l=>l.id===s.id)?"ring-2 ring-primary":"hover:ring-2 hover:ring-primary/20"),onClick:()=>se(s),children:e.jsxs(t.CardContent,{className:"p-0 relative group",children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden bg-muted",children:[s.type==="image"?e.jsx("img",{src:s.thumbnailUrl||"/placeholder.svg",alt:s.name,className:"object-cover w-full h-full min-h-[100px]"}):e.jsxs("div",{className:"flex items-center justify-center h-full",children:[e.jsx(x.Film,{className:"h-12 w-12 text-muted-foreground"}),s.thumbnailUrl&&e.jsx("img",{src:s.thumbnailUrl||"/placeholder.svg",alt:s.name,className:"absolute inset-0 object-cover w-full h-full"})]}),e.jsxs("div",{className:"absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2",children:[e.jsx(t.Button,{variant:"secondary",size:"icon",className:"h-8 w-8",onClick:l=>{l.stopPropagation(),de(s)},children:e.jsx(x.ImageIcon,{className:"h-4 w-4"})}),e.jsx(t.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 hidden",onClick:l=>{l.stopPropagation(),D({id:s.id,show:!0,file:s.url,name:s.name})},children:e.jsx(x.Edit,{className:"h-4 w-4"})}),e.jsx(t.Button,{variant:"destructive",size:"icon",className:"h-8 w-8",onClick:l=>{l.stopPropagation(),oe(s)},children:e.jsx(x.Trash2,{className:"h-4 w-4"})})]}),g.some(l=>l.id===s.id)&&e.jsx("div",{className:"absolute top-2 left-2",children:e.jsx("input",{type:"checkbox",checked:g.some(l=>l.id===s.id),readOnly:!0,className:"rounded-full"})})]}),e.jsxs("div",{className:"p-2",children:[e.jsx("div",{className:"text-sm font-medium truncate",title:s.name,children:s.name}),e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center justify-between",children:[e.jsx("span",{children:Ne((s==null?void 0:s.size)||0)}),e.jsx("span",{children:Se(s.createdAt)})]})]})]})},s.id)),Q&&E.length>0&&e.jsx("div",{className:"col-span-full flex justify-center py-4",children:e.jsx(x.Loader2,{className:"h-6 w-6 animate-spin text-muted-foreground"})})]}),u>1&&e.jsx("div",{className:"mt-4 flex justify-center border-t pt-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(t.Button,{variant:"outline",size:"sm",onClick:Z,disabled:!U,children:"Previous"}),Array.from({length:Math.min(5,u)},(s,l)=>{const m=l+1;return e.jsx(t.Button,{variant:d===m?"default":"outline",size:"sm",onClick:()=>y(m),children:m},m)}),u>5&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground",children:"..."}),e.jsx(t.Button,{variant:d===u?"default":"outline",size:"sm",onClick:()=>y(u),children:u})]}),e.jsx(t.Button,{variant:"outline",size:"sm",onClick:X,disabled:!P,children:"Next"})]})})]})]}),e.jsx(t.TabsContent,{value:"upload",className:"flex-1 ",children:e.jsxs("div",{...le(),className:L.mergeClasses("border-2 border-dashed rounded-lg h-[380px] flex flex-col items-center justify-center text-center cursor-pointer hover:bg-gray-50",ie?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...ne()}),$||H?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(x.Loader2,{className:"h-12 w-12 text-primary animate-spin mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-1",children:"Uploading files..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait while your files are being processed."})]}):e.jsxs(e.Fragment,{children:[e.jsx(x.Upload,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-1",children:"Drag & drop files here"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"or click to browse your files"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("p",{children:["Accepted file types: ",h.join(", ")]}),e.jsxs("p",{children:["Maximum file size: ",10,"MB"]})]})]})]})})]})]}),k&&e.jsx(a.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(je,{asset:k,onSave:s=>ue(k,s),onCancel:()=>{B(null)}})}),j.show&&e.jsx(a.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(ve,{imageUrl:j.file,onSave:me,onClose:()=>D({show:!1,file:""}),defaultSavedImageName:j.name,isEditing:!!j.id})}),b&&e.jsx(t.Dialog,{open:!!b,onOpenChange:()=>C(null),children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Delete Asset"}),e.jsxs(t.DialogDescription,{children:['Are you sure you want to delete "',b.name,'"? This action cannot be undone.']})]}),e.jsxs(t.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(t.Button,{variant:"outline",onClick:()=>C(null),children:"Cancel"}),e.jsx(t.Button,{variant:"destructive",onClick:ce,children:"Delete"})]})]})})]})}function Ne(i){return i<1024?`${i.toFixed(2)} B`:i<1024*1024?`${(i/1024).toFixed(2)} KB`:`${(i/(1024*1024)).toFixed(2)} MB`}function Se(i){const r=new Date(i);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(r)}exports.default=ye;