1import{r as N,j as e}from"./vendor-react-O1HtssjF.js";import{u as V,t as E}from"./zod-x2fijbHw.js";import{u as P,b as w}from"./vendor-query-C57Ujfuk.js";import{u as S,d as D,q as g,e as F,C as f,I as c,B as I}from"./index-DE-2a8lD.js";import{g as L}from"./error-messages-izhQU6MT.js";import{L as v,y as $,H as B}from"./vendor-icons-2dxAfxR_.js";import{s as d,o as W}from"./types-BRLVQyzh.js";import"./vendor-radix-Cn4zZLa9.js";import"./vendor-datefns-RsZNnTnu.js";import"./vendor-openai-PX4_LG7y.js";(function(){try{var s=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},i=new s.Error().stack;i&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[i]="9684846e-e4df-441e-8cbe-a57fcef62ab8",s._sentryDebugIdIdentifier="sentry-dbid-9684846e-e4df-441e-8cbe-a57fcef62ab8")}catch{}})();const T=d().optional().transform(s=>s?s.replace(/\D/g,""):"").refine(s=>s===""||s.length===11,"CPF deve ter 11 dÃgitos"),q=d().optional().transform(s=>s?s.replace(/\D/g,""):"").refine(s=>s===""||s.length===8,"CEP deve ter 8 dÃgitos"),z=W({name:d().min(3,"Nome completo deve ter pelo menos 3 caracteres"),cpf:T,cep:q,street:d().optional().default(""),number:d().optional().default(""),complement:d().optional().default(""),neighborhood:d().optional().default(""),city:d().optional().default(""),state:d().optional().default("")});function J(){const[,s]=S(),{toast:i}=D(),[r,h]=N.useState(!1),{data:x,isLoading:j}=P({queryKey:["/api/client/me"],retry:!1}),t=V({resolver:E(z),defaultValues:{name:"",cpf:"",cep:"",street:"",number:"",complement:"",neighborhood:"",city:"",state:""}}),a=x;a&&!t.formState.isDirty&&(a.name&&!a.name.startsWith("pending-")&&t.setValue("name",a.name),a.cpf&&!a.cpf.startsWith("pending-")&&t.setValue("cpf",a.cpf),a.cep&&t.setValue("cep",b(a.cep)),a.street&&t.setValue("street",a.street),a.number&&t.setValue("number",a.number),a.complement&&t.setValue("complement",a.complement),a.neighborhood&&t.setValue("neighborhood",a.neighborhood),a.city&&t.setValue("city",a.city),a.state&&t.setValue("state",a.state));const p=w({mutationFn:async o=>(await F("PUT","/api/client/complete-registration",o)).json(),onSuccess:()=>{i({title:"Cadastro completo!",description:"Seus dados foram salvos com sucesso."}),g.invalidateQueries({queryKey:["/api/auth/user"]}),g.invalidateQueries({queryKey:["/api/client/me"]});const l=new URLSearchParams(window.location.search).get("plan");s(l?`/assinatura?plan=${l}`:"/painel")},onError:o=>{i({title:"Erro ao salvar",description:L(o),variant:"destructive"})}}),y=async o=>{const l=o.replace(/\D/g,"");if(l.length===8){h(!0),t.setValue("street",""),t.setValue("neighborhood",""),t.setValue("city",""),t.setValue("state","");try{const m=await fetch(`/api/cep/${l}`);if(m.ok){const u=await m.json();t.setValue("street",u.logradouro||""),t.setValue("neighborhood",u.bairro||""),t.setValue("city",u.localidade||""),t.setValue("state",u.uf||""),i({title:"Endereço encontrado!",description:"Os campos foram preenchidos automaticamente. Você pode editá-los se necessário."})}else m.status===404?i({title:"CEP não encontrado",description:"Não foi possÃvel localizar o endereço. Preencha os campos manualmente.",variant:"destructive"}):i({title:"Erro ao consultar CEP",description:"Ocorreu um erro. Preencha os campos manualmente.",variant:"destructive"})}catch(m){console.error("Error fetching CEP:",m),i({title:"Erro de conexão",description:"Não foi possÃvel consultar o CEP. Preencha os campos manualmente.",variant:"destructive"})}finally{h(!1)}}},C=o=>{p.mutate(o)};if(j)return e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(v,{className:"h-8 w-8 animate-spin"})});const n=t.formState.errors;return e.jsx("div",{style:{minHeight:"100vh",background:"var(--v2-surface-sunken)",display:"flex",alignItems:"center",justifyContent:"center",padding:16},children:e.jsx("div",{style:{width:"100%",maxWidth:640},children:e.jsxs(f,{children:[e.jsxs(f.Header,{style:{flexDirection:"column",alignItems:"flex-start",gap:4},children:[e.jsx("span",{style:{fontSize:18,fontWeight:600,color:"var(--v2-text-strong)",letterSpacing:"-0.015em"},children:"Complete seu Cadastro"}),e.jsx("span",{style:{fontSize:13,fontWeight:400,color:"var(--v2-text-muted)",lineHeight:1.5},children:"Confirme seu nome para começar. CPF e endereço são opcionais e só ficarão obrigatórios ao assinar um plano pago (para emissão de nota fiscal)."})]}),e.jsx(f.Body,{children:e.jsxs("form",{onSubmit:t.handleSubmit(C),className:"v2-col v2-gap-6",children:[e.jsxs("section",{className:"v2-col v2-gap-4",children:[e.jsxs("div",{className:"v2-row v2-gap-2",style:{alignItems:"center",fontSize:15,fontWeight:600,color:"var(--v2-text-strong)"},children:[e.jsx($,{className:"h-4 w-4"}),e.jsx("span",{children:"Dados Pessoais"})]}
1),e.jsxs("div",{className:"v2-grid-2",children:[e.jsxs("div",{className:"v2-field",style:{gridColumn:"1 / -1"},children:[e.jsx("label",{className:"v2-field-label",htmlFor:"field-name",children:"Nome Completo"}),e.jsx(c,{id:"field-name",...t.register("name"),placeholder:"Seu nome completo",error:!!n.name,"data-testid":"input-name"}),n.name&&e.jsx("span",{className:"v2-field-error",children:n.name.message})]}),e.jsxs("div",{className:"v2-field",children:[e.jsx("label",{className:"v2-field-label",htmlFor:"field-cpf",children:"CPF (opcional)"}),e.jsx(c,{id:"field-cpf",...t.register("cpf"),placeholder:"000.000.000-00",maxLength:14,error:!!n.cpf,onChange:o=>{const l=U(o.target.value);t.setValue("cpf",l,{shouldDirty:!0})},"data-testid":"input-cpf"}),n.cpf&&e.jsx("span",{className:"v2-field-error",children:n.cpf.message})]})]})]}),e.jsxs("section",{className:"v2-col v2-gap-4",children:[e.jsxs("div",{className:"v2-row v2-gap-2",style:{alignItems:"center",fontSize:15,fontWeight:600,color:"var(--v2-text-strong)"},children:[e.jsx(B,{className:"h-4 w-4"}),e.jsx("span",{children:"Endereço"})]}),e.jsxs("div",{className:"v2-callout v2-info",children:[e.jsx("span",{className:"v2-callout-icon",children:"i"}),e.jsx("span",{children:"Informe o CEP para preenchermos o endereço automaticamente. Todos os campos abaixo são opcionais."})]}),e.jsxs("div",{className:"v2-grid-3",children:[e.jsxs("div",{className:"v2-field",children:[e.jsx("label",{className:"v2-field-label",htmlFor:"field-cep",children:"CEP (opcional)"}),e.jsx(c,{id:"field-cep",...t.register("cep"),placeholder:"00000-000",maxLength:9,error:!!n.cep,rightIcon:r?e.jsx(v,{className:"h-4 w-4 animate-spin"}):void 0,onChange:o=>{const l=b(o.target.value);t.setValue("cep",l,{shouldDirty:!0})},onBlur:o=>{y(o.target.value)},"data-testid":"input-cep"}),n.cep&&e.jsx("span",{className:"v2-field-error",children:n.cep.message})]}),e.jsxs("div",{className:"v2-field",style:{gridColumn:"span 2"},children:[e.jsx("label",{className:"v2-field-label",htmlFor:"field-street",children:"Rua (opcional)"}),e.jsx(c,{id:"field-street",...t.register("street"),placeholder:r?"Buscando...":"Nome da rua",disabled:r,"data-testid":"input-street"})]}),e.jsxs("div",{className:"v2-field",children:[e.jsx("label",{className:"v2-field-label",htmlFor:"field-number",children:"Número (opcional)"}),e.jsx(c,{id:"field-number",...t.register("number"),placeholder:"123","data-testid":"input-number"})]}),e.jsxs("div",{className:"v2-field",style:{gridColumn:"span 2"},children:[e.jsx("label",{className:"v2-field-label",htmlFor:"field-complement",children:"Complemento (opcional)"}),e.jsx(c,{id:"field-complement",...t.register("complement"),placeholder:"Apto, Bloco, etc.","data-testid":"input-complement"})]}),e.jsxs("div",{className:"v2-field",children:[e.jsx("label",{className:"v2-field-label",htmlFor:"field-neighborhood",children:"Bairro (opcional)"}),e.jsx(c,{id:"field-neighborhood",...t.register("neighborhood"),placeholder:r?"Buscando...":"Nome do bairro",disabled:r,"data-testid":"input-neighborhood"})]}),e.jsxs("div",{className:"v2-field",children:[e.jsx("label",{className:"v2-field-label",htmlFor:"field-city",children:"Cidade (opcional)"}),e.jsx(c,{id:"field-city",...t.register("city"),placeholder:r?"Buscando...":"Nome da cidade",disabled:r,"data-testid":"input-city"})]}),e.jsxs("div",{className:"v2-field",children:[e.jsx("label",{className:"v2-field-label",htmlFor:"field-state",children:"Estado (opcional)"}),e.jsx(c,{id:"field-state",...t.register("state"),placeholder:r?"...":"UF",disabled:r,maxLength:2,onChange:o=>{t.setValue("state",o.target.value.toUpperCase(),{shouldDirty:!0})},"data-testid":"input-state"})]})]})]}),e.jsx(I,{type:"submit",size:"lg",fullWidth:!0,loading:p.isPending,disabled:p.isPending,"data-testid":"button-submit-registration",children:p.isPending?"Salvando...":"Completar Cadastro"})]})})]})})})}function U(s){return s.replace(/\D/g,"").slice(0,11).replace(/(\d{3})(\d)/,"$1.$2").replace(/(\d{3})(\d)/,"$1.$2").replace(/(\d{3})(\d{1,2})$/,"$1-$2")}function b(s){return s.replace(/\D/g,"").slice(0,8).replace(/(\d{5})(\d)/,"$1-$2")}export{J as default}; 2//# sourceMappingURL=completar-cadastro-fMVCBrUR.js.map
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.