1import{j as e}from"./ui-CMTTTAxa.js";import{u as B,f as O,a}from"./vendor-BDindXV3.js";import{s as u,L as R,H as I,j as U,h as T}from"./index-Bqrg_C6x.js";import{S as Y}from"./shield-check-DrsOzGGv.js";import"./supabase-Czj9ajwo.js";const H="#070f1c",q="#0f1a2e",N="#1a2942",b="#5BC8E8",w="#e8f1fb",l="#7088a8";function G(){const n=new URLSearchParams(window.location.hash.replace(/^#/,"")),f=new URLSearchParams(window.location.search);return n.get("error_code")||n.get("error")||f.get("error_code")||null}function X(){var P;const n=B(),[f]=O(),S=(t,s)=>!!t&&!t.startsWith("//")&&(t===s||t.startsWith(`${s}?`)||t.startsWith(`${s}/`)),x=f.get("next"),c=S(x,"/affiliate"),j=S(x,"/portal")||c?x:null,[y,L]=a.useState(""),[h,W]=a.useState(!1),[g,p]=a.useState(!1),[k,m]=a.useState(""),[_]=a.useState(G),[d,v]=a.useState(void 0),[C,z]=a.useState("");a.useEffect(()=>{let t=!1;u.auth.getSession().then(({data:r})=>{var o,i;t||(v((r==null?void 0:r.session)??null),(i=(o=r==null?void 0:r.session)==null?void 0:o.user)!=null&&i.email&&z(r.session.user.email))});const{data:s}=u.auth.onAuthStateChange((r,o)=>{var i;t||(v(o||null),(i=o==null?void 0:o.user)!=null&&i.email&&z(o.user.email))});return()=>{var r;t=!0,(r=s==null?void 0:s.subscription)==null||r.unsubscribe()}},[]);async function F(t){if(t.preventDefault(),y.length<8){m("Password must be at least 8 characters.");return}p(!0),m("");const{error:s}=await u.auth.updateUser({password:y});if(s){p(!1),m(s.message||"Could not set your password.");return}const{error:r}=await u.rpc("mark_my_password_set");r&&console.error("[SetPassword] mark_my_password_set:",r.message);const o=c?"claim_my_affiliate_record":"claim_my_client_record",{error:i}=await u.rpc(o);i&&console.error(`[SetPassword] ${o}:`,i.message),p(!1),n(j||"/",{replace:!0})}async function $(){p(!0);const t=c?"claim_my_affiliate_record":"claim_my_client_record",{error:s}=await u.rpc(t);s&&console.error(`[SetPassword] ${t}:`,s.message),p(!1),n(j||"/",{replace:!0})}const A=!!((P=d==null?void 0:d.user)!=null&&P.created_at)&&Date.now()-new Date(d.user.created_at).getTime()>3600*1e3,E=!!_||d===null;return e.jsx("div",{style:{minHeight:"100vh",background:H,display:"grid",placeItems:"center",padding:20},children:e.jsxs("div",{style:{width:"100%",maxWidth:420,background:q,border:`1px solid ${N}`,borderRadius:14,padding:26},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:9,marginBottom:6},children:[e.jsx(Y,{size:18,style:{color:b}}),e.jsx("h1",{style:{fontSize:17,fontWeight:700,color:w,margin:0},children:"Set your password"})]}),!_&&d===void 0&&e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,padding:"18px 0",color:l,fontSize:13},children:[e.jsx(R,{size:15,className:"animate-spin",style:{color:b}})," Checking your linkâ¦"]}),E&&e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{fontSize:13,color:"#f87171",lineHeight:1.6,margin:"10px 0 12px"},children:"This link has expired or has already been used."}),e.jsx("p",{style:{fontSize:12.5,color:l,lineHeight:1.6,margin:"0 0 16px"},children:"Open your Closehaul Capital portal email again and click its button â it opens a fresh link every time. If you were resetting your password, request a new link with âForgot passwordâ on the sign-in page."}),e.jsx(I,{text:c?"Opens the partner portal sign-in page.":"Opens the client portal sign-in page.",children:e.jsx("button",{onClick:()=>n(c?"/login?portal=affiliate":"/login?portal=client"),style:D(!0),children:"Go to sign in"})}),e.jsx("p",{style:{fontSize:12,color:l,margin:"12px 0 0",lineHeight:1.6},children:c?"Still stuck? We can send you a new partner portal link.":"Still stuck? Your Loan Expert can send you a new invite."})]}),!E&&d&&e.jsxs("form",{onSubmit:F,style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsxs("p",{style:{fontSize:12.5,color:l,lineHeight:1.6,margin:"4px 0 0"},children:["Choose a password for ",C?e.jsx("strong",{style:{color:w},children:C}):"your account",". Youâll use it to sign in to your Closehaul Capital ",c?"partner portal":"portal","."]}),e.jsxs("div",{children:[e.jsx("label",{style:{display:"block",fontSize:12,color:l,marginBottom:6},children:"New password"}),e.jsxs("div",{style:{position:"relative"},children:[e.jsx("input",{type:h?"text":"password",value:y,autoComplete:"new-password",placeholder:"Min. 8 characters",onChange:t=>{L(t.target.value),m("")},style:{width:"100%",height:40,padding:"0 42px 0 12px",boxSizing:"border-box",background:H,border:`1px solid ${N}`,borderRadius:9,color:w,fontSize:14,fontFamily:"inherit",outline:"none"}}),e.jsx("button",{type:"button",onClick:()=>W(!h),"aria-label":h?"Hide password":"Show password",style:{position:"absolute",right:10,top:"50%",transform:"translateY(-50%)",background:"transparent",border:"none",color:l,cursor:"pointer",display:"flex"},children:h?e.jsx(U,{size:15}):e.jsx(T,{size:15})})]})]}),k&&e.jsx("p",{style:{fontSize:12,color:"#f87171",margin:0,padding:"8px 10px",borderRadius:8,background:"rgba(239,68,68,0.10)",border:"1px solid rgba(239,68,68,0.3)"},children:k}),e.jsx("button",{type:"submit",disabled:g,style:D(!g),children:g?e.jsxs(e.Fragment,{children:[e.jsx(R,{size:15,className:"animate-spin"})," Savingâ¦"]}):"Set password & continue"}),A&&e.jsx(I,{text:"You're already signed in. Opens your portal without changing your password.",children:e.jsx("button",{type:"button",onClick:$,disabled:g,style:{background:"transparent",border:"none",color:l,fontSize:12.5,cursor:"pointer",fontFamily:"inherit",textDecoration:"underline",padding:4},children:"I already have a password â go to my portal"})})]})]})})}const D=n=>({display:"inline-flex",alignItems:"center",justifyContent:"center",gap:8,width:"100%",height:42,borderRadius:10,border:"none",background:n?b:"#1a2942",color:n?"#042C53":l,fontSize:14,fontWeight:700,fontFamily:"inherit",curs
1or:n?"pointer":"not-allowed"});export{X 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.