import{at as E,r as h,j as l,b as o,F as T,an as B,bl as N,R as C,ag as $,bX as S,D as A,f as I,g as z,q as D,v as O,x as j,y as s,w as U,z as _,A as F,i as L,B as H,av as M,ar as n}from"./index-ktJf6c6X.js";import{d as W}from"./CloudDownload-DzHhu5_h.js";const q=`${M}/erp-crm/v1`,Q=({modulePath:m,fileBaseName:p,criteria:u,onImported:V,canExport:R=!0,canImport:X=!0})=>{const b=E(a=>{var r,d;return(d=(r=a==null?void 0:a.user)==null?void 0:r.data)==null?void 0:d.accessToken});h.useRef(null);const[v,x]=h.useState(null),[i,f]=h.useState(null),[e,g]=h.useState(null),k=()=>b?{Authorization:`Bearer ${b}`}:{},w=async a=>{x(null);try{const r=await fetch(`${q}/${m}/export?format=${a}`,{method:"POST",headers:{"Content-Type":"application/json",...k()},body:JSON.stringify(u||{})});if(!r.ok)throw new Error(`Export failed (${r.status})`);const d=await r.blob(),y=window.URL.createObjectURL(d),t=document.createElement("a");t.href=y,t.download=`${p}.${a}`,document.body.appendChild(t),t.click(),t.remove(),window.URL.revokeObjectURL(y)}catch(r){f({severity:"error",message:(r==null?void 0:r.message)||"Export failed"})}};return l(H,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:[R&&l(T,{children:[o(B,{startIcon:o(W,{}),sx:{bgcolor:"#1F4E78",px:2,color:"#ffffff","&:hover":{bgcolor:"#4d6274",color:"#fff"}},onClick:a=>x(a.currentTarget),children:"Export"}),l(N,{anchorEl:v,open:!!v,onClose:()=>x(null),children:[o(C,{onClick:()=>w("xlsx"),children:"Excel (.xlsx)"}),o(C,{onClick:()=>w("csv"),children:"CSV (.csv)"})]})]}),o(S,{open:!!i,autoHideDuration:5e3,onClose:()=>f(null),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:i?o($,{severity:i.severity,onClose:()=>f(null),sx:{width:"100%"},children:i.message}):void 0}),l(A,{open:!!(e&&(e.failed??0)>0),onClose:()=>g(null),maxWidth:"sm",fullWidth:!0,children:[o(I,{children:"Import result"}),l(z,{dividers:!0,children:[l(D,{variant:"body2",gutterBottom:!0,children:[e!=null&&e.fileName?`${e.fileName}: `:"",(e==null?void 0:e.imported)??0," imported, ",(e==null?void 0:e.failed)??0," failed",typeof(e==null?void 0:e.totalRows)=="number"?` of ${e.totalRows} row(s)`:"","."]}),(e==null?void 0:e.errors)&&e.errors.length>0&&l(O,{size:"small",children:[o(U,{children:l(j,{children:[o(s,{children:"Row"}),o(s,{children:"Name"}),o(s,{children:"Reason"})]})}),o(_,{children:e.errors.map((a,r)=>l(j,{children:[o(s,{children:a.row}),o(s,{children:a.label||a.customerName||"-"}),o(s,{children:a.message})]},`${a.row}-${r}`))})]})]}),o(L,{children:o(F,{btnType:"close",onClick:()=>g(null),children:"Close"})})]})]})};var J="container_5496fe",P="inner_3d3774",c="dot_e701da";const Y=({size:m=60,color:p="black",speed:u=2.5})=>n.jsx("div",{className:J,style:{"--uib-size":m+"px","--uib-color":p,"--uib-speed":u+"s"},children:n.jsxs("div",{className:P,children:[n.jsx("div",{className:c}),n.jsx("div",{className:c}),n.jsx("div",{className:c}),n.jsx("div",{className:c}),n.jsx("div",{className:c})]})});export{Q as I,Y as d};
