import{bq as T,br as $,a9 as n,bt as B,r as p,j as l,b as o,H as N,$ as D,aR as _,Q as E,bX as A,bY as I,D as F,f as z,g as M,s as O,w as W,y as j,z as t,x as U,E as q,A as H,i as L,B as P,bu as V,F as J}from"./index-BiWH3VAt.js";var b={},Q=T;Object.defineProperty(b,"__esModule",{value:!0});var R=b.default=void 0,X=Q($()),Y=n;R=b.default=(0,X.default)((0,Y.jsx)("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96M17 13l-5 5-5-5h3V9h4v4z"}),"CloudDownload");const G=`${V}/erp-crm/v1`,re=({modulePath:c,fileBaseName:s,criteria:m,onImported:ee,canExport:k=!0,canImport:oe=!0})=>{const v=B(a=>{var r,u;return(u=(r=a==null?void 0:a.user)==null?void 0:r.data)==null?void 0:u.accessToken});p.useRef(null);const[g,f]=p.useState(null),[h,x]=p.useState(null),[e,w]=p.useState(null),S=()=>v?{Authorization:`Bearer ${v}`}:{},C=async a=>{f(null);try{const r=await fetch(`${G}/${c}/export?format=${a}`,{method:"POST",headers:{"Content-Type":"application/json",...S()},body:JSON.stringify(m||{})});if(!r.ok)throw new Error(`Export failed (${r.status})`);const u=await r.blob(),y=window.URL.createObjectURL(u),i=document.createElement("a");i.href=y,i.download=`${s}.${a}`,document.body.appendChild(i),i.click(),i.remove(),window.URL.revokeObjectURL(y)}catch(r){x({severity:"error",message:(r==null?void 0:r.message)||"Export failed"})}};return l(P,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:[k&&l(N,{children:[o(D,{startIcon:o(R,{}),sx:{bgcolor:"#1F4E78",px:2,color:"#ffffff","&:hover":{bgcolor:"#4d6274",color:"#fff"}},onClick:a=>f(a.currentTarget),children:"Export"}),l(_,{anchorEl:g,open:!!g,onClose:()=>f(null),children:[o(E,{onClick:()=>C("xlsx"),children:"Excel (.xlsx)"}),o(E,{onClick:()=>C("csv"),children:"CSV (.csv)"})]})]}),o(I,{open:!!h,autoHideDuration:5e3,onClose:()=>x(null),anchorOrigin:{vertical:"bottom",horizontal:"center"},children:h?o(A,{severity:h.severity,onClose:()=>x(null),sx:{width:"100%"},children:h.message}):void 0}),l(F,{open:!!(e&&(e.failed??0)>0),onClose:()=>w(null),maxWidth:"sm",fullWidth:!0,children:[o(z,{children:"Import result"}),l(M,{dividers:!0,children:[l(O,{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(W,{size:"small",children:[o(U,{children:l(j,{children:[o(t,{children:"Row"}),o(t,{children:"Name"}),o(t,{children:"Reason"})]})}),o(q,{children:e.errors.map((a,r)=>l(j,{children:[o(t,{children:a.row}),o(t,{children:a.label||a.customerName||"-"}),o(t,{children:a.message})]},`${a.row}-${r}`))})]})]}),o(L,{children:o(H,{btnType:"close",onClick:()=>w(null),children:"Close"})})]})]})};function le({label:c,size:s="small"}){return o(J,{label:c??"—",size:s,sx:{bgcolor:"#EEF2FF",color:"#3730A3",border:"1px solid #C7D2FE",fontWeight:600,fontSize:s==="small"?11:13}})}var K="container_5496fe",Z="inner_3d3774",d="dot_e701da";const ne=({size:c=60,color:s="black",speed:m=2.5})=>n.jsx("div",{className:K,style:{"--uib-size":c+"px","--uib-color":s,"--uib-speed":m+"s"},children:n.jsxs("div",{className:Z,children:[n.jsx("div",{className:d}),n.jsx("div",{className:d}),n.jsx("div",{className:d}),n.jsx("div",{className:d}),n.jsx("div",{className:d})]})});export{re as I,le as W,R as a,ne as d};
