import"./hoisted.yFz1BYXO.js";const c=window.__PW_API,l=new URLSearchParams(window.location.search),r=l.get("token");function n(a){["state-loading","state-invalid","state-success","reset-form"].forEach(t=>document.getElementById(t)?.classList.toggle("hidden",t!==a))}n(r?"reset-form":"state-invalid");document.getElementById("reset-form")?.addEventListener("submit",async a=>{a.preventDefault();const t=document.getElementById("new-password").value,i=document.getElementById("confirm-password").value,e=document.getElementById("reset-err"),s=document.getElementById("reset-btn");if(e.classList.add("hidden"),t.length<8){e.textContent="Password must be at least 8 characters.",e.classList.remove("hidden");return}if(t!==i){e.textContent="Passwords don't match.",e.classList.remove("hidden");return}s.disabled=!0,s.textContent="Saving…";try{const o=await fetch(`${c}/api/v1/auth/reset-password`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:r,password:t})}),d=await o.json();o.ok?(n("state-success"),d.customer&&window.dispatchEvent(new CustomEvent("pw:auth",{detail:d.customer})),setTimeout(()=>{window.location.href="/"},2500)):(e.textContent=d.error||"Reset failed. Please request a new link.",e.classList.remove("hidden"),s.disabled=!1,s.textContent="Set new password",o.status===400&&n("state-invalid"))}catch{e.textContent="Network error. Please try again.",e.classList.remove("hidden"),s.disabled=!1,s.textContent="Set new password"}});