1import{j as e,a7 as x,a6 as U,I as z,ab as K,T as I,at as N,n as Q,ar as W,ac as O,X,ai as Y,Z,aq as G,O as H,N as R}from"./mui-CRsYZxVY.js";import{b as r}from"./vendor-Dwao9eNC.js";import{u as k,aK as A,b as J,T as F,b3 as n,e7 as $}from"./index-TALscxEc.js";import{C as ee}from"./CertificadoReenvioAlert-4LpNdURr.js";import{F as ae}from"./FileSelector-D88j3gbb.js";import{u as ie}from"./useFiscalConfig-CQEKyhOW.js";import{a as M,b as q}from"./query-8ViTdhdk.js";import{M as te,D as re}from"./icons-D8aatgQ4.js";import{L as se}from"./lab-DSem1Osk.js";import"./datePickers-BIJXYOKG.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};a.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var a=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},i=new a.Error().stack;i&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[i]="ca229304-a212-41cb-8acd-4f6cc880f43e",a._sentryDebugIdIdentifier="sentry-dbid-ca229304-a212-41cb-8acd-4f6cc880f43e")})()}catch{}const oe=()=>{const{user:a}=k(),i=M();return q({mutationFn:async({file:c,password:l})=>{if(!(a!=null&&a.id))throw new Error("User not authenticated");const s=new FormData;return s.append("file",c),s.append("password",l),(await A.post("/fiscal/certificado",s,{headers:{"Content-Type":"multipart/form-data"}})).data},onSuccess:()=>{i.invalidateQueries({queryKey:["fiscal-config"]})}})},ne=()=>{const{user:a}=k(),i=M();return q({mutationFn:async()=>{if(!(a!=null&&a.id))throw new Error("User not authenticated");return(await A.delete("/fiscal/certificado")).data},onSuccess:()=>{i.invalidateQueries({queryKey:["fiscal-config"]})}})},ve=()=>{var D,E,S;const a=J(),{data:i,isLoading:c}=ie(),l=oe(),s=ne(),[o,v]=r.useState(null),[d,y]=r.useState(""),[C,f]=r.useState(null),[j,B]=r.useState(null),[b,h]=r.useState(null),[L,u]=r.useState(!1),m=r.useRef(null);r.useEffect(()=>()=>{m.current&&clearTimeout(m.current)},[]);const P=async()=>{var t,T;if(!(!o||!d))try{await l.mutateAsync({file:o,password:d}),v(null),y(""),f(null),B("Certificado enviado com sucesso. Você já pode emitir notas fiscais."),m.current=setTimeout(()=>a(-1),1800)}catch(_){f(((T=(t=_.response)==null?void 0:t.data)==null?void 0:T.error)||"Erro ao enviar certificado. Verifique o arquivo e a senha.")}},V=async()=>{u(!1);try{await s.mutateAsync(),a(-1)}catch{f("Erro ao remover certificado.")}};if(c)return e.jsx(x,{sx:{height:"70vh",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(U,{})});if(!i)return e.jsxs(x,{p:2,children:[e.jsx(F,{title:"Certificado digital",navigateBack:!0}),e.jsx(n,{severity:"warning",children:"Cadastre os dados da empresa antes de enviar o certificado digital."})]});const p=!!((D=i.certificado)!=null&&D.validade||(E=i.certificado)!=null&&E.serial),w=(S=i.certificado)!=null&&S.validade?new Date(i.certificado.validade)<new Date:!1,g=p&&i.precisaEnviarCertificado;return e.jsxs(x,{p:2,children:[e.jsx(F,{title:"Certificado digital",navigateBack:!0,children:p&&e.jsx(z,{color:"inherit",onClick:t=>h(t.currentTarget),children:e.jsx(te,{})})}),e.jsxs(K,{spacing:3,children:[j?e.jsx(n,{severity:"success",children:j}):g?e.jsx(ee,{}):p?e.jsxs(n,{severity:w?"error":"success",title:"Certificado instalado",children:[i.certificado.validade&&e.jsxs(e.Fragment,{children:[w?"Expirado em ":"Válido até ",new Date(i.certificado.validade).toLocaleDateString("pt-BR")]}),i.certificado.serial&&e.jsxs(I,{component:"span",sx:{display:"block",fontSize:"0.7rem",color:"text.disabled",mt:.5},children:["Serial: ",i.certificado.serial]})]}):e.jsx(n,{severity:"info",children:"Envie seu certificado digital A1 (.pfx ou .p12) para poder emitir notas fiscais."}),e.jsx(I,{variant:"subtitle1",fontWeight:"bold",children:g?"Reenviar certificado":p?"Substituir certificado":"Enviar certificado"}),e.jsx(ae,{onFileChange:t=>v(t),acceptedFileTypes:".pfx,.p12"}),o&&e.jsx($,{label:"Senha do certificado *",value:d,onChange:t=>y(t.target.value),fullWidth:!0}),C&&e.jsx(n,{severity:"error",onClose:()=>f(null),children:C}),o&&e.jsx(se,{variant:"contained",loading:l.isPending,onClick:P,disabled:!d,fullWidth:!0,children:g?"Reenviar certificado":"Enviar certificado"})]}
1),e.jsx(N,{anchorEl:b,open:!!b,onClose:()=>h(null),children:e.jsxs(Q,{onClick:()=>{h(null),u(!0)},sx:{color:"error.main"},children:[e.jsx(W,{sx:{color:"inherit"},children:e.jsx(re,{fontSize:"small"})}),e.jsx(O,{children:"Remover certificado"})]})}),e.jsxs(X,{open:L,onClose:()=>u(!1),children:[e.jsx(Y,{children:"Remover certificado"}),e.jsx(Z,{children:e.jsx(G,{children:"Tem certeza que deseja remover o certificado digital? Você não poderá emitir notas fiscais até enviar um novo certificado."})}),e.jsxs(H,{children:[e.jsx(R,{onClick:()=>u(!1),children:"Cancelar"}),e.jsx(R,{onClick:V,color:"error",disabled:s.isPending,children:"Remover"})]})]})]})};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.