16 lines
41 KiB
JavaScript
16 lines
41 KiB
JavaScript
import"../chunks/DsnmJJEf.js";import{i as J,m as Ve,j as o,g as e,h as Z,p as Pe,f as xe,t as X,a as _,b as Ce,d as r,c as T,s as d,n as pt,r as t,e as Ue,l as Dt,u as kt,o as At,aA as lt,ak as It,k as Tt,$ as Ft}from"../chunks/krC2xWPP.js";import{d as Be,a as L,s as h,e as je}from"../chunks/CddAxf8c.js";import{p as xt,i as P}from"../chunks/DjsWWzyL.js";import{s as ae,h as St}from"../chunks/j_DJpx8B.js";import{i as j,c as be,b as Nt,a as zt}from"../chunks/Cu5ilWky.js";import{o as Ot}from"../chunks/DukJHxi2.js";import{e as Le,h as Lt,s as me,c as Rt,j as Ut,i as Ye,r as tt,t as ke,b as Pt}from"../chunks/Lvd_r9sp.js";import{b as _t}from"../chunks/ciapVzar.js";import{b as Ct}from"../chunks/CpuCZOqP.js";import{r as Xt,a as Wt,d as jt,c as Bt,b as ct,e as ut,f as rt,U as Kt,X as Gt,I as Vt}from"../chunks/DXEgXodZ.js";import{p as vt}from"../chunks/BzvfRedh.js";import{C as Ht}from"../chunks/CqW2kplp.js";import{c as Je}from"../chunks/BcwIk3O9.js";import{D as He}from"../chunks/nlum2O0L.js";import{b as ht,F as bt,a as at}from"../chunks/H7qjuNF4.js";import{S as Qt}from"../chunks/agE6NDSA.js";import{L as qt}from"../chunks/tFcFjFQJ.js";import{L as Yt}from"../chunks/CPwAX0SU.js";import{S as Jt,F as Ze}from"../chunks/BZUPCn-g.js";import{I as Zt}from"../chunks/CM67Jphm.js";import{V as $t,M as er,F as nt,a as it,b as ot,c as dt,d as st}from"../chunks/CwgO52cF.js";import{X as yt}from"../chunks/CiIMiELt.js";import{F as tr}from"../chunks/BWRSGq4A.js";import{U as et}from"../chunks/hiAQl6ey.js";import{T as Et}from"../chunks/CSNyvbvN.js";import{C as wt}from"../chunks/DEuEFefA.js";import{A as Qe,a as qe}from"../chunks/CZyBFLho.js";import{C as ft}from"../chunks/Cv606Ht4.js";import{E as rr}from"../chunks/CYnWUDOj.js";import{P as ar}from"../chunks/h5MFuJx-.js";import{L as nr}from"../chunks/C_E2vM9U.js";import{S as ir}from"../chunks/K87jKp17.js";import{c as or}from"../chunks/CuDfWLaU.js";function dr(){let $=J(""),i=J(Ve([])),R=J(Ve([])),M=J(!1),E=J(Ve({page:1,per_page:100,total:0,total_pages:0})),A=J(Ve(new Set)),I=J(-1),x=J(null),B=J("name"),Q=J("asc"),N=J(""),W=J(""),z=J(!1),S=0;const s=Z(()=>{const a=[...e(i)];return a.sort((l,v)=>{let p=0;switch(e(B)){case"name":p=l.filename.localeCompare(v.filename,void 0,{sensitivity:"base"});break;case"size":p=l.size-v.size;break;case"modified":p=new Date(l.modified).getTime()-new Date(v.modified).getTime();break;case"type":p=l.type.localeCompare(v.type);break}return e(Q)==="asc"?p:-p}),a});async function c(a,l){try{const v=await ut({path:a||void 0,type:e(W)||void 0,per_page:200});if(l!==S)return;o(i,v.items,!0),o(R,v.folders,!0),o(E,v.pagination,!0),o(z,!1)}catch(v){if(l!==S)return;console.error("[MediaManager] Failed to load folder:",v),o(i,[],!0),o(R,[],!0)}finally{l===S&&o(M,!1)}}async function F(a,l){try{const v=await ut({search:a,type:e(W)||void 0,per_page:200});if(l!==S)return;o(i,v.items,!0),o(R,[],!0),o(E,v.pagination,!0),o(z,!0)}catch(v){if(l!==S)return;console.error("[MediaManager] Search failed:",v),o(i,[],!0),o(R,[],!0)}finally{l===S&&o(M,!1)}}return{get currentPath(){return e($)},get files(){return e(s)},get folders(){return e(R)},get loading(){return e(M)},get pagination(){return e(E)},get selectedFiles(){return e(A)},get inspectedFile(){return e(x)},get sortField(){return e(B)},get sortOrder(){return e(Q)},get searchQuery(){return e(N)},get typeFilter(){return e(W)},get isSearching(){return e(z)},get lastSelectedIndex(){return e(I)},get viewMode(){return vt.mediaViewMode},set viewMode(a){vt.mediaViewMode=a},navigateTo(a){o($,a,!0),o(N,""),o(z,!1),o(A,new Set,!0),o(I,-1),o(x,null),o(M,!0);const l=++S;c(a,l)},goUp(){if(e(z)){o(N,""),o(z,!1);const l=++S;o(M,!0),c(e($),l);return}if(!e($))return;const a=e($).split("/");a.pop(),this.navigateTo(a.join("/"))},refresh(){if(e(z)&&e(N)){const a=++S;o(M,!0),F(e(N),a)}else{const a=++S;o(M,!0),c(e($),a)}},search(a){if(o(N,a,!0),o(A,new Set,!0),o(I,-1),o(x,null),!a||a.length<2){o(z,!1);const v=++S;o(M,!0),c(e($),v);return}o(M,!0);const l=++S;F(a,l)},setTypeFilter(a){o(W,a,!0),this.refresh()},setSort(a){e(B)===a?o(Q,e(Q)==="asc"?"desc":"asc",!0):(o(B,a,!0),o(Q,"asc"))},select(a,l){const v=a.path?`${a.path}/${a.filename}`:a.filename;o(A,new Set([v]),!0),o(I,l,!0),o(x,a,!0)},toggleSelect(a,l){const v=a.path?`${a.path}/${a.filename}`:a.filename,p=new Set(e(A));p.has(v)?(p.delete(v),e(x)?.filename===a.filename&&e(x)?.path===a.path&&o(x,null)):(p.add(v),o(x,a,!0)),o(A,p,!0),o(I,l,!0)},selectRange(a){const l=Math.min(e(I),a),v=Math.max(e(I),a),p=new Set(e(A));for(let K=l;K<=v;K++){const U=e(s)[K];if(U){const re=U.path?`${U.path}/${U.filename}`:U.filename;p.add(re)}}o(A,p,!0),e(s)[a]&&o(x,e(s)[a],!0)},selectAll(){const a=new Set;for(const l of e(s)){const v=l.path?`${l.path}/${l.filename}`:l.filename;a.add(v)}o(A,a,!0)},clearSelection(){o(A,new Set,!0),o(I,-1),o(x,null)},isSelected(a){const l=a.path?`${a.path}/${a.filename}`:a.filename;return e(A).has(l)},inspectFile(a){o(x,a,!0)},navigateInspector(a){if(!e(x))return;const l=e(s).findIndex(p=>p.filename===e(x).filename&&p.path===e(x).path),v=a==="next"?l+1:l-1;if(v>=0&&v<e(s).length){const p=e(s)[v];this.select(p,v)}},async deleteSelected(){const a=[],l=[...e(A)];for(const v of l)try{await ct(v)}catch{a.push(v)}return o(A,new Set,!0),o(x,null),this.refresh(),a},async deleteFile(a){const l=a.path?`${a.path}/${a.filename}`:a.filename;await ct(l),e(x)?.filename===a.filename&&e(x)?.path===a.path&&o(x,null);const v=new Set(e(A));v.delete(l),o(A,v,!0),this.refresh()},async createFolder(a){const l=e($)?`${e($)}/${a}`:a;await Bt(l),this.refresh()},async deleteFolder(a){await jt(a.path),this.refresh()},async renameFile(a,l){const v=a.path?`${a.path}/${a.filename}`:a.filename,p=a.path?`${a.path}/${l}`:l,K=await Wt(v,p);return this.refresh(),o(x,K,!0),K},async renameFolder(a,l){const v=a.path.includes("/")?a.path.substring(0,a.path.lastIndexOf("/")):"",p=v?`${v}/${l}`:l;await Xt(a.path,p),this.refresh()}}}const u=dr();var sr=T("<!> <button> </button>",1),lr=T('<!> <span class="text-[0.8125rem] text-muted-foreground"> </span>',1),cr=T('<button class="absolute right-2 top-1/2 -translate-y-1/2 rounded-sm p-0.5 text-muted-foreground transition-colors hover:text-foreground"><!></button>'),ur=T('<button><!> <span class="hidden lg:inline"> </span></button>'),vr=T("<option> </option>"),fr=T('<button class="inline-flex h-8 items-center gap-1.5 rounded-md border border-destructive/30 bg-destructive/10 px-3 text-[0.75rem] font-medium text-destructive transition-colors hover:bg-destructive/20"><!> </button>'),mr=T('<!> <button class="inline-flex h-8 items-center gap-1.5 rounded-md border border-border px-2.5 text-[0.75rem] font-medium text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground"><!> <span class="hidden md:inline"> </span></button> <button class="inline-flex h-8 items-center gap-1.5 rounded-md bg-primary px-3 text-[0.75rem] font-medium text-primary-foreground shadow-sm transition-colors hover:bg-primary/90"><!> <span class="hidden md:inline"> </span></button>',1),gr=T('<div class="flex items-center gap-1 border-b border-border px-4 py-2 text-sm"><button><span class="flex items-center gap-1"><!> Media</span></button> <!> <!></div> <div class="flex items-center gap-2 border-b border-border px-4 py-2"><div class="relative flex-1"><!> <input type="text" class="h-8 w-full rounded-md border border-input bg-muted/50 ps-9 pe-8 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring"/> <!></div> <div class="hidden items-center sm:flex"></div> <select class="h-8 rounded-md border border-input bg-muted/50 px-2 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-ring"></select> <div class="inline-flex rounded-md border border-border shadow-sm"><button><!></button> <button><!></button></div> <div class="h-5 w-px bg-border"></div> <!></div>',1);function pr($,i){Pe(i,!0);let R=xt(i,"readonly",3,!1),M=J(""),E=null;function A(w){o(M,w,!0),E&&clearTimeout(E),E=setTimeout(()=>{u.search(w)},300)}function I(){o(M,""),E&&clearTimeout(E),u.search("")}const x=Z(()=>{if(u.isSearching)return[];const w=u.currentPath;return w?w.split("/"):[]}),B=[{value:"",label:"All",icon:Jt},{value:"image",label:"Images",icon:Zt},{value:"video",label:"Video",icon:$t},{value:"audio",label:"Audio",icon:er},{value:"document",label:"Docs",icon:Ze}],Q=[{value:"name",label:"Name"},{value:"size",label:"Size"},{value:"modified",label:"Date"},{value:"type",label:"Type"}],N=Z(()=>u.selectedFiles.size);var W=gr(),z=xe(W),S=r(z),s=r(S),c=r(s);ht(c,{size:14}),pt(),t(s),t(S);var F=d(S,2);Le(F,17,()=>e(x),Ye,(w,D,g)=>{var O=sr(),V=xe(O);He(V,{name:"chevron-forward",size:12,class:"text-muted-foreground/50"});var ce=d(V,2),ye=r(ce,!0);t(ce),X(()=>{ae(ce,1,`rounded px-1.5 py-0.5 text-[0.8125rem] font-medium transition-colors
|
||
${g===e(x).length-1?"text-foreground":"text-muted-foreground hover:text-foreground"}`),h(ye,e(D))}),L("click",ce,()=>u.navigateTo(e(x).slice(0,g+1).join("/"))),_(w,O)});var a=d(F,2);{var l=w=>{var D=lr(),g=xe(D);He(g,{name:"chevron-forward",size:12,class:"text-muted-foreground/50"});var O=d(g,2),V=r(O);t(O),X(()=>h(V,`Search: "${u.searchQuery??""}"`)),_(w,D)};P(a,w=>{u.isSearching&&w(l)})}t(z);var v=d(z,2),p=r(v),K=r(p);Qt(K,{size:14,class:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground"});var U=d(K,2);tt(U);var re=d(U,2);{var ne=w=>{var D=cr(),g=r(D);yt(g,{size:14}),t(D),X(O=>me(D,"aria-label",O),[()=>j.t("ADMIN_NEXT.CLEAR_SEARCH")]),L("click",D,I),_(w,D)};P(re,w=>{e(M)&&w(ne)})}t(p);var de=d(p,2);Le(de,21,()=>B,Ye,(w,D)=>{var g=ur(),O=r(g);Je(O,()=>e(D).icon,(ye,Te)=>{Te(ye,{size:13})});var V=d(O,2),ce=r(V,!0);t(V),t(g),X(()=>{ae(g,1,`inline-flex h-8 items-center gap-1 px-2.5 text-[0.75rem] font-medium transition-colors first:rounded-l-md first:border first:border-r-0 last:rounded-r-md last:border last:border-l-0 [&:not(:first-child):not(:last-child)]:border-y
|
||
${u.typeFilter===e(D).value?"border-primary/30 bg-primary/10 text-primary":"border-border text-muted-foreground hover:bg-accent/50 hover:text-foreground"}`),h(ce,e(D).label)}),L("click",g,()=>u.setTypeFilter(e(D).value)),_(w,g)}),t(de);var q=d(de,2);Le(q,21,()=>Q,Ye,(w,D)=>{var g=vr(),O=r(g,!0);t(g);var V={};X(()=>{h(O,e(D).label),V!==(V=e(D).value)&&(g.value=(g.__value=e(D).value)??"")}),_(w,g)}),t(q);var ie;Lt(q);var le=d(q,2),b=r(le),Y=r(b);qt(Y,{size:14}),t(b);var ee=d(b,2),C=r(ee);Yt(C,{size:14}),t(ee),t(le);var G=d(le,4);{var y=w=>{var D=mr(),g=xe(D);{var O=ge=>{var Ee=fr(),Fe=r(Ee);Et(Fe,{size:13});var We=d(Fe);t(Ee),X(()=>h(We,` Delete (${e(N)??""})`)),L("click",Ee,function(...Ge){i.ondeleteselected?.apply(this,Ge)}),_(ge,Ee)};P(g,ge=>{e(N)>0&&ge(O)})}var V=d(g,2),ce=r(V);tr(ce,{size:14});var ye=d(ce,2),Te=r(ye,!0);t(ye),t(V);var Ne=d(V,2),Xe=r(Ne);et(Xe,{size:13});var ze=d(Xe,2),Ke=r(ze,!0);t(ze),t(Ne),X((ge,Ee,Fe)=>{me(V,"aria-label",ge),h(Te,Ee),h(Ke,Fe)},[()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_TOOLBAR.NEW_FOLDER"),()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_TOOLBAR.FOLDER"),()=>j.t("ADMIN_NEXT.UPLOAD")]),L("click",V,function(...ge){i.onnewfolder?.apply(this,ge)}),L("click",Ne,function(...ge){i.onupload?.apply(this,ge)}),_(w,D)};P(G,w=>{R()||w(y)})}t(v),X((w,D,g)=>{ae(S,1,`rounded px-1.5 py-0.5 text-[0.8125rem] font-medium transition-colors
|
||
${!u.currentPath&&!u.isSearching?"text-foreground":"text-muted-foreground hover:text-foreground"}`),me(U,"placeholder",w),Rt(U,e(M)),ie!==(ie=u.sortField)&&(q.value=(q.__value=u.sortField)??"",Ut(q,u.sortField)),ae(b,1,`inline-flex h-8 w-8 items-center justify-center transition-colors first:rounded-l-md last:rounded-r-md
|
||
${u.viewMode==="grid"?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"}`),me(b,"aria-label",D),ae(ee,1,`inline-flex h-8 w-8 items-center justify-center transition-colors first:rounded-l-md last:rounded-r-md
|
||
${u.viewMode==="list"?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"}`),me(ee,"aria-label",g)},[()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_TOOLBAR.SEARCH_MEDIA"),()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_TOOLBAR.GRID_VIEW"),()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_TOOLBAR.LIST_VIEW")]),L("click",S,()=>u.navigateTo("")),L("input",U,w=>A(w.currentTarget.value)),L("change",q,w=>u.setSort(w.currentTarget.value)),L("click",b,()=>u.viewMode="grid"),L("click",ee,()=>u.viewMode="list"),_($,W),Ce()}Be(["click","input","change"]);var xr=T('<div class="group flex cursor-pointer flex-col items-center justify-center gap-2 rounded-lg border border-border bg-card p-4 transition-all hover:border-primary/30 hover:bg-accent/50 hover:shadow-sm"><!> <div class="w-full text-center"><div class="truncate text-[0.8125rem] font-medium text-foreground"> </div> <div class="text-[0.6875rem] text-muted-foreground"> <!></div></div></div>'),_r=T('<img class="h-full w-full object-cover" loading="lazy"/>'),hr=T('<div><!> <span class="rounded bg-background/80 px-2 py-0.5 text-[0.625rem] font-semibold tracking-wide"> </span></div>'),br=T('<div><div class="relative aspect-square overflow-hidden bg-muted/50"><!> <div><div><!></div></div></div> <div class="flex flex-col gap-0.5 px-2.5 py-2"><div class="truncate text-[0.75rem] font-medium text-foreground"> </div> <div class="text-[0.6875rem] text-muted-foreground"> </div></div></div>');function mt($,i){Pe(i,!0);function R(c){const F=rt(c);return F.startsWith("http")?F:F.startsWith("/")?`${be.serverUrl}${F}`:`${be.serverUrl}/${F}`}function M(c){return c.startsWith("http")?c:`${be.serverUrl}${c}`}function E(c){return c.thumbnail_url?M(c.thumbnail_url):R(c.url)}function A(c){return c.type.startsWith("image/")}function I(c){return c.startsWith("video/")?{icon:nt,bg:"bg-purple-500/10 text-purple-500 dark:text-purple-400"}:c.startsWith("audio/")?{icon:it,bg:"bg-emerald-500/10 text-emerald-500 dark:text-emerald-400"}:c==="application/pdf"?{icon:Ze,bg:"bg-red-500/10 text-red-500 dark:text-red-400"}:c.includes("zip")||c.includes("compressed")||c.includes("tar")||c.includes("gzip")?{icon:ot,bg:"bg-amber-500/10 text-amber-500 dark:text-amber-400"}:c.includes("spreadsheet")||c.includes("excel")?{icon:dt,bg:"bg-green-500/10 text-green-500 dark:text-green-400"}:c==="image/svg+xml"?{icon:st,bg:"bg-blue-500/10 text-blue-500 dark:text-blue-400"}:{icon:at,bg:"bg-muted text-muted-foreground"}}function x(c){const F=c.split(".");return F.length>1?F.pop().toUpperCase():""}function B(c){return c<1024?`${c} B`:c<1024*1024?`${(c/1024).toFixed(0)} KB`:`${(c/(1024*1024)).toFixed(1)} MB`}function Q(c){if(i.kind==="folder"){u.navigateTo(i.folder.path);return}c.metaKey||c.ctrlKey?u.toggleSelect(i.item,i.index):c.shiftKey?u.selectRange(i.index):u.select(i.item,i.index)}const N=Z(()=>i.kind==="file"&&u.isSelected(i.item));var W=Ue(),z=xe(W);{var S=c=>{var F=xr(),a=r(F);bt(a,{size:32,class:"text-primary/70"});var l=d(a,2),v=r(l),p=r(v,!0);t(v);var K=d(v,2),U=r(K),re=d(U);{var ne=de=>{var q=Dt();X(()=>h(q,`, ${i.folder.children_count??""} folder${i.folder.children_count!==1?"s":""}`)),_(de,q)};P(re,de=>{i.folder.children_count>0&&de(ne)})}t(K),t(l),t(F),X(()=>{h(p,i.folder.name),h(U,`${i.folder.file_count??""} file${i.folder.file_count!==1?"s":""} `)}),L("click",F,Q),_(c,F)},s=c=>{const F=Z(()=>I(i.item.type));var a=br(),l=r(a),v=r(l);{var p=C=>{var G=_r();X(y=>{me(G,"src",y),me(G,"alt",i.item.filename)},[()=>E(i.item)]),_(C,G)},K=Z(()=>A(i.item)),U=C=>{var G=hr(),y=r(G);Je(y,()=>e(F).icon,(g,O)=>{O(g,{size:28})});var w=d(y,2),D=r(w,!0);t(w),t(G),X(g=>{ae(G,1,`flex h-full w-full flex-col items-center justify-center gap-2 ${e(F).bg??""}`),h(D,g)},[()=>x(i.item.filename)]),_(C,G)};P(v,C=>{e(K)?C(p):C(U,-1)})}var re=d(v,2),ne=r(re),de=r(ne);{var q=C=>{wt(C,{size:12,strokeWidth:3})};P(de,C=>{e(N)&&C(q)})}t(ne),t(re),t(l);var ie=d(l,2),le=r(ie),b=r(le,!0);t(le);var Y=d(le,2),ee=r(Y,!0);t(Y),t(ie),t(a),X(C=>{ae(a,1,`group relative flex cursor-pointer flex-col overflow-hidden rounded-lg border-2 transition-colors
|
||
${e(N)?"border-primary bg-primary/5 shadow-sm":"border-transparent bg-card hover:border-border hover:shadow-sm"}`),ae(re,1,`absolute left-1.5 top-1.5 ${e(N)?"opacity-100":"opacity-0 group-hover:opacity-100"} transition-opacity`),ae(ne,1,`flex h-5 w-5 items-center justify-center rounded border-2 shadow-md transition-colors
|
||
${e(N)?"border-primary bg-primary text-primary-foreground":"border-foreground/60 bg-background/85"}`),h(b,i.item.filename),h(ee,C)},[()=>B(i.item.size)]),L("click",a,Q),_(c,a)};P(z,c=>{i.kind==="folder"?c(S):c(s,-1)})}_($,W),Ce()}Be(["click"]);var yr=T('<div class="grid grid-cols-[repeat(auto-fill,minmax(160px,1fr))] gap-3 p-4"><!> <!></div>');function Er($){const i=Z(()=>u.folders),R=Z(()=>u.files);var M=yr(),E=r(M);Le(E,17,()=>e(i),I=>I.path,(I,x)=>{mt(I,{kind:"folder",get folder(){return e(x)}})});var A=d(E,2);Le(A,19,()=>e(R),I=>I.path+"/"+I.filename,(I,x,B)=>{mt(I,{kind:"file",get item(){return e(x)},get index(){return e(B)}})}),t(M),_($,M)}var wr=T('<div class="group flex cursor-pointer items-center gap-3 border-b border-border/50 px-4 py-2 transition-colors hover:bg-accent/50"><div class="flex h-10 w-10 shrink-0 items-center justify-center rounded-md bg-primary/10"><!></div> <div class="min-w-0 flex-1"><div class="text-sm font-medium text-foreground"> </div> <div class="text-[0.6875rem] text-muted-foreground"> </div></div> <!></div>'),Mr=T('<img alt="" class="h-full w-full object-cover" loading="lazy"/>'),Dr=T('<div class="truncate text-[0.6875rem] text-muted-foreground"> </div>'),kr=T('<div><div><!></div> <div class="flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-md border border-border bg-muted/50"><!></div> <div class="min-w-0 flex-1"><div class="truncate text-sm font-medium text-foreground"> </div> <!></div> <div class="hidden w-20 text-end text-[0.6875rem] text-muted-foreground sm:block"> </div> <div class="w-16 text-end text-[0.6875rem] text-muted-foreground"> </div> <div class="hidden w-24 text-end text-[0.6875rem] text-muted-foreground md:block"> </div></div>');function gt($,i){Pe(i,!0);function R(s){return s.startsWith("http")?s:`${be.serverUrl}${s}`}function M(s){if(s.thumbnail_url)return R(s.thumbnail_url);if(s.type.startsWith("image/")){const c=rt(s.url);return c.startsWith("http")?c:`${be.serverUrl}${c.startsWith("/")?"":"/"}${c}`}return""}function E(s){return s.startsWith("video/")?{icon:nt,color:"text-purple-500 dark:text-purple-400"}:s.startsWith("audio/")?{icon:it,color:"text-emerald-500 dark:text-emerald-400"}:s==="application/pdf"?{icon:Ze,color:"text-red-500 dark:text-red-400"}:s.includes("zip")||s.includes("compressed")||s.includes("tar")?{icon:ot,color:"text-amber-500 dark:text-amber-400"}:s.includes("spreadsheet")||s.includes("excel")?{icon:dt,color:"text-green-500 dark:text-green-400"}:s==="image/svg+xml"?{icon:st,color:"text-blue-500 dark:text-blue-400"}:{icon:at,color:"text-muted-foreground"}}function A(s){return s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(0)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`}function I(s){return new Date(s).toLocaleDateString(void 0,{month:"short",day:"numeric",year:"numeric"})}function x(s){return s.split("/")[1]?.toUpperCase()??s}function B(s){if(i.kind==="folder"){u.navigateTo(i.folder.path);return}s.metaKey||s.ctrlKey?u.toggleSelect(i.item,i.index):s.shiftKey?u.selectRange(i.index):u.select(i.item,i.index)}const Q=Z(()=>i.kind==="file"&&u.isSelected(i.item));var N=Ue(),W=xe(N);{var z=s=>{var c=wr(),F=r(c),a=r(F);bt(a,{size:18,class:"text-primary/70"}),t(F);var l=d(F,2),v=r(l),p=r(v,!0);t(v);var K=d(v,2),U=r(K);t(K),t(l);var re=d(l,2);He(re,{name:"chevron-forward",size:14,class:"text-muted-foreground/40"}),t(c),X(()=>{h(p,i.folder.name),h(U,`${i.folder.file_count??""} file${i.folder.file_count!==1?"s":""}`)}),L("click",c,B),_(s,c)},S=s=>{const c=Z(()=>E(i.item.type)),F=Z(()=>M(i.item));var a=kr(),l=r(a),v=r(l);{var p=g=>{wt(g,{size:12,strokeWidth:3})};P(v,g=>{e(Q)&&g(p)})}t(l);var K=d(l,2),U=r(K);{var re=g=>{var O=Mr();X(()=>me(O,"src",e(F))),_(g,O)},ne=Z(()=>e(F)&&i.item.type.startsWith("image/")),de=g=>{var O=Ue(),V=xe(O);Je(V,()=>e(c).icon,(ce,ye)=>{ye(ce,{size:16,get class(){return e(c).color}})}),_(g,O)};P(U,g=>{e(ne)?g(re):g(de,-1)})}t(K);var q=d(K,2),ie=r(q),le=r(ie,!0);t(ie);var b=d(ie,2);{var Y=g=>{var O=Dr(),V=r(O,!0);t(O),X(()=>h(V,i.item.path)),_(g,O)};P(b,g=>{i.item.path&&g(Y)})}t(q);var ee=d(q,2),C=r(ee,!0);t(ee);var G=d(ee,2),y=r(G,!0);t(G);var w=d(G,2),D=r(w,!0);t(w),t(a),X((g,O,V)=>{ae(a,1,`group flex cursor-pointer items-center gap-3 border-b border-border/50 px-4 py-2 transition-colors
|
||
${e(Q)?"bg-primary/5":"hover:bg-accent/50"}`),ae(l,1,`flex h-5 w-5 shrink-0 items-center justify-center rounded border transition-colors
|
||
${e(Q)?"border-primary bg-primary text-primary-foreground":"border-border"}
|
||
${e(Q)?"":"opacity-0 group-hover:opacity-100"}`),h(le,i.item.filename),h(C,g),h(y,O),h(D,V)},[()=>x(i.item.type),()=>A(i.item.size),()=>I(i.item.modified)]),L("click",a,B),_(s,a)};P(W,s=>{i.kind==="folder"?s(z):s(S,-1)})}_($,N),Ce()}Be(["click"]);var Ar=T('<div class="flex items-center gap-3 border-b border-border px-4 py-1.5"><div class="w-[76px] shrink-0"></div> <div class="flex-1"><button>Name <!></button></div> <div class="hidden w-20 text-end sm:block"><button>Type <!></button></div> <div class="w-16 text-end"><button>Size <!></button></div> <div class="hidden w-24 text-end md:block"><button> <!></button></div></div> <div><!> <!></div>',1);function Ir($,i){Pe(i,!0);const R=Z(()=>u.folders),M=Z(()=>u.files),E=Z(()=>u.sortField),A=Z(()=>u.sortOrder);function I(b){u.setSort(b)}var x=Ar(),B=xe(x),Q=d(r(B),2),N=r(Q),W=d(r(N));{var z=b=>{var Y=Ue(),ee=xe(Y);{var C=y=>{Qe(y,{size:11})},G=y=>{qe(y,{size:11})};P(ee,y=>{e(A)==="asc"?y(C):y(G,-1)})}_(b,Y)};P(W,b=>{e(E)==="name"&&b(z)})}t(N),t(Q);var S=d(Q,2),s=r(S),c=d(r(s));{var F=b=>{var Y=Ue(),ee=xe(Y);{var C=y=>{Qe(y,{size:11})},G=y=>{qe(y,{size:11})};P(ee,y=>{e(A)==="asc"?y(C):y(G,-1)})}_(b,Y)};P(c,b=>{e(E)==="type"&&b(F)})}t(s),t(S);var a=d(S,2),l=r(a),v=d(r(l));{var p=b=>{var Y=Ue(),ee=xe(Y);{var C=y=>{Qe(y,{size:11})},G=y=>{qe(y,{size:11})};P(ee,y=>{e(A)==="asc"?y(C):y(G,-1)})}_(b,Y)};P(v,b=>{e(E)==="size"&&b(p)})}t(l),t(a);var K=d(a,2),U=r(K),re=r(U),ne=d(re);{var de=b=>{var Y=Ue(),ee=xe(Y);{var C=y=>{Qe(y,{size:11})},G=y=>{qe(y,{size:11})};P(ee,y=>{e(A)==="asc"?y(C):y(G,-1)})}_(b,Y)};P(ne,b=>{e(E)==="modified"&&b(de)})}t(U),t(K),t(B);var q=d(B,2),ie=r(q);Le(ie,17,()=>e(R),b=>b.path,(b,Y)=>{gt(b,{kind:"folder",get folder(){return e(Y)}})});var le=d(ie,2);Le(le,19,()=>e(M),b=>b.path+"/"+b.filename,(b,Y,ee)=>{gt(b,{kind:"file",get item(){return e(Y)},get index(){return e(ee)}})}),t(q),X(b=>{ae(N,1,`flex items-center gap-1 text-[0.6875rem] font-medium uppercase tracking-wider transition-colors
|
||
${e(E)==="name"?"text-foreground":"text-muted-foreground hover:text-foreground"}`),ae(s,1,`ms-auto flex items-center gap-1 text-[0.6875rem] font-medium uppercase tracking-wider transition-colors
|
||
${e(E)==="type"?"text-foreground":"text-muted-foreground hover:text-foreground"}`),ae(l,1,`ms-auto flex items-center gap-1 text-[0.6875rem] font-medium uppercase tracking-wider transition-colors
|
||
${e(E)==="size"?"text-foreground":"text-muted-foreground hover:text-foreground"}`),ae(U,1,`ms-auto flex items-center gap-1 text-[0.6875rem] font-medium uppercase tracking-wider transition-colors
|
||
${e(E)==="modified"?"text-foreground":"text-muted-foreground hover:text-foreground"}`),h(re,`${b??""} `)},[()=>j.t("ADMIN_NEXT.PAGES.HEADER_MODIFIED")]),L("click",N,()=>I("name")),L("click",s,()=>I("type")),L("click",l,()=>I("size")),L("click",U,()=>I("modified")),_($,x),Ce()}Be(["click"]);var Tr=T('<img class="w-full object-contain" style="max-height: 240px;"/>'),Fr=T('<div><!> <span class="text-xs font-medium"> </span></div>'),Sr=T('<input class="w-full rounded-md border border-input bg-transparent px-2 py-1 text-sm font-medium focus:outline-none focus:ring-1 focus:ring-ring"/>'),Nr=T('<div class="flex items-center gap-2"><h3 class="min-w-0 flex-1 truncate text-sm font-semibold text-foreground"> </h3> <button class="shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"><!></button></div>'),zr=T('<div><dt class="text-[0.6875rem] font-medium text-muted-foreground">Path</dt> <dd class="mt-0.5 text-sm text-foreground"> </dd></div>'),Or=T('<div><dt class="text-[0.6875rem] font-medium text-muted-foreground"> </dt> <dd class="mt-0.5 text-sm text-foreground"> </dd></div>'),Lr=T('<div class="flex h-full flex-col border-s border-border bg-card"><div class="flex items-center justify-between border-b border-border px-4 py-2"><div class="flex items-center gap-1"><button class="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"><!></button> <button class="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"><!></button></div> <button class="inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground" aria-label="Close"><!></button></div> <div class="flex-1 overflow-y-auto p-4"><div class="overflow-hidden rounded-lg border border-border bg-muted/30"><!></div> <div class="mt-4"><!></div> <div class="mt-4 space-y-3"><!> <div><dt class="text-[0.6875rem] font-medium text-muted-foreground">Type</dt> <dd class="mt-0.5 text-sm text-foreground"> </dd></div> <div><dt class="text-[0.6875rem] font-medium text-muted-foreground">Size</dt> <dd class="mt-0.5 text-sm text-foreground"> </dd></div> <!> <div><dt class="text-[0.6875rem] font-medium text-muted-foreground"> </dt> <dd class="mt-0.5 text-sm text-foreground"> </dd></div></div> <div class="mt-5 space-y-2"><button class="flex w-full items-center gap-2 rounded-md border border-border px-3 py-2 text-start text-[0.75rem] transition-colors hover:bg-accent/50"><!> <span class="min-w-0 flex-1 truncate font-mono text-muted-foreground"> </span></button> <button class="flex w-full items-center gap-2 rounded-md border border-border px-3 py-2 text-start text-[0.75rem] transition-colors hover:bg-accent/50"><!> <span class="min-w-0 flex-1 truncate font-mono text-muted-foreground"> </span></button></div> <div class="mt-5 flex items-center gap-2 border-t border-border pt-4"><a target="_blank" rel="noopener" class="inline-flex h-8 items-center gap-1.5 rounded-md border border-border px-3 text-[0.75rem] font-medium text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground"><!> Open</a> <div class="flex-1"></div> <button class="inline-flex h-8 items-center gap-1.5 rounded-md border border-destructive/30 bg-destructive/10 px-3 text-[0.75rem] font-medium text-destructive transition-colors hover:bg-destructive/20"><!> </button></div></div></div>');function Rr($,i){Pe(i,!0);let R=J(!1),M=J("");function E(f){const k=rt(f);return k.startsWith("http")?k:k.startsWith("/")?`${be.serverUrl}${k}`:`${be.serverUrl}/${k}`}function A(f){return f.startsWith("http")?f:`${be.serverUrl}${f}`}function I(){return i.file.thumbnail_url?A(i.file.thumbnail_url):E(i.file.url)}function x(){return i.file.type.startsWith("image/")}function B(f){return f.startsWith("video/")?{icon:nt,bg:"bg-purple-500/10 text-purple-500"}:f.startsWith("audio/")?{icon:it,bg:"bg-emerald-500/10 text-emerald-500"}:f==="application/pdf"?{icon:Ze,bg:"bg-red-500/10 text-red-500"}:f.includes("zip")||f.includes("compressed")||f.includes("tar")?{icon:ot,bg:"bg-amber-500/10 text-amber-500"}:f.includes("spreadsheet")||f.includes("excel")?{icon:dt,bg:"bg-green-500/10 text-green-500"}:f==="image/svg+xml"?{icon:st,bg:"bg-blue-500/10 text-blue-500"}:{icon:at,bg:"bg-muted text-muted-foreground"}}function Q(f){return f<1024?`${f} B`:f<1024*1024?`${(f/1024).toFixed(0)} KB`:`${(f/(1024*1024)).toFixed(1)} MB`}function N(f){return new Date(f).toLocaleString()}function W(){return`media://${i.file.path?`${i.file.path}/${i.file.filename}`:i.file.filename}`}function z(){const f=W();return i.file.type.startsWith("image/")?``:`[${i.file.filename}](${f})`}async function S(f,k){try{await navigator.clipboard.writeText(f),ke.success(j.t("ADMIN_NEXT.TOASTS.COPIED",{label:k}))}catch{ke.error(j.t("ADMIN_NEXT.MEDIA.MEDIA_INSPECTOR.FAILED_TO_COPY"))}}function s(){o(R,!0),o(M,i.file.filename,!0)}async function c(){if(!e(M)||e(M)===i.file.filename){o(R,!1);return}try{await u.renameFile(i.file,e(M)),ke.success(j.t("ADMIN_NEXT.MEDIA.MEDIA_INSPECTOR.FILE_RENAMED")),o(R,!1)}catch(f){ke.error(`Rename failed: ${f instanceof Error?f.message:"Unknown error"}`)}}function F(f){f.key==="Enter"?(f.preventDefault(),c()):f.key==="Escape"&&o(R,!1)}var a=Lr(),l=r(a),v=r(l),p=r(v),K=r(p);He(K,{name:"chevron-back",size:14}),t(p);var U=d(p,2),re=r(U);He(re,{name:"chevron-forward",size:14}),t(U),t(v);var ne=d(v,2),de=r(ne);yt(de,{size:14}),t(ne),t(l);var q=d(l,2),ie=r(q),le=r(ie);{var b=f=>{var k=Tr();X(te=>{me(k,"src",te),me(k,"alt",i.file.filename)},[()=>I()]),_(f,k)},Y=Z(()=>x()),ee=f=>{const k=Z(()=>B(i.file.type));var te=Fr(),Ie=r(te);Je(Ie,()=>e(k).icon,(Se,$e)=>{$e(Se,{size:36})});var De=d(Ie,2),Re=r(De,!0);t(De),t(te),X(Se=>{ae(te,1,`flex h-40 flex-col items-center justify-center gap-2 ${e(k).bg??""}`),h(Re,Se)},[()=>i.file.filename.split(".").pop()?.toUpperCase()]),_(f,te)};P(le,f=>{e(Y)?f(b):f(ee,-1)})}t(ie);var C=d(ie,2),G=r(C);{var y=f=>{var k=Sr();tt(k),L("keydown",k,F),je("blur",k,c),_t(k,()=>e(M),te=>o(M,te)),_(f,k)},w=f=>{var k=Nr(),te=r(k),Ie=r(te,!0);t(te);var De=d(te,2),Re=r(De);ar(Re,{size:12}),t(De),t(k),X(Se=>{h(Ie,i.file.filename),me(De,"aria-label",Se)},[()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_INSPECTOR.RENAME")]),L("click",De,s),_(f,k)};P(G,f=>{e(R)?f(y):f(w,-1)})}t(C);var D=d(C,2),g=r(D);{var O=f=>{var k=zr(),te=d(r(k),2),Ie=r(te);t(te),t(k),X(()=>h(Ie,`${i.file.path??""}/`)),_(f,k)};P(g,f=>{i.file.path&&f(O)})}var V=d(g,2),ce=d(r(V),2),ye=r(ce,!0);t(ce),t(V);var Te=d(V,2),Ne=d(r(Te),2),Xe=r(Ne,!0);t(Ne),t(Te);var ze=d(Te,2);{var Ke=f=>{var k=Or(),te=r(k),Ie=r(te,!0);t(te);var De=d(te,2),Re=r(De);t(De),t(k),X(Se=>{h(Ie,Se),h(Re,`${i.file.dimensions.width??""} × ${i.file.dimensions.height??""}`)},[()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_INSPECTOR.DIMENSIONS")]),_(f,k)};P(ze,f=>{i.file.dimensions&&f(Ke)})}var ge=d(ze,2),Ee=r(ge),Fe=r(Ee,!0);t(Ee);var We=d(Ee,2),Ge=r(We,!0);t(We),t(ge),t(D);var n=d(D,2),m=r(n),H=r(m);ft(H,{size:13,class:"shrink-0 text-muted-foreground"});var fe=d(H,2),we=r(fe,!0);t(fe),t(m);var ue=d(m,2),Ae=r(ue);ft(Ae,{size:13,class:"shrink-0 text-muted-foreground"});var oe=d(Ae,2),_e=r(oe,!0);t(oe),t(ue),t(n);var ve=d(n,2),pe=r(ve),Me=r(pe);rr(Me,{size:13}),pt(),t(pe);var he=d(pe,4),se=r(he);Et(se,{size:13});var Oe=d(se);t(he),t(ve),t(q),t(a),X((f,k,te,Ie,De,Re,Se,$e,Mt)=>{me(p,"aria-label",f),me(U,"aria-label",k),h(ye,i.file.type),h(Xe,te),h(Fe,Ie),h(Ge,De),h(we,Re),h(_e,Se),me(pe,"href",$e),h(Oe,` ${Mt??""}`)},[()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_INSPECTOR.PREVIOUS_FILE"),()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_INSPECTOR.NEXT_FILE"),()=>Q(i.file.size),()=>j.t("ADMIN_NEXT.PAGES.HEADER_MODIFIED"),()=>N(i.file.modified),()=>W(),()=>z(),()=>E(i.file.url),()=>j.t("ADMIN_NEXT.DELETE")]),L("click",p,()=>u.navigateInspector("prev")),L("click",U,()=>u.navigateInspector("next")),L("click",ne,()=>u.inspectFile(null)),L("click",m,()=>S(W(),"Media path")),L("click",ue,()=>S(z(),"Markdown")),L("click",he,()=>i.ondelete(i.file)),_($,a),Ce()}Be(["click","keydown"]);var Ur=T('<div class="flex h-64 items-center justify-center"><!></div>'),Pr=T('<button class="mt-2 inline-flex h-9 items-center gap-2 rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground shadow-sm transition-colors hover:bg-primary/90"><!> </button>'),Cr=T('<div class="flex h-64 flex-col items-center justify-center gap-3 text-center"><div class="flex h-14 w-14 items-center justify-center rounded-xl bg-muted"><!></div> <div><p class="text-sm font-medium text-foreground"> </p> <p class="mt-1 text-xs text-muted-foreground"> </p></div> <!></div>'),Xr=T('<div class="space-y-1"><div class="flex items-center justify-between text-xs text-muted-foreground"><span class="truncate"> </span> <span> </span></div> <div class="h-1.5 overflow-hidden rounded-full bg-secondary"><div class="h-full rounded-full bg-primary transition-[width] duration-200"></div></div></div>'),Wr=T('<div class="border-t border-border bg-card px-4 py-3"><div class="space-y-2"></div></div>'),jr=T('<div class="hidden w-[320px] shrink-0 lg:block"><!></div>'),Br=T('to <span class="font-semibold"> </span>',1),Kr=T('<div class="absolute inset-0 z-10 flex items-center justify-center bg-background/80 backdrop-blur-sm"><div class="flex flex-col items-center gap-3 rounded-xl border-2 border-dashed border-primary/50 bg-primary/5 px-12 py-8"><!> <p class="text-sm font-medium text-primary">Drop files to upload <!></p></div></div>'),Gr=T('<div class="fixed inset-0 z-50 flex items-center justify-center bg-neutral-900/75 p-4 backdrop-blur-sm"><div class="w-full max-w-sm rounded-xl border border-border bg-card p-6 shadow-2xl"><h3 class="text-base font-semibold text-foreground"> </h3> <p class="mt-1 text-xs text-muted-foreground"> </p> <input class="mt-4 flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"/> <div class="mt-4 flex justify-end gap-2"><button class="inline-flex h-9 items-center rounded-md border border-border px-4 text-sm font-medium text-foreground transition-colors hover:bg-accent"> </button> <button class="inline-flex h-9 items-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground shadow-sm transition-colors hover:bg-primary/90 disabled:opacity-50"> </button></div></div></div>'),Vr=T('<input type="file" multiple="" class="hidden"/> <div class="flex h-full flex-col"><!> <div class="relative flex flex-1 overflow-hidden"><div class="flex-1 overflow-y-auto"><!> <!></div> <!> <!></div></div> <!> <!>',1);function Hr($,i){Pe(i,!0);let R=xt(i,"readonly",3,!1),M=J(!1),E=J(Ve(new Map)),A=J(!1),I=J(0),x=J(!1),B=J(null),Q=J(""),N=J(!1),W=J(!1),z=J(""),S,s;function c(){const n=u.currentPath,m=`${be.serverUrl}${be.apiPrefix}/media`;return n?`${m}?path=${encodeURIComponent(n)}`:m}function F(){const n={};return be.accessToken&&(n["X-API-Token"]=be.accessToken),n["X-Grav-Environment"]=be.gravEnvironment,n}function a(){s=new Kt({id:"site-media",autoProceed:!0,restrictions:{maxFileSize:64*1024*1024}}),s.use(Gt,{endpoint:c(),fieldName:"file",headers:F}),s.use(Vt,{quality:.8,actions:{revert:!0,rotate:!0,granularRotate:!0,flip:!0,zoomIn:!0,zoomOut:!0,cropSquare:!0,cropWidescreen:!0,cropWidescreenVertical:!0}}),s.addPreProcessor(async()=>{await Nt.ensureAuth()}),s.on("upload-start",()=>{o(M,!0)}),s.on("upload-progress",(n,m)=>{if(n){const H=m.bytesTotal??0,fe=H>0?Math.round(m.bytesUploaded/H*100):0;o(E,new Map(e(E).set(n.id,fe)),!0)}}),s.on("upload-success",n=>{n&&(e(E).delete(n.id),o(E,new Map(e(E)),!0))}),s.on("upload-error",(n,m)=>{ke.error(`Failed to upload ${n?.name??"file"}: ${m.message}`)}),s.on("complete",n=>{o(M,!1),o(E,new Map,!0);const m=n?.successful?.length??0;if(m>0){ke.success(j.t("ADMIN_NEXT.TOASTS.FILES_UPLOADED",{n:m}));const H=u.currentPath||"/";zt.emit([`media:update:${H}`,"media:list"])}u.refresh(),s?.cancelAll()})}kt(()=>{if(u.currentPath,s){const n=s.getPlugin("XHRUpload");n&&(n.opts.endpoint=c())}});function l(n){if(s)for(const m of n)try{s.addFile({name:m.name,type:m.type,data:m,source:"local"})}catch(H){console.warn("Could not add file:",H)}}function v(n){n.preventDefault(),lt(I),n.dataTransfer?.types.includes("Files")&&o(A,!0)}function p(){lt(I,-1),e(I)<=0&&(o(I,0),o(A,!1))}function K(n){n.preventDefault(),n.dataTransfer&&(n.dataTransfer.dropEffect="copy")}function U(n){n.preventDefault(),o(A,!1),o(I,0);const m=n.dataTransfer?.files;!m||m.length===0||l(Array.from(m))}function re(n){const m=n.target;!m.files||m.files.length===0||(l(Array.from(m.files)),m.value="")}function ne(){S?.click()}function de(){o(z,""),o(W,!0)}async function q(){if(e(z).trim())try{await u.createFolder(e(z).trim()),ke.success(j.t("ADMIN_NEXT.TOASTS.FOLDER_CREATED",{name:e(z).trim()})),o(W,!1)}catch(n){ke.error(`Failed to create folder: ${n instanceof Error?n.message:"Unknown error"}`)}}function ie(n){o(B,n,!0),o(Q,`Delete "${n.filename}"? This cannot be undone.`),o(N,!1),o(x,!0)}function le(){const n=u.selectedFiles.size;o(B,null),o(Q,`Delete ${n} selected file${n!==1?"s":""}? This cannot be undone.`),o(N,!0),o(x,!0)}async function b(){o(x,!1);try{if(e(N)){const n=await u.deleteSelected();n.length>0?ke.error(j.t("ADMIN_NEXT.TOASTS.FILES_DELETE_FAILED",{n:n.length})):ke.success(j.t("ADMIN_NEXT.MEDIA.MEDIA_MANAGER.FILES_DELETED"))}else e(B)&&(await u.deleteFile(e(B)),ke.success(j.t("ADMIN_NEXT.TOASTS.FILE_DELETED",{name:e(B).filename})))}catch(n){ke.error(`Delete failed: ${n instanceof Error?n.message:"Unknown error"}`)}}function Y(n){n.target instanceof HTMLInputElement||n.target instanceof HTMLTextAreaElement||(n.key==="Escape"?u.inspectedFile?u.inspectFile(null):u.clearSelection():n.key==="ArrowLeft"?(u.navigateInspector("prev"),n.preventDefault()):n.key==="ArrowRight"?(u.navigateInspector("next"),n.preventDefault()):(n.key==="Delete"||n.key==="Backspace")&&u.selectedFiles.size>0?(le(),n.preventDefault()):(n.metaKey||n.ctrlKey)&&n.key==="a"&&(u.selectAll(),n.preventDefault()))}const ee=Z(()=>u.files.length>0||u.folders.length>0);Ot(()=>(a(),u.navigateTo(""),()=>{s?.cancelAll()}));var C=Vr();je("keydown",At,Y);var G=xe(C);Ct(G,n=>S=n,()=>S);var y=d(G,2),w=r(y);{let n=Z(()=>R()?()=>{}:ne),m=Z(()=>R()?()=>{}:de),H=Z(()=>R()?()=>{}:le);pr(w,{get onupload(){return e(n)},get onnewfolder(){return e(m)},get ondeleteselected(){return e(H)},get readonly(){return R()}})}var D=d(w,2),g=r(D),O=r(g);{var V=n=>{var m=Ur(),H=r(m);nr(H,{size:24,class:"animate-spin text-muted-foreground"}),t(m),_(n,m)},ce=n=>{var m=Cr(),H=r(m),fe=r(H);ht(fe,{size:24,class:"text-muted-foreground"}),t(H);var we=d(H,2),ue=r(we),Ae=r(ue,!0);t(ue);var oe=d(ue,2),_e=r(oe,!0);t(oe),t(we);var ve=d(we,2);{var pe=Me=>{var he=Pr(),se=r(he);et(se,{size:14});var Oe=d(se);t(he),X(f=>h(Oe,` ${f??""}`),[()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_MANAGER.UPLOAD_FILES")]),L("click",he,ne),_(Me,he)};P(ve,Me=>{u.isSearching||Me(pe)})}t(m),X(()=>{h(Ae,u.isSearching?"No results found":"This folder is empty"),h(_e,u.isSearching?"Try a different search term":"Drop files here or click Upload to get started")}),_(n,m)},ye=n=>{Er(n)},Te=n=>{Ir(n,{})};P(O,n=>{u.loading?n(V):e(ee)?u.viewMode==="grid"?n(ye,2):n(Te,-1):n(ce,1)})}var Ne=d(O,2);{var Xe=n=>{var m=Wr(),H=r(m);Le(H,21,()=>[...e(E)],Ye,(fe,we)=>{var ue=Z(()=>It(e(we),2));let Ae=()=>e(ue)[0],oe=()=>e(ue)[1];var _e=Xr(),ve=r(_e),pe=r(ve),Me=r(pe,!0);t(pe);var he=d(pe,2),se=r(he);t(he),t(ve);var Oe=d(ve,2),f=r(Oe);let k;t(Oe),t(_e),X(te=>{h(Me,te),h(se,`${oe()??""}%`),k=Pt(f,"",k,{width:`${oe()??""}%`})},[()=>s?.getFile(Ae())?.name??"Uploading..."]),_(fe,_e)}),t(H),t(m),_(n,m)};P(Ne,n=>{e(M)&&e(E).size>0&&n(Xe)})}t(g);var ze=d(g,2);{var Ke=n=>{var m=jr(),H=r(m);Rr(H,{get file(){return u.inspectedFile},ondelete:ie}),t(m),_(n,m)};P(ze,n=>{u.inspectedFile&&n(Ke)})}var ge=d(ze,2);{var Ee=n=>{var m=Kr(),H=r(m),fe=r(H);et(fe,{size:32,class:"text-primary"});var we=d(fe,2),ue=d(r(we));{var Ae=oe=>{var _e=Br(),ve=d(xe(_e)),pe=r(ve,!0);t(ve),X(()=>h(pe,u.currentPath)),_(oe,_e)};P(ue,oe=>{u.currentPath&&oe(Ae)})}t(we),t(H),t(m),_(n,m)};P(ge,n=>{e(A)&&n(Ee)})}t(D),t(y);var Fe=d(y,2);{let n=Z(()=>j.t("ADMIN_NEXT.DELETE"));Ht(Fe,{get open(){return e(x)},get title(){return e(n)},get message(){return e(Q)},confirmLabel:"Delete",variant:"destructive",onconfirm:b,oncancel:()=>o(x,!1)})}var We=d(Fe,2);{var Ge=n=>{var m=Gr(),H=r(m),fe=r(H),we=r(fe,!0);t(fe);var ue=d(fe,2),Ae=r(ue,!0);t(ue);var oe=d(ue,2);tt(oe);var _e=d(oe,2),ve=r(_e),pe=r(ve,!0);t(ve);var Me=d(ve,2),he=r(Me,!0);t(Me),t(_e),t(H),t(m),X((se,Oe,f,k,te)=>{h(we,se),h(Ae,u.currentPath?`Create in ${u.currentPath}/`:"Create in root"),me(oe,"placeholder",Oe),h(pe,f),Me.disabled=k,h(he,te)},[()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_MANAGER.NEW_FOLDER"),()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_MANAGER.FOLDER_NAME"),()=>j.t("ADMIN_NEXT.CANCEL"),()=>!e(z).trim(),()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_MANAGER.CREATE")]),L("click",m,se=>{se.target===se.currentTarget&&o(W,!1)}),L("keydown",oe,se=>{se.key==="Enter"&&q(),se.key==="Escape"&&o(W,!1)}),_t(oe,()=>e(z),se=>o(z,se)),L("click",ve,()=>o(W,!1)),L("click",Me,q),_(n,m)};P(We,n=>{e(W)&&n(Ge)})}L("change",G,re),je("dragenter",D,function(...n){(R()?void 0:v)?.apply(this,n)}),je("dragleave",D,function(...n){(R()?void 0:p)?.apply(this,n)}),je("dragover",D,function(...n){(R()?void 0:K)?.apply(this,n)}),je("drop",D,function(...n){(R()?void 0:U)?.apply(this,n)}),_($,C),Ce()}Be(["change","click","keydown"]);var Qr=T('<p class="mt-0.5 text-xs text-muted-foreground"> </p>'),qr=T("<div><div><div><h1>Media</h1> <!></div></div></div>"),Yr=T('<div class="flex h-full flex-col"><!> <div class="flex-1 overflow-hidden"><!></div></div>');function Sa($,i){Pe(i,!0);const R=Z(()=>or("media"));var M=Yr();St("14bqwv7",x=>{Tt(B=>{Ft.title=B??""},[()=>j.t("ADMIN_NEXT.MEDIA.MEDIA_GRAV_ADMIN")])});var E=r(M);ir(E,{noBorder:!0,children:(B,Q)=>{let N=()=>Q?.().scrolled;var W=qr(),z=r(W),S=r(z),s=r(S),c=d(s,2);{var F=a=>{var l=Qr(),v=r(l,!0);t(l),X(p=>h(v,p),[()=>j.t("ADMIN_NEXT.MEDIA.MANAGE_SITE_WIDE_MEDIA_FILES")]),_(a,l)};P(c,a=>{N()||a(F)})}t(S),t(z),t(W),X(()=>{ae(W,1,`px-6 transition-[padding] duration-200 ${N()?"py-2":"pt-6 pb-3"}`),ae(z,1,`flex items-center justify-between ${N()?"min-h-6":"min-h-8"}`),ae(s,1,`font-semibold tracking-tight text-foreground transition-[font-size] duration-200 ${N()?"text-sm":"text-xl"}`)}),_(B,W)},$$slots:{default:!0}});var A=d(E,2),I=r(A);{let x=Z(()=>!e(R));Hr(I,{get readonly(){return e(x)}})}t(A),t(M),_($,M),Ce()}export{Sa as component};
|