1import{j as e,a7 as d,ak as A,$,a1 as I,H as T,T as x,ad as M,N,Q as C,R as _,ac as E,ao as h,as as W}from"./mui-CRsYZxVY.js";import{r as l}from"./vendor-Dwao9eNC.js";import{u as K,w as O,c8 as Q,c1 as z,bc as H,c as U,T as Y,K as G,b as J,cF as V,cR as X,aK as Z}from"./index-TALscxEc.js";import{C as ee}from"./ContactsPicker-5yc6Pf7M.js";import{d as te,a as se,f as ae}from"./formatRelativeDateAndTime-DMOe89_J.js";import{F as re}from"./FileSelector-D88j3gbb.js";import{u as oe,a as ie}from"./query-8ViTdhdk.js";import{L as ne}from"./lab-DSem1Osk.js";import"./datePickers-BIJXYOKG.js";import"./icons-D8aatgQ4.js";import"./ProductSearchBar-CThCmE3j.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},s=new t.Error().stack;s&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[s]="cc1d2f38-36f0-4e9f-b5ee-2d916476e3ba",t._sentryDebugIdIdentifier="sentry-dbid-cc1d2f38-36f0-4e9f-b5ee-2d916476e3ba")})()}catch{}const le=()=>{const{user:t}=K(),s=t==null?void 0:t.id;return oe({queryKey:["customerImports"],queryFn:async()=>{if(!s)throw new Error("Usuário não autenticado");const{data:n,error:r}=await O.from("importacao_cliente").select("id, user_id, quantidade_clientes, criado_em").eq("user_id",s).order("criado_em",{ascending:!1});if(r)throw new Error(r.message);return n},enabled:!!s})},de=({id:t,date:s,customerCount:n})=>{const r=J();return e.jsx(_,{disablePadding:!0,onClick:()=>r(`/customers/import/${t}`),sx:{border:"1px solid",borderColor:"divider"},children:e.jsxs(W,{children:[e.jsx(E,{primary:`Importação de ${n} ${n===1?"cliente":"clientes"}`,secondary:ae(V(s))}),e.jsx(X,{color:"primary"})]})})},ve=()=>{const t=Q(),s=z.isNativePlatform(),n=l.useMemo(()=>(s&&t.pathname.endsWith("contacts-import"),0),[t.pathname,s]),[r,B]=l.useState(n),{appBarWidth:L,appBarMarginLeft:S}=H(),[m,y]=l.useState(null),[P,g]=l.useState(0),[b,j]=l.useState(!1),[u,c]=l.useState(null),D=ie(),{data:p,isLoading:R,error:F}=le(),{data:f}=U(),k=a=>{y(a),a||g(i=>i+1)},q=async()=>{var i,v;if(!m)return;c(null),j(!0);const a=new FormData;a.append("file",m);try{const w=(await Z.post("/customer/import",a,{headers:{"Content-Type":"multipart/form-data"}})).data;c({show:!0,message:`${w.count} ${w.count===1?"cliente importado":"clientes importados"} com sucesso.`,severity:"success"}),D.invalidateQueries({queryKey:["customerImports"]})}catch(o){c({show:!0,message:((v=(i=o==null?void 0:o.response)==null?void 0:i.data)==null?void 0:v.error)||(o==null?void 0:o.message)||"Erro desconhecido ao importar clientes.",severity:"error"})}finally{j(!1),y(null),g(o=>o+1)}};return e.jsxs(d,{sx:{display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(Y,{title:"Importar clientes",navigateBack:!0,hideBottomBorder:!0}),s&&e.jsx(A,{position:"fixed",color:"default",sx:{top:"calc(var(--safe-area-inset-top) + 56px)",left:0,right:0,width:L,ml:S,zIndex:1,backgroundColor:"white"},elevation:0,children:e.jsxs($,{value:r,onChange:(a,i)=>B(i),variant:"fullWidth",indicatorColor:"primary",textColor:"primary",sx:{"& .MuiTab-root":{textTransform:"none",minHeight:48,fontWeight:600}},children:[e.jsx(I,{label:"Contatos"}),e.jsx(I,{label:"Planilha"})]})}),e.jsxs(d,{sx:{flex:1,overflow:"hidden",pt:s?"48px":"0px"},children:[s&&r===0&&e.jsx(ee,{mode:"multi"}),(s&&r===1||!s&&r===0)&&e.jsxs(d,{sx:{p:2},children:[e.jsxs(T,{elevation:0,sx:{p:2,mb:2,bgcolor:"white"},children:[e.jsx(x,{variant:"h6",gutterBottom:!0,color:"primary",fontWeight:"bold",children:"Nova importação"}),u&&e.jsx(M,{severity:u.severity,sx:{my:2},onClose:()=>c(null),children:u.message}),e.jsxs(d,{sx:{my:2},children:[e.jsx(re,{onFileChange:k,acceptedFileTypes:".csv, .xlsx, .xls"},P),e.jsx(ne,{loading:b,loadingPosition:"start",startIcon:e.jsx(te,{}),variant:"contained",fullWidth:!0,onClick:q,disabled:!m,sx:{mt:2},children:b?"Importando...":"Importar clientes"})]}),e.jsx(d,{sx:{display:"flex",justifyContent:"space-between",mt:2},children:e.jsx(N,{startIcon:e.jsx(se,{}),size:"small",sx:{flex:1,mr:1},component:"a",href:f==null?void 0:f.CUSTOMER_IMPORT_SPREADSHEET_MODEL,children:"Baixar modelo"})})]}),e.jsxs(T,{elevation:0,sx:{p:2,bgcolor:"white"},children:[e.jsx(x,{variant:"h6",gutterBottom:!0,color:"primary",fontWeight:"bold",marginBottom:2,children:"Importações recentes"}),R?e.jsx(C,{disablePadding:!0,children:[1,2,3].map((a,i)=>e.jsxs(_,{sx:{border:"1px solid",borderColor:"divider"},children:[e.jsx(E,{primary:e.jsx(h,{width:"60%"}),secondary:e.jsx(h,{width:"40%"})}),e.jsx(h,{variant:"circular",width:24,height:24})]},i))}):F?e.jsx(x,{color:"error",children:"Erro ao carregar importações"}):p&&p.length>0?e.jsx(C,{disablePadding:!0,children:p.map(a=>e.jsx(de,{id:a.id,date:a.criado_em,customerCount:a.quantidade_clientes},a.id))}):e.jsx(G,{primaryText:"Nenhuma importação recente",secondaryText:"As importações aparecerão aqui após serem realizadas"})]})]})]})]})};export{ve as default};
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.