1import{j as s}from"./vendor-query-CDWquNOr.js";import{u as _,r as o,L as k}from"./vendor-react-kb4SOhqU.js";import{O as T}from"./OnboardingChoiceDialog-D1ul0Lzz.js";import{u as L,N as O,C as q,k as I,i as U,f as D,P as A,B as F,s as a,J as t,v as B,l as J}from"./index-Dal2VKqF.js";import{a as R,i as H,r as M}from"./talentRouting-DyRY6cRD.js";import{r as Z}from"./companyRouting-BiYkQEc4.js";import"./vendor-icons-DPyBaExq.js";import"./vendor-supabase-D0XKNO17.js";import"./vendor-radix-CqRzJ76P.js";import"./vendor-charts-CSz2-Rta.js";import"./vendor-stripe-BKT3e942.js";import"./vendor-media-BBVX24IF.js";import"./vendor-markdown-DwPMj3Qf.js";import"./vendor-motion-DW9K_eHB.js";const ne=()=>{const p=_(),[n,v]=o.useState(""),[m,y]=o.useState(""),[w,i]=o.useState(!1),[j,f]=o.useState(!1),{t:r}=L();o.useEffect(()=>{(async()=>{const{data:{session:d}}=await a.auth.getSession();if(!d){t.error("Invalid or expired reset link. Please request a new one.");return}})()},[]);const C=async h=>{var g;if(h.preventDefault(),n!==m){t.error(r("auth.passwords.no.match"));return}const d=B(n);if(!d.ok){t.error(J(d.errors,"es")||"Invalid password");return}if(i(!0),window.passwordUpdateInProgress){i(!1);return}window.passwordUpdateInProgress=!0;try{const{data:{session:e}}=await a.auth.getSession();if(!(e!=null&&e.user))throw new Error("No active user session found");const N=a.auth.updateUser({password:n}),S=new Promise((b,c)=>setTimeout(()=>c(new Error("Password update timeout after 15 seconds")),15e3)),{data:z,error:l}=await Promise.race([N,S]);if(l)throw l.message.includes("New password should be different from the old password")?new Error("Please enter a different password from your current one."):l;t.success("Password updated successfully!");const{error:x}=await a.from("profiles").update({set_up_password:!0,updated_at:new Date().toISOString()}).eq("id",e.user.id);x&&console.error("Error updating user profile:",x),t.success("Password updated successfully! Redirecting..."),i(!1);const{data:u}=await a.from("profiles").select("user_type").eq("id",e.user.id).single(),P=(u==null?void 0:u.user_type)||((g=e.user.user_metadata)==null?void 0:g.user_type);if(P==="talent"){const{data:b}=await a.from("challenge_participants").select("id, challenges!inner(slug)").eq("user_id",e.user.id).eq("challenges.slug","moeve-innovation-challenge").maybeSingle(),{data:c}=await a.from("talent").select("*, talent_education(id)").eq("id",e.user.id).maybeSingle();if(!R(c)&&H(e.user)){f(!0);return}const E=M(e.user,c,{isEventParticipant:!!b});setTimeout(()=>{p(E)},1e3)}else setTimeout(P==="company"?()=>{p(Z())}:()=>{window.location.href="/"},1e3)}catch(e){console.error("Password update error:",e),t.error((e==null?void 0:e.message)||"An unexpected error occurred during password update"),i(!1)}finally{window.passwordUpdateInProgress=!1}};return s.jsxs(s.Fragment,{children:[s.jsx(O,{}),s.jsx("div",{className:"min-h-screen resend-spotlight flex items-center justify-center px-4",children:s.jsx("div",{className:"max-w-md w-full",children:s.jsxs(q,{className:"bento-card border-white/[0.08]",children:[s.jsxs(I,{className:"text-center",children:[s.jsx(k,{to:"/",className:"flex items-center justify-center mb-4",children:s.jsx("img",{src:"/lovable-uploads/4e58b65e-1cfd-49f0-b0e4-3b8bcf69faac.png",alt:"Zetta",className:"h-12 w-auto object-contain"})}),s.jsx(U,{className:"text-white text-2xl",children:r("auth.new.password")})]}),s.jsx(D,{className:"space-y-4",children:s.jsxs("form",{onSubmit:C,className:"space-y-4",children:[s.jsx(A,{password:n,confirmPassword:m,onPasswordChange:v,onConfirmPasswordChange:y,variant:"dark",hideLabels:!0,passwordPlaceholder:r("auth.new.password.placeholder"),confirmPlaceholder:r("auth.confirm.password.placeholder"),idPrefix:"setpw"}),s.jsx(F,{type:"submit",disabled:w,className:"w-full metallic-silver-gradient text-white hover:bg-gray-900",children:r(w?"status.loading":"auth.update.password")})]})})]})})}),s.jsx(T,{open:j,onOpenChange:f})]})};export{ne 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.