import{h as _,m as z,j as i,g as t,p as te,u as re,d,f as ae,s as y,r as u,t as k,a as m,b as se,k as oe,c as x}from"./qex-fw8l.js";import"./DsnmJJEf.js";import{d as ne,s as I,a as O}from"./vzbhwc8t.js";import{i as W}from"./BnUrxEZg.js";import{e as R,s as T}from"./HL7kq492.js";import{s as ie}from"./CoLYeqRS.js";import{i as S,b as D}from"./dc0o8kHW.js";import{getSiteMedia as le,encodeMediaFileUrl as ue,mediaAltText as ce,siteMediaStreamPath as de}from"./BcrkOjQV.js";import{C as fe}from"./DpMFZQsC.js";import{L as ve}from"./BnIIe8z2.js";import{I as pe}from"./CW6kszZ5.js";import{F as me}from"./Ddg03Ate.js";let g=_(z({}));const Ue={get types(){return t(g)},register(a,v,n="plugins"){for(const h of Object.keys(v))t(g)[h]={slug:a,kind:n};i(g,{...t(g)},!0)},has(a){return a in t(g)},getProvider(a){return t(g)[a]},getPluginSlug(a){return t(g)[a]?.slug},clear(){i(g,{},!0)}};let M=_(null);const q=[];let ge=1;function $(a){if(!t(M))return;const v=t(M).resolve;i(M,q.shift()??null,!0),v(a)}const We={get current(){return t(M)},open(a){return new Promise(v=>{const n={id:ge++,options:a,resolve:v};t(M)?q.push(n):i(M,n,!0)})},form(a){return this.open({...a,kind:"form"})},resolve(a){$(a)},cancel(){$(null)}};var xe=x('<!> <button type="button"> </button>',1),_e=x('<div class="flex h-[180px] items-center justify-center text-muted-foreground"><!></div>'),he=x('<div class="flex h-[180px] items-center justify-center px-4 text-center text-xs text-destructive"> </div>'),be=x('<div class="flex h-[180px] flex-col items-center justify-center gap-2 text-xs text-muted-foreground"><!> </div>'),ye=x('<button type="button" class="flex flex-col items-center justify-center gap-1 rounded-md border border-border bg-muted/30 p-3 text-center transition-colors hover:border-primary hover:bg-accent/40"><!> <span class="w-full truncate text-[0.6875rem] text-foreground"> </span></button>'),Me=x('<button type="button" class="group flex flex-col overflow-hidden rounded-md border border-border bg-muted/40 text-start transition-colors hover:border-primary hover:bg-accent/40"><span class="block aspect-square overflow-hidden bg-muted/50"><img class="h-full w-full object-cover transition-transform group-hover:scale-105" loading="lazy"/></span> <span class="truncate px-1.5 py-1 text-[0.625rem] text-muted-foreground"> </span></button>'),ke=x('<div class="grid grid-cols-3 gap-2 sm:grid-cols-4"><!> <!></div>'),Ie=x('<div class="flex flex-col gap-3"><nav class="flex flex-wrap items-center gap-0.5 text-xs text-muted-foreground"></nav> <div class="min-h-[180px]"><!></div></div>');function Se(a,v){te(v,!0);let n=_(""),h=_(z([])),w=_(z([])),N=_(!0),A=_("");re(()=>{C(t(n))});async function C(r){i(N,!0),i(A,"");try{const e=await le({path:r,type:"image",per_page:200});if(r!==t(n))return;i(h,e.folders,!0),i(w,e.items,!0)}catch(e){if(r!==t(n))return;i(h,[],!0),i(w,[],!0),i(A,e instanceof Error?e.message:"Failed to load media",!0)}finally{r===t(n)&&i(N,!1)}}const P=oe(()=>{const r=[{label:S.t("ADMIN_NEXT.MEDIA.MEDIA_MANAGER.ROOT"),path:""}];if(t(n)){let e="";for(const s of t(n).split("/"))e=e?`${e}/${s}`:s,r.push({label:s,path:e})}return r});function G(r){const e=ue(r.thumbnail_url??r.url);return e.startsWith("http")?e:e.startsWith("/")?`${D.serverUrl}${e}`:`${D.serverUrl}/${e}`}function L(r){const e=r.url;return e.startsWith("http")?e:e.startsWith("/")?`${D.serverUrl}${e}`:`${D.serverUrl}/${e}`}function X(r){i(n,r.path,!0)}function B(r){r!==t(n)&&i(n,r,!0)}function K(r){v.onpick({url:de(r),display:L(r),alt:ce(r)})}var j=Ie(),F=d(j);R(F,23,()=>t(P),r=>r.path,(r,e,s)=>{var b=xe(),c=ae(b);{var l=f=>{fe(f,{size:12,class:"opacity-50"})};W(c,f=>{t(s)>0&&f(l)})}var o=y(c,2),p=d(o,!0);u(o),k(()=>{ie(o,1,`rounded px-1 py-0.5 transition-colors hover:bg-accent hover:text-foreground ${t(s)===t(P).length-1?"font-medium text-foreground":""}`),I(p,t(e).label)}),O("click",o,()=>B(t(e).path)),m(r,b)}),u(F);var U=y(F,2),H=d(U);{var J=r=>{var e=_e(),s=d(e);ve(s,{size:20,class:"animate-spin"}),u(e),m(r,e)},Q=r=>{var e=he(),s=d(e,!0);u(e),k(()=>I(s,t(A))),m(r,e)},V=r=>{var e=be(),s=d(e);pe(s,{size:18});var b=y(s);u(e),k(c=>I(b,` ${c??""}`),[()=>S.t("ADMIN_NEXT.MARKDOWN_EDITOR.IMAGE_INSERT.NO_MEDIA")]),m(r,e)},Y=r=>{var e=ke(),s=d(e);R(s,17,()=>t(h),c=>c.path,(c,l)=>{var o=ye(),p=d(o);me(p,{size:26,class:"text-muted-foreground"});var f=y(p,2),E=d(f,!0);u(f),u(o),k(()=>{T(o,"title",t(l).name),I(E,t(l).name)}),O("click",o,()=>X(t(l))),m(c,o)});var b=y(s,2);R(b,17,()=>t(w),c=>c.filename,(c,l)=>{var o=Me(),p=d(o),f=d(p);u(p);var E=y(p,2),Z=d(E,!0);u(E),u(o),k(ee=>{T(o,"title",t(l).alt||t(l).filename),T(f,"src",ee),T(f,"alt",t(l).alt||t(l).filename),I(Z,t(l).filename)},[()=>G(t(l))]),O("click",o,()=>K(t(l))),m(c,o)}),u(e),m(r,e)};W(H,r=>{t(N)?r(J):t(A)?r(Q,1):t(h).length===0&&t(w).length===0?r(V,2):r(Y,-1)})}u(U),u(j),m(a,j),se()}ne(["click"]);export{Se as M,Ue as c,We as m};
