1import{e as G,f as q,u as K,r as l,g as T,h as O,R as z,i as $,k as Q,j as e,B as o,l as b,m as Y,n as D,U as h,M as L,o as x}from"./index-BrT3F50e.js";import{f as J}from"./dayjs-CSchl2My.js";import{E as H,I as V,P as X}from"./EmptyState-BsaFrTWq.js";import{F as Z}from"./Table-6SzYbSzL.js";import{D as ee}from"./index-BI849doy.js";import{s as i}from"./index-DtDFBFnu.js";import"./timezoneNormalizer-l1yj-VtS.js";import"./styleChecker-CI4V7a_h.js";import"./index-DF5CAhcZ.js";import"./Overflow-BkMYm1DN.js";import"./getAllowClear-C4A34otO.js";import"./Input-DOcZa3u3.js";import"./index-BDXfpOYW.js";import"./useForm-BVKnLQxW.js";import"./LeftOutlined-C9qxU1fR.js";import"./Dropdown-DXdTgnhA.js";import"./index-Cl3KiXUs.js";import"./EllipsisOutlined-Cu-qV7Vg.js";import"./Sider-DNV35gRJ.js";import"./useBreakpoint-FD8ghq8d.js";import"./index-DDdNZ6K1.js";import"./gapSize-U1swVQyS.js";import"./Pagination-DBPbQz54.js";const{Dragger:te}=h;function ke(){const r=G(),{workspaceId:B}=q({from:"/workspace/$workspaceId/file-manager"}),{workspaces:I}=K(),v=I.find(t=>t.id===B)?.settings.timezone,[R,w]=l.useState(!1),[n,y]=l.useState(1),[d,N]=l.useState(10),[P,p]=l.useState(!1),[a,m]=l.useState({open:!1,file:null}),[C,u]=l.useState(!1),j=T(),{data:f}=O({queryKey:["files"],queryFn:()=>x.listFiles()}),M=z.useMemo(()=>(f?.files||[]).filter(t=>$(t.name)!==null).sort(Q),[f]),S=f?.total_size_mb??0,F=f?.limit??0,c=M.length,A=M.slice((n-1)*d,n*d),[g,k]=l.useState([]),E={selectedRowKeys:g,onChange:t=>{k(t)}};z.useEffect(()=>{const t=Math.max(1,Math.ceil(c/d));n>t&&y(t)},[c,d,n]);const U=async()=>{if(a.file)try{u(!0),await x.deleteFile([a.file.id]),j.invalidateQueries({queryKey:["files"]}),m({open:!1,file:null})}catch(t){console.error(t),i.error("Failed to delete file")}finally{u(!1)}},W=async t=>{try{w(!0);const s=new FormData;s.append("files",t),await x.uploadFiles(s),j.invalidateQueries({queryKey:["files"]}),p(!1),i.success(`${t.name} uploaded successfully`)}catch(s){console.error(s),i.error(`Failed to upload ${t.name}`)}finally{w(!1)}},_=async t=>{try{u(!0),await x.deleteFile(t),j.invalidateQueries({queryKey:["files"]}),k([]),i.success(`Deleted ${t.length} file(s) successfully`)}catch(s){console.error(s),i.error("Failed to delete selected files")}finally{u(!1)}};return e.jsxs("div",{className:"flex flex-col",style:{height:r?"calc(100vh - 56px)":"100vh"},children:[e.jsxs("div",{className:"flex justify-between items-center px-5 shrink-0",style:{height:"60px",backgroundColor:"#FAFAFA",borderBottom:"1px solid #EAEAEC"},children:[e.jsxs("h1",{className:"text-2xl font-semibold",style:{color:"#1C1D1F",marginBottom:0},children:["File Manager"," ",e.jsxs("span",{className:"text-sm font-normal",style:{color:"#6B7280"},children:["(",S.toFixed(2)," MB)"]})]}),e.jsx(o,{type:"primary",icon:e.jsx(b,{}),onClick:()=>p(!0),style:{backgroundColor:"#2F6DFB",borderRadius:"10px",fontWeight:700},children:"Upload Files"})]}),c===0?e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(H,{icon:e.jsx(V,{}),title:"No Files Uploaded Yet",action:e.jsx(o,{type:"primary",icon:e.jsx(b,{}),onClick:()=>p(!0),style:{backgroundColor:"#2F6DFB",borderRadius:"10px",fontWeight:700},children:"Upload Files"})})}):e.jsx("div",{className:"flex-1 overflow-auto px-5 py-6",children:e.jsxs("div",{style:{backgroundColor:"#FAFAFA",borderRadius:"20px",padding:"10px",overflow:"hidden"},children:[g.length>0&&e.jsxs(o,{danger:!0,onClick:()=>_(g),loading:C,children:["Delete selected (",g.length,")"]}),e.jsx(Z,{className:"table-no-cell-border",dataSource:A,rowKey:"id",rowClassName:(t,s)=>s%2===1?"zebra-row":"",pagination:!1,rowSelection:E,columns:[{title:"Image",key:"image",width:r?120:300,render:(t,s)=>e.jsx("img",{src:s.url,alt:s.name,loading:"lazy",style:{height:64,maxWidth:"100%",borderRadius:"8px",objectFit:"contain",background:"#F0F0F0"}})},{title:"Name",dataIndex:"name",key:"name",ellipsis:!0},{title:"Created",dataIndex:"created_at",key:"created_at",width:r?100:140,render:t=>t?J(t,v,"MMM D, YYYY"):"â"},{title:"Size",dataIndex:"size",key:"size",width:r?80:100,render:t=>Y(t,{round:0,separator:","})},{key:"actions",width:60,align:"right",render:(t,s)=>e.jsx(o,{type:"text",icon:e.jsx(D,{}),onClick:()=>m({open:!0,file:s})})}]})]})}),c>0&&e.jsx(X,{totalItems:c,currentPage:n,pageSize:d,onPageChange:y,onPageSizeChange:t=>{N(t),y(1)}}),e.jsx(ee,{title:"Upload File(s)",open:P,onClose:()=>p(!1),width:r?"100%":420,children:e.jsx(te,{multiple:!0,accept:"image/jpeg,image/png,image/bmp",showUploadList:!1,disabled:R,beforeUpload:t=>["image/jpeg","image/png","image/bmp"].includes(t.type)?t.size/1024/1024<5?F>0&&S+t.size/1024/1024>F?(i.error(`Storage limit of ${F}MB would be exceeded`),h.LIST_IGNORE):!0:(i.error("File must be under 5MB"),h.LIST_IGNORE):(i.error("Only JPEG, PNG, BMP files are allowed"),h.LIST_IGNORE),customRequest:async({file:t})=>{await W(t)},style:{borderRadius:"12px",padding:"40px 20px",border:"1.5px dashed #d9d9d9",background:"#fafafa"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:12},children:[e.jsx(b,{style:{fontSize:40,color:"#2F6DFB"}}),e.jsx("div",{style:{fontSize:15,fontWeight:500,color:"#1C1D1F"},children:"Click or drag file(s) to this area to upload"}),e.jsx("div",{style:{fontSize:13,color:"rgba(28, 29, 31, 0.5)"},children:"JPEG, PNG, BMP, under 5MB"})]})})}),e.jsx(L,{open:a.open,onCancel:()=>m({open:!1,file:null}),footer:null,centered:!0,width:480,children:e.jsxs("div",{style:{textAlign:"center",padding:"8px 0"},children:[e.jsx("h3",{style:{fontSize:20,fontWeight:600,marginBottom:16},children:"Are you sure you want to delete this file?"}),a.file&&e.jsx("img",{src:a.file.url,alt:a.file.name,style:{width:"100%",maxHeight:240,objectFit:"cover",borderRadius:"12px",marginBottom:16}}),e.jsx("p",{style:{color:"rgba(28, 29, 31, 0.6)",fontSize:14,marginBottom:24},children:"The file will be removed from the server. This action cannot be undone."}),e.jsxs("div",{style:{display:"flex",gap:12,justifyContent:"center"},children:[e.jsx(o,{size:"large",onClick:()=>m({open:!1,file:null}),style:{borderRadius:"10px",minWidth:120,fontWeight:600},children:"Cancel"}),e.jsx(o,{size:"large",danger:!0,type:"primary",icon:e.jsx(D,{}),loading:C,onClick:U,style:{borderRadius:"10px",minWidth:120,fontWeight:600},children:"Delete"})]})]})})]})}export{ke as FileManagerPage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.