1import{r as v,j as e}from"./react-vendor-pafHdoJx.js";import{u as z,b as C,d as p,l as D}from"./index-Db0fDLGN.js";import{ay as A,I as M,L as h,P,l as j,ae as L,av as $}from"./ui-vendor-DLXJn6s3.js";import"./map-vendor-Dr8zbd0c.js";import"./firebase-vendor-D3UzkAhn.js";const b=i=>(i||0).toLocaleString("pt-BR",{style:"currency",currency:"BRL"}),I=["Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"];function Y(){var B,F,S;const i=new Date,m=new Date(i.getFullYear(),i.getMonth()-1,1),[c,q]=v.useState(m.getFullYear()),[x,E]=v.useState(m.getMonth()+1),[y,f]=v.useState(!1),{toast:g}=z(),o=C(()=>p.spedList(),[]),t=C(()=>p.spedPreview(c,x),[c,x]),w=async(s=!1)=>{var l,d,k;f(!0);try{const r=await p.spedGerar({ano:c,mes:x,retificador:s});g({title:`Arquivo gerado: ${r.incluidos} documentos${(l=r.rejeitados)!=null&&l.length?`, ${r.rejeitados.length} fora`:""}.`,kind:(d=r.rejeitados)!=null&&d.length?"warning":"success"}),o.refetch(),t.refetch(),D("sped_gerado",{incluidos:r.incluidos,rejeitados:((k=r.rejeitados)==null?void 0:k.length)??0})}catch(r){g({title:(r==null?void 0:r.message)||"Falha ao gerar o arquivo",kind:"error"})}finally{f(!1)}},N={borderColor:"var(--border-primary)",background:"var(--surface-secondary)"},a=t.data,n=(a==null?void 0:a.rejeitados)||[];return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{size:20,style:{color:"#0891B2"}}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold",style:{color:"var(--page-text)"},children:"SPED Fiscal"}),e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-secondary)"},children:"Bloco D â os seus documentos de transporte escriturados, prontos para o contábil importar"})]})]}),e.jsxs("div",{className:"rounded-xl border p-4 flex items-start gap-2.5",style:{borderColor:"#0891B240",background:"#0891B210"},children:[e.jsx(M,{size:15,className:"shrink-0 mt-0.5",style:{color:"#0891B2"}}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",style:{color:"var(--page-text)"},children:"Este arquivo cobre os blocos 0, D e 9 â a escrituração dos seus documentos de transporte."}),e.jsx("p",{className:"text-xs mt-1 leading-relaxed",style:{color:"var(--page-text-secondary)"},children:"Não é a EFD completa: os blocos de compras, apuração, inventário e ativo imobilizado seguem com a sua contabilidade, que é quem responde pela entrega. O que entregamos é o pedaço que nasce aqui â no leiaute 020, com os campos de IBS e CBS de 2026."})]})]}),e.jsxs("div",{className:"rounded-xl border p-4",style:N,children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"sped-mes",className:"text-xs font-semibold block mb-1",style:{color:"var(--page-text-secondary)"},children:"Mês"}),e.jsx("select",{id:"sped-mes",value:x,onChange:s=>E(Number(s.target.value)),className:"px-3 py-2 rounded-lg border text-sm bg-transparent",style:{borderColor:"var(--border-primary)",color:"var(--page-text)"},children:I.map((s,l)=>e.jsx("option",{value:l+1,children:s},s))})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"sped-ano",className:"text-xs font-semibold block mb-1",style:{color:"var(--page-text-secondary)"},children:"Ano"}),e.jsx("input",{id:"sped-ano",type:"number",value:c,onChange:s=>q(Number(s.target.value)),className:"w-24 px-3 py-2 rounded-lg border text-sm bg-transparent",style:{borderColor:"var(--border-primary)",color:"var(--page-text)"}})]}),e.jsxs("button",{onClick:()=>w(!1),disabled:y||t.loading,className:"px-4 py-2 rounded-lg text-sm font-semibold flex items-center gap-1.5 disabled:opacity-50",style:{background:"#0891B2",color:"#fff"},children:[y?e.jsx(h,{size:15,className:"animate-spin"}):e.jsx(P,{size:15})," Gerar arquivo"]})]}),t.loading&&!t.data?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(h,{size:18,className:"animate-spin",style:{color:"var(--page-text-secondary)"}})}):t.error?e.jsxs("p",{className:"text-xs mt-4",style:{color:"#EF4444"},children:["Não consegui calcular a prévia: ",t.error]}):a?e.jsxs("div",{className:"mt-4 grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(u,{label:"Documentos",value:String(a.incluidos),color:"#10B981"}),e.jsx(u,{label:"Fora do arquivo",value:String(n.length),color:n.length?"#F59E0B":"#94A3B8"}),e.jsx(u,{label:"Valor dos serviços",value:b((B=a.totais)==null?void 0:B.valorServico)}),e.jsx(u,{label:"ICMS",value:b((F=a.totais)==null?void 0:F.icms)})]}):null,!(a!=null&&a.emitenteCompleto)&&a&&e.jsxs("p",{className:"text-xs mt-3 flex items-start gap-1.5",style:{color:"#F59E0B"},children:[e.jsx(j,{size:12,className:"mt-0.5 shrink-0"}),"Cadastro da empresa incompleto (CNPJ, UF, razão social e inscrição estadual são obrigatórios no registro 0000). Complete antes de gerar."]}),n.length>0&&e.jsxs("div",{className:"mt-4 rounded-lg p-3",style:{background:"#F59E0B10",border:"1px solid #F59E0B40"},children:[e.jsxs("p",{className:"text-xs font-semibold flex items-center gap-1.5",style:{color:"#F59E0B"},children:[e.jsx(j,{size:12})," ",n.length," documento(s) não entram no arquivo"]}),e.jsx("p",{className:"text-[11px] mt-1",style:{color:"var(--page-text-secondary)"},children:"Corrija antes de entregar ao contador â documento faltando no SPED aparece no cruzamento do fisco."}),e.jsx("div",{className:"mt-2 space-y-1 max-h-48 overflow-y-auto",children:n.slice(0,50).map(s=>e.jsxs("p",{className:"text-[11px] font-mono",style:{color:"var(--page-text-secondary)"},children:[s.chave?`â¦${String(s.chave).slice(-8)}`:s.id," · ",s.motivos.join("; ")]},s.id))})]})]}),e.jsxs("div",{className:"rounded-xl border p-4",style:N,children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide mb-3",style:{color:"var(--page-text-secondary)"},children:"Arquivos gerados"}),o.loading&&!o.data?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(h,{size:18,className:"animate-spin",style:{color:"var(--page-text-secondary)"}})}):o.error?e.jsxs("p",{className:"text-xs",style:{color:"#EF4444"},children:["Não consegui carregar os arquivos: ",o.error]}):(((S=o.data)==null?void 0:S.arquivos)||[]).length===0?e.jsx("p",{className:"text-xs",style:{color:"var(--page-text-muted)"},children:"Nenhum arquivo gerado ainda."}):e.jsx("div",{className:"space-y-2",children:o.data.arquivos.map(s=>{var l;return e.jsxs("div",{className:"rounded-lg border p-3 flex items-center justify-between gap-3 flex-wrap",style:{borderColor:"var(--border-primary)",background:"var(--surface-primary)"},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm font-semibold flex items-center gap-1.5",style:{color:"var(--page-text)"},children:[s.rejeitados>0?e.jsx(j,{size:13,style:{color:"#F59E0B"}}):e.jsx(L,{size:13,style:{color:"#10B981"}}),s.periodo,s.retificador&&e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-amber-100 text-amber-800 text-[9px] font-bold uppercase",children:"retificador"})]}),e.jsxs("p",{className:"text-[11px] mt-0.5",style:{color:"var(--page-text-muted)"},children:[s.incluidos," documentos",s.rejeitados>0?` · ${s.rejeitados} fora`:""," · ",b((l=s.totais)==null?void 0:l.valorServico)," · ","gerado por ",s.geradoPor||"â"]})]}),e.jsxs("button",{onClick:()=>p.spedDownload(s.id,s.nomeArquivo).catch(d=>g({title:(d==null?void 0:d.message)||"Falha no download",kind:"error"})),className:"px-3 py-1.5 rounded-lg text-xs font-semibold flex items-center gap-1.5 shrink-0",style:{background:"#0891B215",color:"#0891B2",border:"1px solid #0891B240"},children:[e.jsx($,{size:12})," Baixar"]})]},s.id)})})]})]})}function u({label:i,value:m,color:c}){return e.jsxs("div",{className:"rounded-lg p-3",style:{background:"var(--surface-primary)",border:"1px solid var(--border-primary)"},children:[e.jsx("p",{className:"text-lg font-bold tabular-nums leading-none",style:{color:c||"var(--page-text)"},children:m}),e.jsx("p",{className:"text-[10px] mt-1.5",style:{color:"var(--page-text-muted)"},children:i})]})}export{Y 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.