1import{r as f,t as R,a as I,j as e,C as k,F as U,B as C,X as E,U as b,D as O,b as P,L as A,c as B,T}from"./index-BRV1LY_U.js";const _=["cnpj","razaoSocial"],M=["regime","uf","email","telefone","responsavel","municipio","cnaeFiscal"],D=[..._,...M],H={cnpj:"cnpj","cnpj/cpf":"cnpj",razaosocial:"razaoSocial","razao social":"razaoSocial","razão social":"razaoSocial",regime:"regime","regime tributario":"regime","regime tributário":"regime",uf:"uf",estado:"uf",email:"email","e-mail":"email",telefone:"telefone",fone:"telefone",responsavel:"responsavel",responsável:"responsavel",municipio:"municipio",municÃpio:"municipio",cidade:"municipio",cnae:"cnaeFiscal",cnaefiscal:"cnaeFiscal","cnae fiscal":"cnaeFiscal"};function $(i){const c=i.trim().toLowerCase().replace(/[_\-\.]/g," ");return H[c]||c}function q(i){const c=i.split(/\r?\n/).filter(a=>a.trim());if(c.length<2)return{headers:[],rows:[]};const m=c[0],p=m.includes(";")?";":",",d=m.split(p).map(a=>a.replace(/^["']|["']$/g,"").trim()).map($),S=[];for(let a=1;a<c.length;a++){const n=c[a].split(p).map(l=>l.replace(/^["']|["']$/g,"").trim()),x={};d.forEach((l,u)=>{D.includes(l)&&(x[l]=n[u]||"")}),x.cnpj&&S.push(x)}return{headers:d,rows:S}}function W({onClose:i,onSuccess:c}){const[m,p]=f.useState("upload"),[r,d]=f.useState([]),[S,a]=f.useState(""),[n,x]=f.useState(null),l=f.useRef(null),u=R.clientes.importCSV.useMutation({onSuccess:t=>{x(t),p("result"),t.success>0&&c()},onError:t=>{I.error(`Erro na importação: ${t.message}`)}});function w(t){const o=t.target.files?.[0];if(!o)return;if(!o.name.endsWith(".csv")&&!o.name.endsWith(".txt")){I.error("Formato inválido. Selecione um arquivo .csv");return}a(o.name);const j=new FileReader;j.onload=g=>{const h=g.target?.result,{headers:V,rows:L}=q(h),N=V.includes("cnpj"),v=V.includes("razaoSocial");if(!N||!v){const s=[];N||s.push("cnpj"),v||s.push("razaoSocial (ou razão social)"),I.error(`Colunas obrigatórias ausentes: ${s.join(", ")}`);return}const F=L.map(s=>({cnpj:s.cnpj||"",razaoSocial:s.razaoSocial||"",regime:s.regime&&["simples","presumido","real"].includes(s.regime.toLowerCase())?s.regime.toLowerCase():null,uf:s.uf?.toUpperCase()||null,email:s.email||null,telefone:s.telefone||null,responsavel:s.responsavel||null,municipio:s.municipio||null,cnaeFiscal:s.cnaeFiscal||null}));d(F),p("preview")},j.readAsText(o,"UTF-8")}function y(){u.mutate({rows:r})}function z(){const t="cnpj;razaoSocial;regime;uf;email;telefone;responsavel;municipio;cnaeFiscal",o="12345678000199;Empresa Exemplo LTDA;simples;SP;[email protected];11999999999;João Silva;São Paulo;4711302",j=new Blob([t+` 2`+o+` 3`],{type:"text/csv;charset=utf-8;"}),g=URL.createObjectURL(j),h=document.createElement("a");h.href=g,h.download="modelo_importacao_taxflow.csv",h.click(),URL.revokeObjectURL(g)}return e.jsx("div",{"data-loc":"client/src/components/ImportCSV.tsx:179",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:e.jsxs(k,{"data-loc":"client/src/components/ImportCSV.tsx:180",className:"w-full max-w-2xl mx-4 p-6 max-h-[85vh] overflow-y-auto",children:[e.jsxs("div",{"data-loc":"client/src/components/ImportCSV.tsx:181",className:"flex items-center justify-between mb-4",children:[e.jsxs("h2",{"data-loc":"client/src/components/ImportCSV.tsx:182",className:"text-lg font-bold flex items-center gap-2",children:[e.jsx(U,{"data-loc":"client/src/components/ImportCSV.tsx:183",className:"w-5 h-5 text-emerald-500"}),"Importar Clientes via CSV"]}),e.jsx(C,{"data-loc":"client/src/components/ImportCSV.tsx:186",variant:"ghost",size:"icon",onClick:i,children:e.jsx(E,{"data-loc":"client/src/components/ImportCSV.tsx:187",className:"w-4 h-4"})})]}),m==="upload"&&e.jsxs("div",{"data-loc":"client/src/components/ImportCSV.tsx:192",className:"space-y-4",children:[e.jsxs("div",{"data-loc":"client/src/components/ImportCSV.tsx:193",className:"border-2 border-dashed border-muted-foreground/25 rounded-xl p-8 text-center cursor-pointer hover:border-emerald-500/50 transition-colors",onClick:()=>l.current?.click(),children:[e.jsx(b,{"data-loc":"client/src/components/ImportCSV.tsx:197",className:"w-10 h-10 mx-auto text-muted-foreground mb-3"}),e.jsx("p",{"data-loc":"client/src/components/ImportCSV.tsx:198",className:"font-medium",children:"Clique para selecionar ou arraste o arquivo CSV"}),e.jsxs("p",{"data-loc":"client/src/components/ImportCSV.tsx:199",className:"text-sm text-muted-foreground mt-1",children:["Colunas obrigatórias: ",e.jsx("strong",{"data-loc":"client/src/components/ImportCSV.tsx:200",children:"cnpj"}),", ",e.jsx("strong",{"data-loc":"client/src/components/ImportCSV.tsx:200",children:"razaoSocial"})]}),e.jsx("p",{"data-loc":"client/src/components/ImportCSV.tsx:202",className:"text-xs text-muted-foreground mt-1",children:"Opcionais: regime, uf, email, telefone, responsavel, municipio, cnaeFiscal"})]}),e.jsx("input",{"data-loc":"client/src/components/ImportCSV.tsx:206",ref:l,type:"file",accept:".csv,.txt",className:"hidden",onChange:w}),e.jsxs(C,{"data-loc":"client/src/components/ImportCSV.tsx:213",variant:"outline",size:"sm",onClick:z,className:"w-full",children:[e.jsx(O,{"data-loc":"client/src/components/ImportCSV.tsx:214",className:"w-4 h-4 mr-2"}),"Baixar modelo CSV"]})]}),m==="preview"&&e.jsxs("div",{"data-loc":"client/src/components/ImportCSV.tsx:221",className:"space-y-4",children:[e.jsxs("div",{"data-loc":"client/src/components/ImportCSV.tsx:222",className:"flex items-center justify-between",children:[e.jsxs("p",{"data-loc":"client/src/components/ImportCSV.tsx:223",className:"text-sm text-muted-foreground",children:[e.jsx("strong",{"data-loc":"client/src/components/ImportCSV.tsx:224",children:S})," â ",r.length," registros encontrados"]}),e.jsxs(P,{"data-loc":"client/src/components/ImportCSV.tsx:226",variant:"outline",children:[r.length," linhas"]})]}),e.jsxs("div",{"data-loc":"client/src/components/ImportCSV.tsx:230",className:"border rounded-lg overflow-x-auto max-h-60",children:[e.jsxs("table",{"data-loc":"client/src/components/ImportCSV.tsx:231",className:"w-full text-xs",children:[e.jsx("thead",{"data-loc":"client/src/components/ImportCSV.tsx:232",className:"bg-muted/50 sticky top-0",children:e.jsxs("tr",{"data-loc":"client/src/components/ImportCSV.tsx:233",children:[e.jsx("th",{"data-loc":"client/src/components/ImportCSV.tsx:234",className:"px-2 py-1.5 text-left",children:"#"}),e.jsx("th",{"data-loc":"client/src/components/ImportCSV.tsx:235",className:"px-2 py-1.5 text-left",children:"CNPJ"}),e.jsx("th",{"data-loc":"client/src/components/ImportCSV.tsx:236",className:"px-2 py-1.5 text-left",children:"Razão Social"}),e.jsx("th",{"data-loc":"client/src/components/ImportCSV.tsx:237",className:"px-2 py-1.5 text-left",children:"Regime"}),e.jsx("th",{"data-loc":"client/src/components/ImportCSV.tsx:238",className:"px-2 py-1.5 text-left",children:"UF"})]})}),e.jsx("tbody",{"data-loc":"client/src/components/ImportCSV.tsx:241",children:r.slice(0,10).map((t,o)=>e.jsxs("tr",{"data-loc":"client/src/components/ImportCSV.tsx:243",className:"border-t",children:[e.jsx("td",{"data-loc":"client/src/components/ImportCSV.tsx:244",className:"px-2 py-1 text-muted-foreground",children:o+1}),e.jsx("td",{"data-loc":"client/src/components/ImportCSV.tsx:245",className:"px-2 py-1 font-mono",children:t.cnpj}),e.jsx("td",{"data-loc":"client/src/components/ImportCSV.tsx:246",className:"px-2 py-1",children:t.razaoSocial}),e.jsx("td",{"data-loc":"client/src/components/ImportCSV.tsx:247",className:"px-2 py-1",children:t.regime||"â"}),e.jsx("td",{"data-loc":"client/src/components/ImportCSV.tsx:248",className:"px-2 py-1",children:t.uf||"â"})]},o))})]}),r.length>10&&e.jsxs("p",{"data-loc":"client/src/components/ImportCSV.tsx:254",className:"text-xs text-center text-muted-foreground py-2",children:["...e mais ",r.length-10," registros"]})]}),e.jsxs("div",{"data-loc":"client/src/components/ImportCSV.tsx:260",className:"flex gap-2",children:[e.jsx(C,{"data-loc":"client/src/components/ImportCSV.tsx:261",variant:"outline",onClick:()=>{p("upload"),d([])},className:"flex-1",children:"Voltar"}),e.jsx(C,{"data-loc":"client/src/components/ImportCSV.tsx:264",onClick:y,disabled:u.isPending,className:"flex-1 bg-emerald-600 hover:bg-emerald-700",children:u.isPending?e.jsxs(e.Fragment,{children:[e.jsx(A,{"data-loc":"client/src/components/ImportCSV.tsx:271",className:"w-4 h-4 mr-2 animate-spin"}),"Importando..."]}):e.jsxs(e.Fragment,{children:[e.jsx(b,{"data-loc":"client/src/components/ImportCSV.tsx:276",className:"w-4 h-4 mr-2"}),"Confirmar Importação (",r.length,")"]})})]})]}),m==="result"&&n&&e.jsxs("div",{"data-loc":"client/src/components/ImportCSV.tsx:286",className:"space-y-4",children:[e.jsxs("div",{"data-loc":"client/src/components/ImportCSV.tsx:287",className:"flex items-center gap-3 p-4 rounded-lg bg-emerald-500/10 border border-emerald-500/20",children:[e.jsx(B,{"data-loc":"client/src/components/ImportCSV.tsx:288",className:"w-6 h-6 text-emerald-500"}),e.jsxs("div",{"data-loc":"client/src/components/ImportCSV.tsx:289",children:[e.jsxs("p",{"data-loc":"client/src/components/ImportCSV.tsx:290",className:"font-semibold",children:[n.success," clientes importados com sucesso"]}),n.skippedByLimit>0&&e.jsxs("p",{"data-loc":"client/src/components/ImportCSV.tsx:292",className:"text-sm text-amber-500 mt-1",children:[n.skippedByLimit," ignorados (limite do plano)"]})]})]}),n.errors.length>0&&e.jsxs("div",{"data-loc":"client/src/components/ImportCSV.tsx:300",className:"border rounded-lg p-3",children:[e.jsxs("p",{"data-loc":"client/src/components/ImportCSV.tsx:301",className:"text-sm font-medium flex items-center gap-2 mb-2",children:[e.jsx(T,{"data-loc":"client/src/components/ImportCSV.tsx:302",className:"w-4 h-4 text-amber-500"}),n.errors.length," erros encontrados"]}),e.jsx("div",{"data-loc":"client/src/components/ImportCSV.tsx:305",className:"max-h-40 overflow-y-auto space-y-1",children:n.errors.map((t,o)=>e.jsxs("p",{"data-loc":"client/src/components/ImportCSV.tsx:307",className:"text-xs text-muted-foreground",children:["Linha ",t.row,": ",t.error]},o))})]}),e.jsx(C,{"data-loc":"client/src/components/ImportCSV.tsx:315",onClick:i,className:"w-full",children:"Fechar"})]})]})})}export{W 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.