const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["ConfigureTheView-BJhIOZyn.js","strapi-ye6TfKul.js","strapi-D6821bIJ.css"])))=>i.map(i=>d[i]);
import{iv as v,iG as ge,iO as Be,hT as $e,iE as Pe,gp as O,f1 as r,fH as e,bU as S,cz as D,c3 as ze,bw as Ve,aI as Oe,ck as E,ha as it,gt as Ee,eA as ot,gH as y,bN as lt,aD as ae,s as dt,U as rt,jF as ct,eS as ut,cI as P,cQ as Te,cf as Ie,jD as M,iD as Qe,iR as ht,dx as se,gZ as N,dN as We,K as Ne,g1 as u,d2 as Ge,a4 as pt,eC as gt,bh as Y,n as Q,o as ft,cH as xt,W as J,hd as mt,b1 as jt,ey as yt,ee as Ct,je as bt,iZ as He,j as At,jG as T,G as vt,hX as Mt,c7 as qe,hh as wt,iV as St,eU as G,hq as kt,hY as Et,ah as Tt,ap as It,ao as Ft,cd as Lt,g6 as _t,fr as Ut,aS as Rt,a8 as Dt,cV as Bt,gX as pe,iP as ne,dR as Fe,fE as $t,ae as Pt,em as Le,ad as zt,iB as Ze,aZ as te,cG as Vt,bn as Ot,fP as Xe,cx as Qt,u as Wt,iF as Nt,iY as Gt,iJ as Ht,hm as qt,hZ as Zt,e1 as Xt,hW as Kt,iT as Yt,bL as z,a$ as Jt,hc as es,d as ts,fL as ss,jn as ee,cg as as,cr as ns,am as is,aj as os,ak as ls,al as ds,dI as rs,jB as cs,m as us,bM as he,cC as hs,a6 as ps,a5 as gs,fR as fs,ht as xs,c6 as ms,c5 as _e,d5 as js}from"./strapi-ye6TfKul.js";import{S as ys}from"./SearchInput-BQCQgGkW.js";const Cs=()=>{const{formatMessage:t}=v(),{toggleNotification:a}=ge(),n=Be(),{post:s}=$e(),i=Pe(({updates:p})=>s("/upload/actions/bulk-update",{updates:p}),{onSuccess(p){const{data:x}=p;x&&x.length>0&&(n.refetchQueries([O,"assets"],{active:!0}),n.refetchQueries([O,"asset-count"],{active:!0}),n.refetchQueries([O,"folders"],{active:!0})),a({type:"success",message:t({id:r("modal.edit.success-label"),defaultMessage:"Files have been successfully updated."})})}});return{...i,edit:p=>i.mutateAsync({updates:p})}},Ke=M(mt)`
  opacity: 0;
  z-index: 1;

  &:focus-within {
    opacity: 1;
  }
`,bs=M(S)`
  background: ${({theme:t})=>t.colors.neutral0};
  border: 1px solid ${({theme:t})=>t.colors.neutral150};
  border-radius: ${({theme:t})=>t.borderRadius};

  &:hover {
    ${Ke} {
      opacity: 1;
    }
  }
`,As=({asset:t})=>{const{formatMessage:a}=v(),n=W("AssetCardActions",o=>o.dispatch),s=W("AssetCardActions",o=>o.state),l=W("AssetCardActions",o=>o.onClose),{canUpdate:i,canCopyLink:c,canDownload:p}=Qe(),[x,g]=y.useState(!1),{removeAsset:j}=ht(()=>{}),f=async o=>{o?.preventDefault(),await j(t.id),n({type:"remove_uploaded_asset",payload:{id:t.id}}),s.uploadedAssets.length===1&&l()},m=o=>{o.stopPropagation()},A=o=>{o&&(n({type:"edit_uploaded_asset",payload:{editedAsset:o}}),g(!1))};return e.jsxs(Ke,{onClick:m,position:"end",children:[e.jsxs(se.Root,{children:[e.jsx(se.Trigger,{children:e.jsx(N,{label:a({id:r("control-card.remove-selection"),defaultMessage:"Remove from selection"}),children:e.jsx(We,{})})}),e.jsx(Ne,{onConfirm:f})]}),e.jsxs(u.Root,{open:x,onOpenChange:g,children:[e.jsx(u.Trigger,{children:e.jsx(N,{label:a({id:r("control-card.edit"),defaultMessage:"Edit"}),children:e.jsx(Ge,{})})}),e.jsx(u.Content,{children:e.jsx(pt,{asset:{...t,isLocal:!1,folder:typeof t.folder=="number"?{id:t.folder}:t.folder},onClose:o=>A(o),canUpdate:i,canCopyLink:c,canDownload:p,omitFields:["caption","alternativeText"],omitActions:["replace"]})})]})]})},vs=M.span`
  text-transform: uppercase;
`,Ms=M(S)`
  position: relative;
  height: 100%;
  overflow: hidden;

  canvas,
  video {
    display: block;
    pointer-events: none;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: ${({theme:t})=>t.borderRadius};
  }
`,ws=M(jt)`
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
`,Ss=M(S)`
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;

  canvas,
  audio {
    display: block;
    max-width: 100%;
    max-height: 100%;
  }
`,ks=({assetType:t,thumbnailUrl:a,assetUrl:n,asset:s})=>{const[l,i]=y.useState(),c=l?gt(l):void 0;switch(t){case Q.Image:return e.jsx(Y,{src:a,size:"S",alt:s.alternativeText||s.name});case Q.Video:return e.jsx(Y,{size:"S",children:e.jsxs(Ms,{children:[e.jsx(xt,{url:n,mime:s.mime||"video/mp4",onLoadDuration:i,alt:s.alternativeText||s.name}),c&&e.jsx(ws,{children:c})]})});case Q.Audio:return e.jsx(Y,{size:"S",children:e.jsx(Ss,{children:e.jsx(ft,{url:n,alt:s.alternativeText||s.name})})});default:return e.jsx(Y,{src:a,size:"S",alt:s.alternativeText||s.name})}},Es=M(Ve)`
  display: flex;
  padding: ${({theme:t})=>t.spaces[2]} ${({theme:t})=>t.spaces[1]};
`,Ts=M(ze)`
  width: 100%;
  height: 100%;
  border: none;
  box-shadow: none;
  border-radius: 0;
  padding: 0;
`,Is=t=>{switch(t){case Q.Image:return{id:r("settings.section.image.label"),defaultMessage:"IMAGE"};case Q.Video:return{id:r("settings.section.video.label"),defaultMessage:"VIDEO"};case Q.Audio:return{id:r("settings.section.audio.label"),defaultMessage:"AUDIO"};case J.Pdf:return{id:r("settings.section.pdf.label"),defaultMessage:"PDF"};case J.Csv:return{id:r("settings.section.csv.label"),defaultMessage:"CSV"};case J.Xls:return{id:r("settings.section.xls.label"),defaultMessage:"XLS"};case J.Zip:return{id:r("settings.section.zip.label"),defaultMessage:"ZIP"};default:return{id:r("settings.section.doc.label"),defaultMessage:"DOC"}}},Fs=({asset:t,onCaptionChange:a,onAltTextChange:n,wasAltTextChanged:s,wasCaptionChanged:l})=>{const{formatMessage:i}=v(),c=it(t.mime||""),p=Ee(t?.formats?.thumbnail?.url||t.url)||"",x=Ee(t.url)||"",g=t.height&&t.width?` - ${t.width}x${t.height}`:"",j=t.size?ot(t.size):"",f=`${g}${g&&j?" - ":""}${j}`,[m,A]=y.useState(t.caption||"");y.useEffect(()=>{a(m)},[m,a]);const[o,L]=y.useState(t.alternativeText||"");return y.useEffect(()=>{n(o)},[o,n]),e.jsx(bs,{children:e.jsxs(D.Root,{children:[e.jsx(D.Item,{m:5,xs:12,alignItems:"stretch",children:e.jsxs(Ts,{width:"100%",height:"100%",shadow:"none",borderRadius:0,padding:0,children:[e.jsxs(lt,{style:{borderStyle:"none"},children:[e.jsx(As,{asset:t}),e.jsx(ks,{assetType:c,thumbnailUrl:p,assetUrl:x,asset:t})]}),e.jsx(Es,{children:e.jsxs(Oe,{width:"100%",children:[e.jsxs(E,{justifyContent:"space-between",alignItems:"start",children:[e.jsx(ae,{tag:"h2",children:e.jsx(dt,{tag:"span",children:t.name})}),e.jsx(rt,{children:i(Is(c))})]}),e.jsx(E,{children:e.jsxs(ct,{children:[e.jsx(vs,{children:ut(t.ext)}),f]})})]})})]})}),e.jsx(D.Item,{m:7,xs:12,flex:1,children:e.jsxs(E,{direction:"column",height:"100%",alignItems:"stretch",flex:1,padding:4,gap:2,children:[e.jsxs(P.Root,{name:"caption",children:[e.jsx(E,{alignItems:"center",gap:2,children:e.jsx(P.Label,{children:i({id:r("form.input.label.file-caption"),defaultMessage:"Caption"})})}),e.jsx(Te,{value:m,onChange:k=>A(k.target.value),placeholder:i({id:r("form.input.placeholder.file-caption"),defaultMessage:"Enter caption"}),endAction:!l&&t.caption&&e.jsx(Ie,{width:"16px",height:"16px",fill:"#AC73E6"}),type:"text"})]}),e.jsxs(P.Root,{name:"alternativeText",hint:i({id:r("form.input.description.file-alt"),defaultMessage:"This text will be displayed if the asset can't be shown."}),children:[e.jsx(E,{alignItems:"center",gap:2,children:e.jsx(P.Label,{children:i({id:r("form.input.label.file-alt"),defaultMessage:"Alternative text"})})}),e.jsx(Te,{value:o,onChange:k=>L(k.target.value),placeholder:i({id:r("form.input.placeholder.file-alt"),defaultMessage:"Enter alternative text"}),endAction:!s&&t.alternativeText&&e.jsx(Ie,{width:"16px",height:"16px",fill:"#AC73E6"}),type:"text"}),e.jsx(P.Hint,{})]})]})})]})})},R=M(S)`
  background: linear-gradient(
    90deg,
    ${({theme:t})=>t.colors.neutral100} 25%,
    ${({theme:t})=>t.colors.neutral150} 50%,
    ${({theme:t})=>t.colors.neutral100} 75%
  );
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: ${({theme:t})=>t.borderRadius};
  width: ${({width:t})=>t||"100%"};
  height: ${({height:t})=>t||"1rem"};

  @keyframes loading {
    0% {
      background-position: 200% 0;
    }
    100% {
      background-position: -200% 0;
    }
  }
`,Ls=({count:t=1})=>Array.from({length:t},(n,s)=>s).map(n=>e.jsx(S,{background:"neutral0",borderColor:"neutral150",borderStyle:"solid",borderWidth:"1px",borderRadius:"4px",marginBottom:4,children:e.jsxs(D.Root,{children:[e.jsx(D.Item,{col:5,alignItems:"stretch",children:e.jsxs(ze,{height:"100%",width:"100%",borderStyle:"none",shadow:"none",borderRadius:0,padding:2,children:[e.jsx(S,{height:"150px",padding:2,children:e.jsx(R,{height:"100%"})}),e.jsx(Ve,{style:{display:"flex",padding:"8px 4px"},children:e.jsxs(Oe,{width:"100%",children:[e.jsxs(E,{justifyContent:"space-between",alignItems:"start",marginBottom:1,children:[e.jsx(R,{width:"60%",height:"18px"}),e.jsx(R,{width:"40px",height:"16px"})]}),e.jsx(R,{width:"80%",height:"14px"})]})})]})}),e.jsx(D.Item,{m:7,xs:12,flex:1,children:e.jsxs(E,{direction:"column",height:"100%",alignItems:"stretch",flex:1,padding:4,gap:2,children:[e.jsxs(S,{children:[e.jsx(R,{width:"60px",height:"16px",marginBottom:1}),e.jsx(R,{height:"32px"})]}),e.jsxs(S,{children:[e.jsx(R,{width:"100px",height:"16px",marginBottom:1}),e.jsx(R,{height:"32px"}),e.jsx(S,{marginTop:1,children:e.jsx(R,{width:"70%",height:"12px"})})]})]})})]})},n)),Ue=M(u.Body)`
  padding: 0;
  display: flex;
  justify-content: center;

  [data-radix-scroll-area-viewport] {
    padding-top: ${({theme:t})=>t.spaces[6]};
    padding-bottom: ${({theme:t})=>t.spaces[6]};
    padding-left: ${({theme:t})=>t.spaces[7]};
    padding-right: ${({theme:t})=>t.spaces[7]};
  }
`,_s=M(vt)`
  & > button {
    display: none;
  }
`,Us=({onClose:t})=>{const{formatMessage:a}=v(),{toggleNotification:n}=ge(),s=W("ModalContent",h=>h.state),l=W("ModalContent",h=>h.dispatch),i=W("ModalContent",h=>h.folderId),{upload:c}=bt(),{edit:p,isLoading:x}=Cs(),[g,j]=y.useState(!1),[f,m]=y.useState(null),{trackUsage:A}=He(),o=(h,b)=>{l({type:"set_uploaded_asset_caption",payload:{id:h,caption:b}})},L=(h,b)=>{l({type:"set_uploaded_asset_alt_text",payload:{id:h,altText:b}})},k=()=>{l({type:"set_uploaded_assets",payload:[]})},H=async()=>{if(s.hasUnsavedChanges){const h=s.uploadedAssets.filter(b=>(b.wasCaptionChanged||b.wasAltTextChanged)&&b.file.id);if(h.length>0){h.some(C=>C.wasCaptionChanged)&&A("didEditAICaption"),h.some(C=>C.wasAltTextChanged)&&A("didEditAIAlternativeText");const b=h.map(C=>({id:C.file.id,fileInfo:{name:C.file.name,alternativeText:C.file.alternativeText??null,caption:C.file.caption??null,folder:typeof C.file.folder=="object"&&C.file.folder!==null?C.file.folder.id:C.file.folder}}));try{await p(b),l({type:"clear_unsaved_changes"})}catch(C){n({type:"danger",message:(C instanceof Error?C.message:null)||a({id:"notification.error",defaultMessage:"An error occurred"})});return}}}k(),t()},q=()=>{k(),t()},_=async h=>{l({type:"set_assets_to_upload_length",payload:h.length}),m(null),j(!0);try{const b=h.map(B=>({...B,id:B.id?Number(B.id):void 0})),$=(await c(b,i)).map(B=>({...B,folder:i||B.folder}));l({type:"set_uploaded_assets",payload:$})}catch(b){console.error("Upload failed:",b),m(b instanceof Error?b:new Error("Upload failed"))}finally{j(!1)}};if(s.assetsToUploadLength===0)return e.jsx(u.Content,{children:e.jsx(At,{onClose:t,onAddAsset:_})});if(g||s.assetsToUploadLength>0&&s.uploadedAssets.length===0&&!f)return e.jsxs(u.Content,{children:[e.jsx(u.Header,{children:e.jsx(u.Title,{children:a({id:r("ai.modal.uploading.title"),defaultMessage:"Uploading and processing with AI..."})})}),e.jsx(Ue,{children:e.jsx(Ls,{count:s.assetsToUploadLength})})]});const w=a({id:r("ai.modal.title"),defaultMessage:"{count, plural, one {# asset uploaded} other {# assets uploaded}}, review AI generated metadata"},{count:s.uploadedAssets.length});return f?e.jsxs(u.Content,{children:[e.jsx(u.Header,{children:e.jsx(u.Title,{children:w})}),e.jsx(u.Body,{children:e.jsx(_s,{closeLabel:"",variant:"danger",children:a({id:r("ai.modal.error"),defaultMessage:"Could not generate AI metadata for the uploaded files."})})}),e.jsxs(u.Footer,{children:[e.jsx(T,{onClick:q,variant:"tertiary",children:a({id:"cancel",defaultMessage:"Cancel"})}),e.jsx(T,{onClick:H,loading:x,children:a({id:"global.finish",defaultMessage:"Finish"})})]})]}):e.jsxs(u.Content,{children:[e.jsx(u.Header,{children:e.jsx(u.Title,{children:w})}),e.jsx(Ue,{children:e.jsx(E,{gap:6,direction:"column",alignItems:"stretch",children:s.uploadedAssets.map(({file:h,wasCaptionChanged:b,wasAltTextChanged:C})=>e.jsx(Fs,{asset:h,onCaptionChange:$=>h.id&&o(h.id,$),onAltTextChange:$=>h.id&&L(h.id,$),wasCaptionChanged:b,wasAltTextChanged:C},h.id))})}),e.jsxs(u.Footer,{children:[e.jsx(T,{onClick:q,variant:"tertiary",children:a({id:"cancel",defaultMessage:"Cancel"})}),e.jsx(T,{onClick:H,loading:x,children:a({id:"global.finish",defaultMessage:"Finish"})})]})]})},[Rs,W]=Ct("AIUploadModalContext"),Ds=(t,a)=>yt(t,n=>{if(a.type==="set_uploaded_assets"&&(n.uploadedAssets=a.payload.map(s=>({file:s,wasCaptionChanged:!1,wasAltTextChanged:!1})),n.hasUnsavedChanges=!1),a.type==="set_assets_to_upload_length"&&(n.assetsToUploadLength=a.payload),a.type==="set_uploaded_asset_caption"){const s=n.uploadedAssets.find(l=>l.file.id===a.payload.id);s&&s.file.caption!==a.payload.caption&&(s.file.caption=a.payload.caption,s.wasCaptionChanged=!0,n.hasUnsavedChanges=!0)}if(a.type==="set_uploaded_asset_alt_text"){const s=n.uploadedAssets.find(l=>l.file.id===a.payload.id);s&&s.file.alternativeText!==a.payload.altText&&(s.file.alternativeText=a.payload.altText,s.wasAltTextChanged=!0,n.hasUnsavedChanges=!0)}if(a.type==="remove_uploaded_asset"&&(n.uploadedAssets=n.uploadedAssets.filter(s=>s.file.id!==a.payload.id)),a.type==="edit_uploaded_asset"){const s=n.uploadedAssets.findIndex(l=>l.file.id===a.payload.editedAsset.id);s!==-1&&(n.uploadedAssets[s]={file:a.payload.editedAsset,wasCaptionChanged:n.uploadedAssets[s].wasCaptionChanged,wasAltTextChanged:n.uploadedAssets[s].wasAltTextChanged})}a.type==="clear_unsaved_changes"&&(n.hasUnsavedChanges=!1,n.uploadedAssets.forEach(s=>{s.wasCaptionChanged=!1,s.wasAltTextChanged=!1}))}),Bs=({open:t,onClose:a,folderId:n=null})=>{const[s,l]=y.useReducer(Ds,{uploadedAssets:[],assetsToUploadLength:0,hasUnsavedChanges:!1}),i=y.useCallback(()=>{l({type:"set_uploaded_assets",payload:[]}),a()},[a]);return e.jsx(Rs,{state:s,dispatch:l,folderId:n,onClose:i,children:e.jsx(u.Root,{open:t,onOpenChange:i,children:e.jsx(Us,{onClose:i})})})},$s=t=>{const{id:a}=Mt();return e.jsx(S,{position:"relative",zIndex:2,children:e.jsx(qe,{"aria-labelledby":`${a}-title`,...t})})},Ps=()=>{const t=wt(),{status:a,data:n}=St(t);return t?{status:a,isEnabled:n?.aiMetadata}:{status:"success",isEnabled:!1}},zs=(t,{pathname:a,query:n})=>{const s=[{id:null,label:{id:r("plugin.name"),defaultMessage:"Media Library"},href:t?G(a,n||{}):void 0}];return t?.parent&&typeof t?.parent!="number"&&t?.parent?.parent&&s.push([]),t?.parent&&typeof t.parent!="number"&&s.push({id:t.parent.id,label:t.parent.name,href:G(a,n||{},{folder:t.parent.id?.toString(),folderPath:t.parent.path})}),t&&s.push({id:t.id,label:t.name}),s},Vs=({selected:t,onSuccess:a})=>{const{formatMessage:n}=v(),{remove:s}=kt(),l=async()=>{await s(t),a()};return e.jsxs(se.Root,{children:[e.jsx(se.Trigger,{children:e.jsx(T,{variant:"danger-light",size:"S",startIcon:e.jsx(We,{}),children:n({id:"global.delete",defaultMessage:"Delete"})})}),e.jsx(Ne,{onConfirm:l})]})},Os=()=>{const{formatMessage:t}=v(),{toggleNotification:a}=ge(),n=Be(),{post:s}=$e(),i=Pe(({destinationFolderId:p,filesAndFolders:x})=>{const g=x.reduce((j,f)=>{const{id:m,type:A}=f,o=A==="asset"?"fileIds":"folderIds";return j[o]||(j[o]=[]),j[o].push(m),j},{});return s("/upload/actions/bulk-move",{...g,destinationFolderId:p})},{onSuccess(p){const{data:{data:x}}=p;x?.files?.length>0&&(n.refetchQueries([O,"assets"],{active:!0}),n.refetchQueries([O,"asset-count"],{active:!0})),n.refetchQueries([O,"folders"],{active:!0}),a({type:"success",message:t({id:r("modal.move.success-label"),defaultMessage:"Elements have been moved successfully."})})}});return{...i,move:(p,x)=>i.mutateAsync({destinationFolderId:p,filesAndFolders:x})}},Qs=({onClose:t,selected:a=[],currentFolder:n})=>{const{formatMessage:s}=v(),{data:l,isLoading:i}=Et(),{move:c}=Os();if(!l)return null;const p=async(g,{setErrors:j})=>{try{if(typeof g.destination!="string"){const f=g.destination.value;await c(f,a),t()}}catch(f){const m=_t(f);if(m&&"errors"in m){const A=m.errors?.reduce((o,L)=>(o[L.values?.path?.length||"destination"]=L.defaultMessage,o),{});Ut(A)||j(A)}}};if(i)return e.jsx(u.Content,{children:e.jsx(u.Body,{children:e.jsx(E,{justifyContent:"center",paddingTop:4,paddingBottom:4,children:e.jsx(Tt,{children:s({id:r("content.isLoading"),defaultMessage:"Content is loading."})})})})});const x={destination:{value:n?.id||"",label:n?.name||l[0].label}};return e.jsx(u.Content,{children:e.jsx(It,{validateOnChange:!1,onSubmit:p,initialValues:x,children:({values:g,errors:j,setFieldValue:f})=>e.jsxs(Ft,{noValidate:!0,children:[e.jsx(u.Header,{children:e.jsx(u.Title,{children:s({id:r("modal.folder.move.title"),defaultMessage:"Move elements to"})})}),e.jsx(u.Body,{children:e.jsx(D.Root,{gap:4,children:e.jsx(D.Item,{xs:12,direction:"column",alignItems:"stretch",children:e.jsxs(P.Root,{id:"folder-destination",children:[e.jsx(P.Label,{children:s({id:r("form.input.label.folder-location"),defaultMessage:"Location"})}),e.jsx(Lt,{options:l,onChange:m=>{f("destination",m)},defaultValue:typeof g.destination!="string"?g.destination:void 0,name:"destination",menuPortalTarget:document.querySelector("body"),inputId:"folder-destination",error:j?.destination,ariaErrorMessage:"destination-error"}),j.destination&&e.jsx(ae,{variant:"pi",tag:"p",textColor:"danger600",children:j.destination})]})})})}),e.jsxs(u.Footer,{children:[e.jsx(u.Close,{children:e.jsx(T,{variant:"tertiary",name:"cancel",children:s({id:"global.cancel",defaultMessage:"Cancel"})})}),e.jsx(T,{type:"submit",loading:i,children:s({id:"global.move",defaultMessage:"Move"})})]})]})})})},Ws=({selected:t=[],onSuccess:a,currentFolder:n})=>{const{formatMessage:s}=v(),[l,i]=y.useState(!1),c=()=>{i(!1),a()};return e.jsxs(u.Root,{open:l,onOpenChange:i,children:[e.jsx(u.Trigger,{children:e.jsx(T,{variant:"secondary",size:"S",startIcon:e.jsx(Rt,{}),children:s({id:"global.move",defaultMessage:"Move"})})}),e.jsx(Qs,{currentFolder:n,onClose:c,selected:t})]})},Ns=({selected:t=[],onSuccess:a,currentFolder:n})=>{const{formatMessage:s}=v(),l=t?.reduce(function(i,c){return c?.type==="folder"&&"files"in c&&c?.files&&"count"in c.files?i+c?.files?.count:i+1},0);return e.jsxs(E,{gap:2,paddingBottom:5,children:[e.jsx(ae,{variant:"epsilon",textColor:"neutral600",children:s({id:r("list.assets.selected"),defaultMessage:"{numberFolders, plural, one {1 folder} other {# folders}} - {numberAssets, plural, one {1 asset} other {# assets}} selected"},{numberFolders:t?.filter(({type:i})=>i==="folder").length,numberAssets:l})}),e.jsx(Vs,{selected:t,onSuccess:a}),e.jsx(Ws,{currentFolder:n,selected:t,onSuccess:a})]})},Gs=({isFiltering:t,canCreate:a,canRead:n})=>t?{id:"list.assets-empty.title-withSearch",defaultMessage:"There are no elements with the applied filters"}:n?a?{id:"list.assets.empty-upload",defaultMessage:"Upload your first assets..."}:{id:"list.assets.empty",defaultMessage:"Media Library is empty"}:{id:"header.actions.no-permissions",defaultMessage:"No permissions to view"},Hs=({canCreate:t,isFiltering:a,canRead:n,onActionClick:s})=>{const{formatMessage:l}=v(),i=Gs({isFiltering:a,canCreate:t,canRead:n});return e.jsx(Dt,{icon:n?void 0:Bt,action:t&&!a&&e.jsx(T,{variant:"secondary",startIcon:e.jsx(pe,{}),onClick:s,children:l({id:r("header.actions.add-assets"),defaultMessage:"Add new assets"})}),content:l({...i,id:r(i.id)})})},qs=()=>{const[t,a]=y.useState(!1),{formatMessage:n}=v(),{trackUsage:s}=He(),[{query:l},i]=ne(),c=l?.filters?.$and||[],p=g=>{i({filters:{$and:g},page:1})},x=g=>{s("didFilterMediaLibraryElements",{location:"content-manager",filter:Object.keys(g[g.length-1])[0]}),i({filters:{$and:g},page:1})};return e.jsxs(Fe.Root,{open:t,onOpenChange:a,children:[e.jsx(Fe.Trigger,{children:e.jsx(T,{variant:"tertiary",startIcon:e.jsx($t,{}),size:"S",children:n({id:"app.utils.filters",defaultMessage:"Filters"})})}),e.jsx(Pt,{displayedFilters:Le,filters:c,onSubmit:x,onToggle:a}),e.jsx(zt,{appliedFilters:c,filtersSchema:Le,onRemoveFilter:p})]})},Zs=({breadcrumbs:t=null,canCreate:a,folder:n=null,onToggleEditFolderDialog:s,onToggleUploadAssetDialog:l})=>{const{formatMessage:i}=v(),{pathname:c}=Ze(),[{query:p}]=ne(),x={...p,folder:n?.parent&&typeof n.parent!="number"&&n.parent.id?n.parent.id:void 0,folderPath:n?.parent&&typeof n.parent!="number"&&n.parent.path?n.parent.path:void 0};return e.jsx(te.Header,{title:i({id:r("plugin.name"),defaultMessage:"Media Library"}),subtitle:t&&typeof t!="boolean"&&n&&e.jsx(Wt,{label:i({id:r("header.breadcrumbs.nav.label"),defaultMessage:"Folders navigation"}),breadcrumbs:t,currentFolderId:n?.id}),navigationAction:n&&e.jsx(Vt,{tag:Ot,startIcon:e.jsx(Qt,{}),to:`${c}?${Xe.stringify(x,{encode:!1})}`,children:i({id:r("header.actions.folder-level-up"),defaultMessage:"Back"})}),primaryAction:a&&e.jsxs(E,{gap:2,width:"100%",children:[e.jsx(T,{startIcon:e.jsx(pe,{}),variant:"secondary",onClick:s,fullWidth:!0,children:i({id:r("header.actions.add-folder"),defaultMessage:"Add new folder"})}),e.jsx(T,{startIcon:e.jsx(pe,{}),onClick:l,fullWidth:!0,children:i({id:r("header.actions.add-assets"),defaultMessage:"Add new assets"})})]})})},Xs=M(S)`
  height: 3.2rem;
  display: flex;
  align-items: center;
`,Re=M(ae)`
  max-width: 100%;
`,De=M(S)`
  svg {
    path {
      fill: ${({theme:t})=>t.colors.neutral500};
    }
  }
`,Ks=()=>{const t=Nt(),{canRead:a,canCreate:n,canUpdate:s,canCopyLink:l,canDownload:i,canConfigureView:c,isLoading:p}=Qe(),{isEnabled:x,status:g}=Ps(),j=y.useRef(),{formatMessage:f}=v(),{pathname:m}=Ze(),{trackUsage:A}=Gt(),[{query:o},L]=ne(),k=!!(o._q||o.filters),[H,q]=Ht(fs.view,ee.GRID),_=H===ee.GRID,{data:w,isLoading:h,error:b}=qt({skipWhen:!a,query:o}),{data:C,isLoading:$,error:B}=Zt({enabled:a&&w?.pagination?.page===1&&!Xt(o),query:o}),{data:ie,isLoading:fe,error:Ye}=Kt(o?.folder,{enabled:a&&!!o?.folder});Ye?.name==="NotFoundError"&&t(m);const Z=C?.map(d=>({...d,type:"folder",folderURL:G(m,o,{folder:d.id.toString(),folderPath:d.path}),isSelectable:s}))??[],I=Z?.length||0,X=w?.results?.map(d=>({...d,type:"asset",isSelectable:s}))||[],F=X?.length??0,Je=w?.pagination?.total,et=fe||$||p||h||g==="loading",[oe,tt]=y.useState(!1),[xe,me]=y.useState(!1),[le,de]=y.useState(void 0),[re,je]=y.useState(void 0),[U,{selectOne:ce,selectAll:ye,setSelections:Ce}]=Yt(["type","id"],[]);y.useEffect(()=>{Ce([])},[o.folder,Ce]);const be=U?.length>0&&U?.length!==F+I,K=()=>tt(d=>!d),Ae=({created:d=!1}={})=>{d&&o?.page!=="1"&&L({...o,page:1}),me(V=>!V)},ve=(d,V)=>{d&&A("didSelectAllMediaLibraryElements"),ye(V)},Me=d=>{A("didSortMediaLibraryElements",{location:"upload",sort:d}),L({sort:d})},we=d=>{je(d),me(!0)},st=d=>{je(null),Ae(d),j.current&&j.current.focus()},Se=d=>{d===F&&w?.pagination?.page===w?.pagination?.pageCount&&w?.pagination?.page&&w.pagination.page>1&&L({...o,page:w.pagination.page-1})},at=()=>{ye(),Se(U.length)};return et?e.jsx(z.Loading,{}):b||B||g==="error"?e.jsx(z.Error,{}):e.jsxs(te.Root,{children:[e.jsxs(z.Main,{children:[e.jsx(Zs,{breadcrumbs:fe?null:zs(ie,{pathname:m,query:o}),canCreate:n,onToggleEditFolderDialog:Ae,onToggleUploadAssetDialog:K,folder:ie}),e.jsx(te.Action,{startActions:e.jsxs(e.Fragment,{children:[s&&_&&(F>0||I>0)&&e.jsx(Xs,{paddingLeft:2,paddingRight:2,background:"neutral0",hasRadius:!0,borderColor:"neutral200",children:e.jsx(qe,{"aria-label":f({id:r("bulk.select.label"),defaultMessage:"Select all folders & assets"}),checked:be?"indeterminate":(F>0||I>0)&&U.length===F+I,onCheckedChange:d=>ve(d,[...X,...Z])})}),a&&_&&e.jsx(as,{value:o?.sort,onChangeSort:Me}),a&&e.jsx(qs,{})]}),endActions:e.jsxs(e.Fragment,{children:[c?e.jsx(De,{paddingTop:1,paddingBottom:1,children:e.jsx(N,{tag:Jt,to:{pathname:`${m}/configuration`,search:Xe.stringify(o,{encode:!1})},label:f({id:"app.links.configure-view",defaultMessage:"Configure the view"}),children:e.jsx(es,{})})}):null,e.jsx(De,{paddingTop:1,paddingBottom:1,children:e.jsx(N,{label:f(_?{id:r("view-switch.list"),defaultMessage:"List View"}:{id:r("view-switch.grid"),defaultMessage:"Grid View"}),onClick:()=>q(_?ee.LIST:ee.GRID),children:_?e.jsx(ts,{}):e.jsx(ss,{})})}),e.jsx(ys,{label:f({id:r("search.label"),defaultMessage:"Search for an asset"}),trackedEvent:"didSearchMediaLibraryElements",trackedEventDetails:{location:"upload"}})]})}),e.jsxs(te.Content,{children:[U.length>0&&e.jsx(Ns,{currentFolder:ie,selected:U,onSuccess:at}),I===0&&F===0&&e.jsx(Hs,{canCreate:n,canRead:a,isFiltering:k,onActionClick:K}),a&&!_&&(F>0||I>0)&&e.jsx(ns,{assetCount:F,folderCount:I,indeterminate:be,onChangeSort:Me,onChangeFolder:(d,V)=>t(G(m,o,{folder:d.toString(),folderPath:V})),onEditAsset:de,onEditFolder:we,onSelectOne:ce,onSelectAll:ve,rows:[...Z,...X],selected:U,shouldDisableBulkSelect:!s,sortQuery:o?.sort??""}),a&&_&&e.jsxs(e.Fragment,{children:[I>0&&e.jsx(is,{title:(k&&F>0||!k)&&f({id:r("list.folders.title"),defaultMessage:"Folders ({count})"},{count:I})||"",children:Z.map(d=>{const nt=!!U.filter(({type:ue})=>ue==="folder").find(ue=>ue.id===d.id),ke=G(m,o,{folder:d?.id.toString(),folderPath:d?.path});return e.jsx(D.Item,{col:3,m:4,s:6,xs:12,direction:"column",alignItems:"stretch",children:e.jsx(os,{ref:re&&d.id===re.id?j:void 0,ariaLabel:d.name,id:`folder-${d.id}`,to:ke,startAction:d.isSelectable?e.jsx($s,{"data-testid":`folder-checkbox-${d.id}`,checked:nt,onCheckedChange:()=>ce(d)}):null,cardActions:e.jsx(N,{label:f({id:r("list.folder.edit"),defaultMessage:"Edit folder"}),onClick:()=>we(d),children:e.jsx(Ge,{})}),children:e.jsx(ls,{children:e.jsx(ds,{to:ke,children:e.jsxs(E,{tag:"h2",direction:"column",alignItems:"start",maxWidth:"100%",children:[e.jsxs(Re,{fontWeight:"semiBold",textColor:"neutral800",ellipsis:!0,children:[d.name,e.jsx(rs,{children:":"})]}),e.jsx(Re,{tag:"span",textColor:"neutral600",variant:"pi",ellipsis:!0,children:f({id:r("list.folder.subtitle"),defaultMessage:"{folderCount, plural, one {# folder} other {# folders}}, {filesCount, plural, one {# asset} other {# assets}}"},{folderCount:d.children?.count,filesCount:d.files?.count})})]})})})})},`folder-${d.id}`)})}),F>0&&I>0&&e.jsx(S,{paddingTop:6,paddingBottom:4,children:e.jsx(cs,{})}),F>0&&e.jsx(us,{assets:X,onEditAsset:de,onSelectAsset:ce,selectedAssets:U.filter(({type:d})=>d==="asset"),title:(!k||k&&I>0)&&w?.pagination?.page===1&&f({id:r("list.assets.title"),defaultMessage:"Assets ({count})"},{count:Je})||""})]}),e.jsxs(he.Root,{...w?.pagination,children:[e.jsx(he.PageSize,{}),e.jsx(he.Links,{})]})]})]}),oe&&(x?e.jsx(Bs,{open:oe,onClose:K,folderId:o?.folder?Number(o.folder):null}):e.jsx(hs,{open:oe,onClose:K,trackedLocation:"upload",folderId:o?.folder})),xe&&e.jsx(ps,{open:xe,onClose:()=>st(),folder:re,parentFolderId:o?.folder,location:"upload"}),le&&e.jsx(gs,{onClose:d=>{d===null&&Se(1),de(void 0)},open:!!le,asset:le,canUpdate:s,canCopyLink:l,canDownload:i,trackedLocation:"upload"})]})},Ys=y.lazy(async()=>js(()=>import("./ConfigureTheView-BJhIOZyn.js"),__vite__mapDeps([0,1,2])).then(t=>({default:t.ConfigureTheView}))),ta=()=>{const{config:{isLoading:t,isError:a,data:n}}=xs(),[{rawQuery:s},l]=ne(),{formatMessage:i}=v(),c=i({id:r("plugin.name"),defaultMessage:"Media Library"});return y.useEffect(()=>{t||a||s||l({sort:n.sort,page:1,pageSize:n.pageSize})},[t,a,n,s,l]),t?e.jsx(z.Loading,{}):e.jsxs(z.Main,{children:[e.jsx(z.Title,{children:c}),s?e.jsx(y.Suspense,{fallback:e.jsx(z.Loading,{}),children:e.jsxs(ms,{children:[e.jsx(_e,{index:!0,element:e.jsx(Ks,{})}),e.jsx(_e,{path:"configuration",element:e.jsx(Ys,{config:n})})]})}):null]})};export{ta as Upload};
