1import{r as t,j as e}from"./vendor-query-CeYLmLzt.js";import{aU as w,bx as Q,ag as $,at as q,ai as G,b0 as J,a0 as P,a3 as A,a4 as y,U as S,a1 as C,b2 as K,b5 as W,dc as X,N as E,_ as f,O as D,E as T,a5 as Y,s as Z,dd as ee,a as F,P as se,Q as L}from"./index-BBNmkLNV.js";import{L as u}from"./label-Bmwpld-2.js";import{A as ae,a as re,b as te,c as oe,d as ne,e as ie,f as le}from"./alert-dialog-DQYNK3Jp.js";import{a as ce}from"./vendor-react-BPOX-wWs.js";import"./vendor-supabase-Cc8l7PMd.js";import"./vendor-motion-BtWo1fWB.js";const de=Q("relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),O=t.forwardRef(({className:a,variant:n,...s},h)=>e.jsx("div",{ref:h,role:"alert",className:w(de({variant:n}),a),...s}));O.displayName="Alert";const k=t.forwardRef(({className:a,...n},s)=>e.jsx("h5",{ref:s,className:w("mb-1 font-medium leading-none tracking-tight",a),...n}));k.displayName="AlertTitle";const z=t.forwardRef(({className:a,...n},s)=>e.jsx("div",{ref:s,className:w("text-sm [&_p]:leading-relaxed",a),...n}));z.displayName="AlertDescription";const me=se({newPassword:L().min(6,"A nova senha deve ter no mÃnimo 6 caracteres"),confirmPassword:L().min(1,"Confirmação de senha é obrigatória")}).refine(a=>a.newPassword===a.confirmPassword,{message:"As senhas não coincidem",path:["confirmPassword"]});function ve(){$(),ce();const{profile:a,user:n,isPrimeiroAcesso:s,clearPrimeiroAcesso:h,signOut:v}=q(),[j,c]=t.useState(!1),[x,U]=t.useState(!1),[g,M]=t.useState(!1),[R,N]=t.useState(!1),[_,I]=t.useState(""),[d,V]=t.useState({newPassword:"",confirmPassword:""}),[i,p]=t.useState({}),b=(o,m)=>{V(r=>({...r,[o]:m})),i[o]&&p(r=>({...r,[o]:void 0}))},H=async o=>{o.preventDefault(),p({});const m=me.safeParse(d);if(!m.success){const r={};m.error.errors.forEach(l=>{const B=l.path[0];r[B]=l.message}),p(r);return}c(!0);try{const{error:r}=await Z.auth.updateUser({password:d.newPassword});if(r){const l=ee(r.message);I(l),N(!0),c(!1);return}if(s)try{await h(),await v()}catch(l){console.error("Error clearing primeiro_acesso:",l),F.error("Erro ao finalizar configuração. Tente novamente."),c(!1);return}else await v()}catch(r){console.error("Error updating password:",r),F.error("Erro ao alterar senha. Tente novamente.")}finally{c(!1)}};return e.jsxs(G,{children:[e.jsx(ae,{open:R,onOpenChange:N,children:e.jsxs(re,{children:[e.jsxs(te,{children:[e.jsx(oe,{className:"text-destructive",children:"Erro ao alterar senha:"}),e.jsx(ne,{className:"whitespace-pre-line",children:_})]}),e.jsx(ie,{children:e.jsx(le,{children:"Entendi"})})]})}),e.jsxs("div",{className:"space-y-6",children:[s&&e.jsxs(O,{variant:"destructive",className:"border-orange-500 bg-orange-500/10",children:[e.jsx(J,{className:"h-5 w-5 text-orange-500"}),e.jsx(k,{className:"text-orange-600 font-semibold",children:"Primeiro Acesso"}),e.jsx(z,{className:"text-orange-600",children:"Por segurança, você precisa alterar sua senha antes de continuar. Após a alteração, você será redirecionado para fazer login novamente."})]}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(P,{children:[e.jsx(A,{children:e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(S,{className:"h-5 w-5"}),"Informações do Usuário"]})}),e.jsxs(C,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{className:"text-muted-foreground",children:"Nome"}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted/50 rounded-md",children:[e.jsx(S,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:a?.full_name||"Não informado"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{className:"text-muted-foreground",children:"E-mail"}),e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-muted/50 rounded-md",children:[e.jsx(K,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"font-medium",children:n?.email||a?.email||"Não informado"})]})]})]})]}),e.jsxs(P,{className:s?"ring-2 ring-orange-500":"",children:[e.jsxs(A,{children:[e.jsxs(y,{className:"flex items-center gap-2",children:[e.jsx(W,{className:"h-5 w-5"}),s?"Alterar Senha (Obrigatório)":"Alterar Senha"]}),s&&e.jsx(X,{children:"Você precisa definir uma nova senha para continuar"})]}),e.jsx(C,{children:e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"newPassword",children:"Nova Senha"}),e.jsxs("div",{className:"relative",children:[e.jsx(E,{id:"newPassword",type:x?"text":"password",value:d.newPassword,onChange:o=>b("newPassword",o.target.value),className:i.newPassword?"border-destructive":"",placeholder:"Digite sua Nova Senha",autoF
1ocus:s}),e.jsx(f,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",onClick:()=>U(!x),children:x?e.jsx(D,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(T,{className:"h-4 w-4 text-muted-foreground"})})]}),i.newPassword&&e.jsx("p",{className:"text-sm text-destructive",children:i.newPassword})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(u,{htmlFor:"confirmPassword",children:"Confirmar Nova Senha"}),e.jsxs("div",{className:"relative",children:[e.jsx(E,{id:"confirmPassword",type:g?"text":"password",value:d.confirmPassword,onChange:o=>b("confirmPassword",o.target.value),className:i.confirmPassword?"border-destructive":"",placeholder:"Confirme sua Nova Senha"}),e.jsx(f,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",onClick:()=>M(!g),children:g?e.jsx(D,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(T,{className:"h-4 w-4 text-muted-foreground"})})]}),i.confirmPassword&&e.jsx("p",{className:"text-sm text-destructive",children:i.confirmPassword})]}),e.jsx(f,{type:"submit",className:`w-full ${s?"bg-orange-600 hover:bg-orange-700":""}`,disabled:j,children:j?"Alterando...":e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"h-4 w-4 mr-2"}),s?"Alterar Senha e Fazer Login":"Salvar Nova Senha"]})})]})})]})]})]})]})}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.