1import{be as M,bd as W,aU as n,a as u,aI as e}from"./index-Cgggh05U.js";/* empty css */function X({onLogin:b}){const{token:r}=M(),v=W(),k=n.useRef(null),[o,h]=n.useState("loading"),[f,$]=n.useState(null),[D,H]=n.useState(!1),[c,t]=n.useState(""),[C,P]=n.useState([]),[m,p]=n.useState(null),[d,A]=n.useState(!1),[R,j]=n.useState(!1),[O,N]=n.useState(null),[i,F]=n.useState(""),[g,J]=n.useState(""),[U,x]=n.useState(!1),[w,L]=n.useState(null);n.useEffect(()=>{fetch(`${u}/api/funnel/preview/${r}`).then(a=>{if(a.status===410)return H(!0),h("expired"),null;if(!a.ok)throw new Error("Invalid link");return a.json()}).then(a=>{a&&($(a),h("password"))}).catch(()=>{t("Invalid or expired claim link."),h("error")})},[r]);const y=()=>{const a={"Content-Type":"application/json"},s=localStorage.getItem("token");return s&&(a.Authorization=`Bearer ${s}`),a},I=async(a={token:r})=>{P([]),p(null),N(null),A(!0),t("");try{const l=await(await fetch(`${u}/api/funnel/generate-headshots`,{method:"POST",headers:y(),body:JSON.stringify(a)})).json();l.success&&l.images&&P(l.images)}catch(s){console.error("Failed to generate headshots:",s)}A(!1)},B=async a=>{p(a.id),N(null),t("");try{await fetch(`${u}/api/funnel/select-headshot`,{method:"POST",headers:y(),body:JSON.stringify({token:r,imageId:a.id})})}catch(s){console.error("Failed to select headshot:",s)}},G=async a=>{const s=a.target.files?.[0];if(s){if(!s.type.startsWith("image/")){t("Please upload an image file");return}if(s.size>10*1024*1024){t("Image must be under 10MB");return}j(!0),t(""),p(null);try{const l=new FileReader;l.onload=async()=>{const z=l.result,S=await(await fetch(`${u}/api/funnel/upload-headshot`,{method:"POST",headers:y(),body:JSON.stringify({token:r,imageData:z})})).json();S.success?(N(S.url),p("upload")):t(S.error||"Upload failed"),j(!1)},l.readAsDataURL(s)}catch{t("Upload failed. Please try again."),j(!1)}}},K=()=>{b&&w?.token&&b(w.token,w.user||JSON.parse(localStorage.getItem("user"))),v("/avatars")},Y=()=>{m&&K()},q=()=>I({token:r,regenerate:!0}),T=async()=>{if(t(""),i.length<6){t("Password must be at least 6 characters");return}if(i!==g){t("Passwords do not match");return}x(!0);try{const a=await fetch(`${u}/api/funnel/claim`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:r,password:i})}),s=await a.json();if(!a.ok){t(s.error||"Something went wrong"),x(!1);return}window.fbq&&window.fbq("track","CompleteRegistration"),s.token&&(localStorage.setItem("token",s.token),localStorage.setItem("user",JSON.stringify(s.user))),L(s),x(!1),h("headshots"),I()}catch{t("Network error. Please try again."),x(!1)}},E=a=>{a.key==="Enter"&&i&&g&&T()};return o==="loading"?e.jsx("div",{className:"funnel-page",children:e.jsx("div",{className:"funnel-loading",children:"Loading your artist..."})}):o==="expired"||D?e.jsx("div",{className:"funnel-page",children:e.jsxs("div",{className:"funnel-slide funnel-reveal",children:[e.jsx("h2",{children:"Link Expired"}),e.jsx("p",{className:"funnel-subtitle",children:"This claim link has expired. Create a new artist to get started."}),e.jsx("button",{className:"funnel-start-btn",onClick:()=>v("/register"),children:"Create New Artist"})]})}):o==="error"?e.jsx("div",{className:"funnel-page",children:e.jsxs("div",{className:"funnel-slide funnel-reveal",children:[e.jsx("h2",{children:"Something went wrong"}),e.jsx("p",{className:"funnel-subtitle",children:c}),e.jsx("button",{className:"funnel-start-btn",onClick:()=>v("/register"),children:"Start Over"})]})}):o==="headshots"?e.jsx("div",{className:"funnel-page",children:e.jsx("div",{className:"funnel-slides",children:e.jsxs("div",{className:"funnel-slide",children:[e.jsxs("h2",{children:["Choose a look for ",f?.avatar?.name||"your artist"]}),e.jsx("p",{className:"funnel-subtitle",children:d?"Generating options...":"Pick the one that feels right, or upload your own"}),e.jsxs("div",{className:"claim-headshot-grid",children:[d&&C.length===0&&e.jsx(e.Fragment,{children:[0,1,2,3,4].map(a=>e.jsx("div",{className:"claim-headshot-card claim-headshot-loading",children:e.jsx("div",{className:"claim-headshot-shimmer"})},a))}),C.map(a=>e.jsx("div",{className:`claim-headshot-card ${m===a.id?"selected":""}`,onClick:()=>B(a),children:e.jsx("img",{src:a.url,alt:"Headshot option"})},a.id)),e.jsxs("div",{className:`claim-headshot-card claim-headshot-upload ${m==="upload"?"selected":""}`,onClick:()=>k.current?.click(),children:[O?e.jsx("img",{src:O,alt:"Your upload"}):e.jsxs("div",{className:"claim-upload-placeholder",children:[e.jsx("div",{className:"claim-upload-icon",children:"+"}),e.jsx("span",{children:R?"Uploading...":"Upload Your Own"})]}),e.jsx("input",{ref:k,type:"file",accept:"image/*",onChange:G,style:{display:"none"}})]})]}),c&&e.jsx("div",{className:"funnel-error",children:c}),e.jsxs("div",{className:"funnel-nav",style:{marginTop:"20px"},children:[e.jsx("button",{className:"funnel-btn funnel-btn-back",onClick:q,disabled:d,children:d?"Generating...":"Create a New Look"}),e.jsx("button",{className:"funnel-btn funnel-btn-next",disabled:!m||d,onClick:Y,children:"Use This Look"})]})]})})}):o==="password"?e.jsx("div",{className:"funnel-page",children:e.jsx("div",{className:"funnel-slides",children:e.jsxs("div",{className:"funnel-slide funnel-reveal",children:[e.jsxs("h2",{children:["Claim ",f?.avatar?.name||"Your Artist"]}),e.jsx("p",{className:"funnel-subtitle",children:"Set a password to activate your account"}),e.jsxs("div",{className:"funnel-reveal-card",children:[e.jsx("div",{className:"funnel-reveal-avatar",children:"ð¤"}),e.jsx("div",{className:"funnel-reveal-name",children:f?.avatar?.name}),e.jsx("div",{className:"funnel-reveal-meta",children:f?.avatar?.genre}),e.jsxs("div",{className:"funnel-reveal-check",children:[e.jsx("input",{className:"funnel-input",type:"password",placeholder:"Create a password",value:i,onChange:a=>{F(a.target.value),t("")},onKeyDown:E,style:{marginBottom:"10px",width:"100%"},autoFocus:!0}),e.jsx("input",{className:"funnel-input",type:"password",placeholder:"Confirm password",value:g,onChange:a=>{J(a.target.value),t("")},onKeyDown:E,style:{width:"100%"}}),c&&e.jsx("div",{className:"funnel-error",children:c}),e.jsx("button",{className:"funnel-btn funnel-btn-next",style:{width:"100%",marginTop:"16px"},onClick:()=>T(),disabled:U||!i||!g,children:U?"Activating...":"Activate & Continue"})]})]})]})})}):null}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.