import{N,Q as P,e,ar as $,as as I,at as V,aO as q,av as D,aH as B,au as G,t as l,bU as w,T as m,a7 as H,a4 as R,aw as U,aS as S,P as d,bV as E,U as J,r as o,aD as K,u as Q,w as X,x as Y,M as Z,E as _,S as k,V as ee,B as te,bW as se,F as ae,A as F,G as v,J as ie,K as ne}from"./index-_6SmYgWK.js";const s=B(U)(({theme:a})=>({borderColor:a.palette.grey[900]+25,[`&.${S.head}`]:{color:a.palette.grey[900]},[`&.${S.body}`]:{fontSize:14,height:64}})),g=B(D)(()=>({"&:last-child td, &:last-child th":{border:0}})),W=({data:a,isLoading:h,filterFunction:p,handleDelete:x})=>{const c=N(),u=P(i=>i.customization);return e.jsx(e.Fragment,{children:e.jsx($,{sx:{border:1,borderColor:c.palette.grey[900]+25,borderRadius:2},component:I,children:e.jsxs(V,{sx:{minWidth:650},size:"small","aria-label":"a dense table",children:[e.jsx(q,{sx:{backgroundColor:u.isDarkMode?c.palette.common.black:c.palette.grey[100],height:56},children:e.jsxs(D,{children:[e.jsx(s,{component:"th",scope:"row",style:{width:"25%"},children:"Name"},"0"),e.jsx(s,{style:{width:"40%"},children:"Path"},"1"),e.jsx(s,{style:{width:"25%"},children:"Size"},"2"),e.jsx(s,{style:{width:"10%"},children:"Actions"},"3")]})}),e.jsx(G,{children:h?e.jsxs(e.Fragment,{children:[e.jsxs(g,{children:[e.jsx(s,{children:e.jsx(l,{variant:"text"})}),e.jsx(s,{children:e.jsx(l,{variant:"text"})}),e.jsx(s,{children:e.jsx(l,{variant:"text"})}),e.jsx(s,{children:e.jsx(l,{variant:"text"})})]}),e.jsxs(g,{children:[e.jsx(s,{children:e.jsx(l,{variant:"text"})}),e.jsx(s,{children:e.jsx(l,{variant:"text"})}),e.jsx(s,{children:e.jsx(l,{variant:"text"})}),e.jsx(s,{children:e.jsx(l,{variant:"text"})})]})]}):e.jsx(e.Fragment,{children:a==null?void 0:a.filter(p).map((i,j)=>e.jsxs(g,{children:[e.jsx(s,{children:e.jsx(w,{title:i.name,children:e.jsx(m,{sx:{display:"-webkit-box",fontSize:14,fontWeight:500,WebkitLineClamp:1,WebkitBoxOrient:"vertical",textOverflow:"ellipsis",overflow:"hidden"},children:i.name.split("/").pop()})})},"0"),e.jsx(s,{children:e.jsx(w,{title:i.path,children:e.jsx(m,{sx:{display:"-webkit-box",fontSize:14,fontWeight:500,WebkitLineClamp:1,WebkitBoxOrient:"vertical",textOverflow:"ellipsis",overflow:"hidden"},children:i.path})})},"1"),e.jsx(s,{children:e.jsx(m,{sx:{alignItems:"center",display:"flex",fontSize:".9rem",fontWeight:200},children:`${i.size.toFixed(2)} MB`})},"2"),e.jsx(s,{children:e.jsx(H,{color:"error",onClick:()=>x(i),size:"small",children:e.jsx(R,{})})},"3")]},j))})})]})})})};W.propTypes={data:d.array,images:d.object,isLoading:d.bool,filterFunction:d.func,handleDelete:d.func};const re=()=>E.get("/files"),le=a=>E.delete("/files",{params:{path:a}}),T={getAllFiles:re,deleteFile:le},de=()=>{const{confirm:a}=J(),[h,p]=o.useState(!0),{error:x,setError:c}=K(),[u,i]=o.useState([]),[j,z]=o.useState(""),n=Q(T.getAllFiles),b=X();Y();const y=(...t)=>b(ie(...t)),C=(...t)=>b(ne(...t)),L=t=>{z(t.target.value)};function A(t){return t.name.toLowerCase().indexOf(j.toLowerCase())>-1||t.category&&t.category.toLowerCase().indexOf(j.toLowerCase())>-1}const O=async t=>{const M={title:"Delete",description:`Delete ${t.name}? This process cannot be undone.`,confirmButtonName:"Delete",cancelButtonName:"Cancel"};if(await a(M))try{const r=await T.deleteFile(t.path);r!=null&&r.data&&y({message:"File deleted",options:{key:new Date().getTime()+Math.random(),variant:"success",action:f=>e.jsx(F,{style:{color:"white"},onClick:()=>C(f),children:e.jsx(v,{})})}}),await n.request()}catch(r){c(r),y({message:typeof r.response.data=="object"?r.response.data.message:r.response.data,options:{key:new Date().getTime()+Math.random(),variant:"error",persist:!0,action:f=>e.jsx(F,{style:{color:"white"},onClick:()=>C(f),children:e.jsx(v,{})})}})}};return o.useEffect(()=>{n.request()},[]),o.useEffect(()=>{p(n.loading)},[n.loading]),o.useEffect(()=>{if(n.data)try{const t=n.data;i(t)}catch(t){console.error(t)}},[n.data]),e.jsxs(Z,{children:[x?e.jsx(_,{error:x}):e.jsxs(k,{flexDirection:"column",sx:{gap:3},children:[e.jsx(ee,{onSearchChange:L,search:!0,searchPlaceholder:"Search File",title:"Files"}),e.jsx(W,{data:u,filterFunction:A,handleDelete:O,isLoading:h}),!h&&(!n.data||n.data.length===0)&&e.jsxs(k,{sx:{alignItems:"center",justifyContent:"center"},flexDirection:"column",children:[e.jsx(te,{sx:{p:2,height:"auto"},children:e.jsx("img",{style:{objectFit:"cover",height:"25vh",width:"auto"},src:se,alt:"WorkflowEmptySVG"})}),e.jsx("div",{children:"No Files Yet"})]})]}),e.jsx(ae,{})]})};export{de as default};
