1import{__toESM as e}from"./DDUEPe6U.js";import{ErrorBanner as t,SuccessBanner as a,api as s,require_jsx_runtime as r,require_react as n,useLocalStorage as l}from"./Dqgz-G6s.js";var o=e(n(),1),i=e(r(),1);let c=()=>{var e;if("undefined"==typeof window)return!1;if(null==(e=window.Drupal)||null==(e=e.settings)?void 0:e.recaptchaDebug)return!0;try{return new URLSearchParams(window.location.search).has("recaptcha_debug")}catch(e){return!1}},u="debug-invalid-token-should-fail-server-verification",d=new Set(["EM","STRONG","B","I","A"]),m=(e,t)=>{for(let a of e.childNodes)if(a.nodeType===Node.TEXT_NODE)t.push({type:"text",value:a.nodeValue});else if(a.nodeType===Node.ELEMENT_NODE&&d.has(a.tagName)){let e=[];m(a,e);let s=a.tagName.toLowerCase(),r={};if("a"===s){let e=a.getAttribute("href")||"";/^(\/|https?:|mailto:)/i.test(e)&&(r.href=e)}t.push({type:"el",tag:s,props:r,children:e})}else a.nodeType===Node.ELEMENT_NODE&&m(a,t)},p=(e,t="")=>e.map((e,a)=>{let s=`${t}${a}`;if("text"===e.type)return e.value;let r=e.tag;return(0,i.jsx)(r,{...e.props,children:p(e.children,`${s}-`)},s)}),h=e=>{if(!e)return"";if("string"==typeof e){if("string"!=typeof e||!e.includes("<"))return e;let t=document.createElement("div");t.innerHTML=e;let a=[];return m(t,a),p(a)}if(Array.isArray(e)){let t=e.map(h).filter(e=>""!==e&&null!=e);return t.every(e=>"string"==typeof e)?t.join(" "):t.flatMap((e,t)=>0===t?[e]:[" ",e])}return"object"==typeof e?h(Object.values(e)):String(e)},x=e=>{var t,a;let s=null==(t=window.Drupal)?void 0:t.settings;if(!(null==s?void 0:s.recaptchaEnabled))return"off";let r=null==(a=s.recaptchaActions)?void 0:a[e];return void 0===r?"enforce":"enforce"===r||"monitor"===r||"off"===r?r:Number(r)?"enforce":"off"},b=e=>{var t;return e?"off"!==x(e):!!(null==(t=window.Drupal)||null==(t=t.settings)?void 0:t.recaptchaEnabled)},g="recaptcha-script",f="recaptcha-v2-script",v=(e,t)=>new Promise((a,s)=>{var r;if(!(null==(r=window.grecaptcha)?void 0:r.execute))return void s(Error("reCAPTCHA v3 not loaded"));window.grecaptcha.ready(()=>{window.grecaptcha.execute(e,{action:t}).then(a).catch(s)})}),w=({onToken:e,onGiveUp:t,onExpired:a})=>{let s=(0,o.useRef)(null),[r,n]=(0,o.useState)(!1),[l,i]=(0,o.useState)(!1),c=(0,o.useRef)(null),u=(0,o.useRef)(!1),d=(0,o.useRef)({onToken:e,onGiveUp:t,onExpired:a});d.current={onToken:e,onGiveUp:t,onExpired:a};let m=(0,o.useCallback)(()=>{u.current||(u.current=!0,i(!0),n(!1),setTimeout(()=>{var e,t;return null==(e=(t=d.current).onGiveUp)?void 0:e.call(t)},0))},[]),p=(0,o.useCallback)(()=>{var e,t,a;if(u.current)return;if(n(!0),null!==c.current){null==(t=window.grecaptcha)||null==(a=t.reset)||a.call(t,c.current);return}let r=null==(e=window.Drupal)||null==(e=e.settings)?void 0:e.recaptchaKey;if(!r||!s.current)return void m();(()=>{var e;if((null==(e=window.grecaptcha)?void 0:e.render)||document.getElementById(f))return;let t=document.createElement("script");t.id=f,t.src="https://www.google.com/recaptcha/api.js",t.async=!0,document.head.appendChild(t)})();let l=0,o=()=>{var e;if(!u.current){if((null==(e=window.grecaptcha)?void 0:e.render)&&s.current){c.current=window.grecaptcha.render(s.current,{sitekey:r,size:"normal",callback:e=>{var t,a;return null==(t=(a=d.current).onToken)?void 0:t.call(a,e)},"expired-callback":()=>{var e,t;return null==(e=(t=d.current).onExpired)?void 0:e.call(t)}});return}if(++l>=25)return void m();setTimeout(o,200)}};o()},[m]),h=(0,o.useCallback)(()=>{var e,t;null!==c.current&&(null==(e=window.grecaptcha)||null==(t=e.reset)||t.call(e,c.current))},[]),x=(0,o.useCallback)(()=>null!==c.current,[]);return(0,o.useMemo)(()=>({containerRef:s,showV2:r,unavailable:l,show:p,reset:h,rendered:x}),[r,l,p,h,x])},y=e=>e.rendered()?"Please tick the verification box above to continue.":"Still loading verification. Please wait a moment and try again.",j="Verification expired. Please tick the box again.",k="We couldn't verify your browser. Please turn off content blockers for this site or try another browser.",N=({v2:e})=>(0,i.jsxs)("div",{"aria-live":"polite",children:[e.showV2?(0,i.jsx)("p",{className:"text-sm mb-2",children:"Please confirm youâre not a robot to continue."}):null,(0,i.jsx)("div",{ref:e.containerRef,className:"overflow-x-auto"})]}),C=/^[\x80-\xF7 a-z0-9@+_.'-]+$/i,S=e=>e?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?null:"That email address is not val
1id.":"You must enter an email address.",_=({password:e})=>{if(!e)return null;let{score:t,label:a}=(e=>{if(!e)return{score:0,label:""};let t=0;return e.length>=8&&(t+=1),e.length>=12&&(t+=1),/[a-z]/.test(e)&&/[A-Z]/.test(e)&&(t+=1),/\d/.test(e)&&(t+=1),/[^A-Za-z0-9]/.test(e)&&(t+=1),{score:t=Math.min(t,4),label:["Too short","Weak","Fair","Good","Strong"][t]}})(e),s=t<=1?"progress-error":2===t?"progress-warning":3===t?"progress-info":"progress-success";return(0,i.jsxs)("div",{className:"-mt-1 flex items-center gap-2 text-xs",children:[(0,i.jsx)("progress",{className:`progress ${s} h-1.5 flex-1`,value:t,max:"4","aria-label":"Password strength"}),(0,i.jsx)("span",{"aria-live":"polite",className:"w-16 text-right opacity-80",children:a})]})},E=({id:e,title:t,subtitle:a})=>(0,i.jsxs)("div",{className:"mb-4",children:[(0,i.jsx)("h2",{id:e,className:"text-2xl font-bold",children:t}),(0,i.jsx)("p",{className:"text-sm text-base-content/80 mt-1",children:a})]}),$="login",T="register",D="reset",A=({id:e,label:t,type:a="text",value:s,onChange:r,autoComplete:n,required:l=!0,disabled:c=!1,help:u=null})=>{let d=u?`${e}-help`:void 0,m="password"===a,[p,h]=(0,o.useState)(!1),x=m&&p?"text":a;return(0,i.jsxs)("div",{className:"form-control w-full",children:[(0,i.jsx)("label",{className:"label pb-1",htmlFor:e,children:(0,i.jsx)("span",{className:"label-text font-medium whitespace-normal break-words",children:t})}),(0,i.jsxs)("div",{className:"relative",children:[(0,i.jsx)("input",{id:e,type:x,value:s,onChange:e=>r(e.target.value),autoComplete:n,required:l,"aria-required":l||void 0,"aria-describedby":d,disabled:c,className:`input input-bordered w-full ${m?"pr-10":""}`}),m&&(0,i.jsx)("button",{type:"button",onClick:()=>h(e=>!e),disabled:c,"aria-label":p?"Hide password":"Show password","aria-pressed":p,className:"absolute inset-y-0 right-0 z-10 flex items-center px-3 text-base-content/60 hover:text-base-content focus:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-r-md",tabIndex:-1,children:p?(0,i.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"h-4 w-4","aria-hidden":"true",children:[(0,i.jsx)("path",{d:"M17.94 17.94A10.94 10.94 0 0 1 12 20c-7 0-11-8-11-8a21.77 21.77 0 0 1 5.06-5.94"}),(0,i.jsx)("path",{d:"M9.9 4.24A10.94 10.94 0 0 1 12 4c7 0 11 8 11 8a21.83 21.83 0 0 1-3.17 4.19"}),(0,i.jsx)("path",{d:"M14.12 14.12a3 3 0 1 1-4.24-4.24"}),(0,i.jsx)("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}):(0,i.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"h-4 w-4","aria-hidden":"true",children:[(0,i.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),(0,i.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]}),u&&(0,i.jsx)("span",{id:d,className:"text-xs text-base-content/70 mt-1",children:u})]})},R=({id:e,message:a,onResetClick:s})=>{let r=s?e=>{let t=e.target.closest("a");t&&"/user/password"===t.getAttribute("href")&&(e.preventDefault(),s())}:void 0;return(0,i.jsx)("div",{id:e,"aria-live":"polite","aria-atomic":"true",onClick:r,children:(0,i.jsx)(t,{message:a})})},I=({message:e})=>(0,i.jsx)(a,{message:e}),P=({recaptchaV3Key:e,lastOutcome:t,onSimulateBot:a,formName:s,action:r})=>{var n;let[l,u]=(0,o.useState)(()=>{var e;return!!(null==(e=window.grecaptcha)?void 0:e.execute)});if((0,o.useEffect)(()=>{if(!c()||l)return;let e=setInterval(()=>{var t;(null==(t=window.grecaptcha)?void 0:t.execute)&&(u(!0),clearInterval(e))},250);return()=>clearInterval(e)},[l]),!c())return null;let d=(null==(n=window.Drupal)||null==(n=n.settings)?void 0:n.recaptchaKey)||null,m=x(r),p="off"!==m,h=(e,t,a)=>(0,i.jsxs)("div",{className:"flex justify-between gap-2",children:[(0,i.jsx)("span",{className:"opacity-70",children:e}),(0,i.jsx)("span",{className:!1===a?"text-error":!0===a?"text-success":"",children:t})]});return(0,i.jsxs)("div",{className:"mt-3 rounded border border-base-300 bg-base-200 p-3 text-xs font-mono",children:[(0,i.jsxs)("div",{className:"font-bold mb-1",children:["reCAPTCHA debug â ",s]}),h("mode",m,p),h("v3 site key",e?`${e.slice(0,10)}â¦`:"not set",p?!!e:void 0),h("v3 script loaded",l?"yes":"no",p?l:void 0),h("v2 fallback key",d?`${d.slice(0,10)}â¦`:"not set",p?!!d:void 0),t&&(0,i.jsxs)("div",{className:"mt-2 pt-2 border-t border-base-300",children:[(0,i.jsx)("div",{className:"font-bold mb-1",children:"last submit"}),h("path",t.path),h("token",t.token?`${t.token.slice(0,20)}â¦`:"(empty)"),h("status",t.status,t.ok),null!=t.reason&&h("server reason",t.reason,!1),null!=t.score&&h("server score",t.score),t.message&&h("message",t.message)]}),(0,i.jsx)("button",{type:"button",className:"btn btn-xs btn-warning mt-2 w-full",onClick:a,children:"Simulate bot (send invalid token)"})]})},L=({titleId:e,onSuccess:t,onForgotPassword:a,recaptchaV3Key:r,initialUsername:n="",notice:l="",subtitle:c})=>{let d=(0,o.useId)(),m=b("login"),p="enforce"===x("login"),[g,f]=(0,o.useState)(n),[k,C]=(0,o.useState)("");(0,o.useEffect)(()=>{var e;
1n&&(f(n),null==(e=document.getElementById(`${d}-password`))||e.focus())},[n,d]);let[S,_]=(0,o.useState)(!0),[$,T]=(0,o.useState)(""),[D,I]=(0,o.useState)(!1),[L,B]=(0,o.useState)(null),M=w({onToken:e=>V(e),onGiveUp:()=>V(""),onExpired:()=>T(j)}),V=(0,o.useCallback)(async e=>{var a,n,l,o,i;T(""),I(!0);try{let r=await s.post("/api/dante/user/login",{json:{username:g,password:k,remember_me:S,recaptcha:e}}).json();(null==r?void 0:r.token)&&(window.Drupal.settings.servicesToken=r.token),(null==r?void 0:r.user)&&(window.Drupal.settings.user={uid:r.user.uid,name:r.user.name,roles:r.user.roles,stream_services:null!=(a=null==(n=window.Drupal.settings.user)?void 0:n.stream_services)?a:[]}),B({path:"/api/dante/user/login",token:e,status:"ok",ok:!0}),document.dispatchEvent(new CustomEvent("rifftrax:userLoggedIn",{detail:r})),null==t||t(r)}catch(s){let t=await (null==(l=s.response)||null==(o=l.json)?void 0:o.call(l).catch(()=>null)),a=h(null==t?void 0:t.message)||h(null==t?void 0:t.form_errors);T(a||"Login failed. Please check your username and password."),B({path:"/api/dante/user/login",token:e,status:(null==(i=s.response)?void 0:i.status)||"error",ok:!1,message:a,reason:null==t?void 0:t.recaptcha_reason,score:null==t?void 0:t.recaptcha_score}),p&&r&&(null==t?void 0:t.recaptcha_reason)?M.show():M.reset()}finally{I(!1)}},[g,k,S,p,r,t,M]),q=(0,o.useCallback)(async e=>{if(e.preventDefault(),T(""),!m||M.unavailable)return void await V("");if(M.showV2)return void T(y(M));if(r)try{let e=await v(r,"login");await V(e)}catch(e){if(!p)return void await V("");M.show()}else await V("")},[m,p,M,r,V]);return(0,i.jsxs)("form",{onSubmit:q,noValidate:!0,children:[(0,i.jsx)(E,{id:e,title:"Welcome back!",subtitle:c||"Access your Library, Watch List, and personalized riff picks."}),(0,i.jsxs)("div",{className:"flex flex-col gap-3",children:[l?(0,i.jsx)("output",{className:"alert alert-info text-sm py-2 block","aria-live":"polite",children:l}):null,(0,i.jsx)(A,{id:`${d}-username`,label:"Email address (or username)",value:g,onChange:f,autoComplete:"username",disabled:D}),(0,i.jsx)(A,{id:`${d}-password`,label:"Password",type:"password",value:k,onChange:C,autoComplete:"current-password",disabled:D}),(0,i.jsxs)("label",{className:"label cursor-pointer justify-start gap-2 py-1",children:[(0,i.jsx)("input",{type:"checkbox",checked:S,onChange:e=>_(e.target.checked),disabled:D,className:"checkbox checkbox-sm checkbox-primary"}),(0,i.jsx)("span",{className:"label-text",children:"Remember me on this device"})]}),(0,i.jsx)(R,{id:`${d}-error`,message:$,onResetClick:a}),(0,i.jsx)(N,{v2:M}),(0,i.jsxs)("button",{type:"submit",className:"btn btn-primary w-full",disabled:D||!g||!k,"aria-describedby":$?`${d}-error`:void 0,children:[D?(0,i.jsx)("span",{className:"loading loading-spinner loading-sm"}):null,D?"Signing inâ¦":"Sign in"]}),(0,i.jsx)(P,{formName:"login",action:"login",recaptchaV3Key:r,lastOutcome:L,onSimulateBot:()=>V(u)}),(0,i.jsx)("div",{className:"text-center text-sm",children:(0,i.jsx)("button",{type:"button",className:"link link-primary",onClick:a,children:"Forgot your password?"})})]})]})},B=({titleId:e,mail:t,mode:a,onClose:s})=>{let r=(e=>{var t;let a=null==(t=String(e||"").split("@")[1])?void 0:t.toLowerCase();return a?"gmail.com"===a||"googlemail.com"===a?"https://mail.google.com/":"yahoo.com"===a||"ymail.com"===a||"rocketmail.com"===a?"https://mail.yahoo.com/":"outlook.com"===a||"hotmail.com"===a||"live.com"===a||"msn.com"===a||"outlook.co.uk"===a||"hotmail.co.uk"===a?"https://outlook.live.com/mail/":"icloud.com"===a||"me.com"===a||"mac.com"===a?"https://www.icloud.com/mail":"aol.com"===a?"https://mail.aol.com/":"proton.me"===a||"protonmail.com"===a?"https://mail.proton.me/":null:null})(t);return(0,i.jsxs)("div",{className:"flex flex-col gap-4 text-center py-6",children:[(0,i.jsx)("h2",{id:e,className:"text-2xl font-bold",children:"Check your email"}),(0,i.jsxs)("p",{className:"text-sm text-base-content/80",children:["We sent a confirmation link to ",(0,i.jsx)("strong",{className:"break-all",children:t}),". Click it to finish setting up your account."]}),(0,i.jsx)("p",{className:"text-xs text-base-content/80",children:"Didn't get it? Check your spam folder, then try registering again."}),"page"===a?(0,i.jsxs)("div",{className:"flex flex-col gap-2 mt-2",children:[r&&(0,i.jsx)("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary w-full",children:"Open inbox"}),(0,i.jsx)("a",{href:"/",className:"btn btn-outline w-full",children:"Back to homepage"})]}):(0,i.jsx)("button",{type:"button",className:"btn btn-primary w-full mt-2",onClick:s,children:"Close"})]})},M=({mode:e,titleId:t,onSuccess:a,onClose:r,onRegistered:n,onSwitchToLogin:l,onSwitchToReset:c,recaptchaV3Key:d})=>{var m;let p=(0,o.useId)(),g=b("register"),f=b("login"),C=!!(null==(m=window.Drupal)||null==(m
1=m.settings)?void 0:m.emailVerificationRequired),[$,T]=(0,o.useState)(""),[D,I]=(0,o.useState)(""),[L,M]=(0,o.useState)(""),[V,q]=(0,o.useState)(""),[W,U]=(0,o.useState)(!1),[F,z]=(0,o.useState)(""),[G,O]=(0,o.useState)(!1),[K,Y]=(0,o.useState)(!1),[H,Z]=(0,o.useState)(null),X="enforce"===x("register"),J=w({onToken:e=>Q(e,!0),onGiveUp:()=>z(k),onExpired:()=>z(j)}),Q=(0,o.useCallback)(async(e=null,t=null===e)=>{var r,o,i,c,u,m;if(z(""),null===e&&J.showV2)return void z(y(J));if(t){let t=S($)||($!==D?"Email addresses do not match.":null)||(L?L.length<8?"Password must be at least 8 characters.":/[a-zA-Z]/.test(L)&&/\d/.test(L)?null:"Password must contain both letters and numbers.":"You must enter a password.")||(L!==V?"Passwords do not match.":null);if(t){z(t),null!==e&&J.reset();return}}O(!0);let p=null!=e?e:"";if(null===e&&g&&d)try{p=await v(d,"register")}catch(e){}try{let e=await s.post("/api/dante/user/register",{json:{mail:$,conf_mail:D,pass:L,newsletter:W,recaptcha:p}}).json();Z({path:"/api/dante/user/register",token:p,status:"ok",ok:!0});let t=null!=(r=null==e?void 0:e.verification_required)?r:C,c=()=>{Y(!0),null==n||n()};if(t)return void c();if((null==e?void 0:e.token)&&(null==e||null==(o=e.user)?void 0:o.uid)){window.Drupal.settings.servicesToken=e.token,window.Drupal.settings.user={uid:e.user.uid,name:e.user.name,roles:e.user.roles,stream_services:[]},document.dispatchEvent(new CustomEvent("rifftrax:userLoggedIn",{detail:e})),null==a||a({...e,registered:!0});return}if((null==e?void 0:e.uid)||(null==e||null==(i=e.user)?void 0:i.uid)){let e="";if(f&&d)try{e=await v(d,"login")}catch(e){}try{let t=await s.post("/api/dante/user/login",{json:{username:$,password:L,recaptcha:e}}).json();(null==t?void 0:t.token)&&(window.Drupal.settings.servicesToken=t.token),(null==t?void 0:t.user)&&(window.Drupal.settings.user={uid:t.user.uid,name:t.user.name,roles:t.user.roles,stream_services:[]}),document.dispatchEvent(new CustomEvent("rifftrax:userLoggedIn",{detail:t})),null==a||a({...t,registered:!0})}catch(e){z("Account created. Please sign in to continue."),null==l||l()}}else c()}catch(a){let e=await (null==(c=a.response)||null==(u=c.json)?void 0:u.call(c).catch(()=>null)),t=h(null==e?void 0:e.message)||h(null==e?void 0:e.form_errors)||h(null==e?void 0:e.errors);z(t||"Registration failed. Please try again."),Z({path:"/api/dante/user/register",token:p,status:(null==(m=a.response)?void 0:m.status)||"error",ok:!1,message:t,reason:null==e?void 0:e.recaptcha_reason,score:null==e?void 0:e.recaptcha_score}),X&&(null==e?void 0:e.recaptcha_reason)?J.show():J.reset()}finally{O(!1)}},[$,D,L,V,W,g,X,J,f,d,a,n,l,C]),ee=(0,o.useCallback)(e=>(e.preventDefault(),Q()),[Q]);return K?(0,i.jsx)(B,{titleId:t,mail:$,mode:e,onClose:r}):(0,i.jsxs)("form",{onSubmit:ee,noValidate:!0,children:[(0,i.jsx)(E,{id:t,title:"Create your account",subtitle:"A Library that remembers, recommendations that read your mind, and more goodies than we can fit in this sentence."}),(0,i.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,i.jsx)(A,{id:`${p}-reg-email`,label:"Email address",type:"email",value:$,onChange:T,autoComplete:"email",disabled:G,help:"We'll create a username from your email â change it anytime."}),(0,i.jsx)(A,{id:`${p}-reg-email-confirm`,label:"Confirm email address",type:"email",value:D,onChange:I,autoComplete:"email",disabled:G}),(0,i.jsx)(A,{id:`${p}-reg-pass`,label:"Password",type:"password",value:L,onChange:M,autoComplete:"new-password",disabled:G,help:"At least 8 characters, with letters and numbers."}),(0,i.jsx)(_,{password:L}),(0,i.jsx)(A,{id:`${p}-reg-pass-confirm`,label:"Confirm password",type:"password",value:V,onChange:q,autoComplete:"new-password",disabled:G}),(0,i.jsxs)("label",{className:"label cursor-pointer items-start justify-start gap-2 py-1",children:[(0,i.jsx)("input",{type:"checkbox",checked:W,onChange:e=>U(e.target.checked),disabled:G,className:"checkbox checkbox-sm checkbox-primary mt-0.5 shrink-0"}),(0,i.jsx)("span",{className:"label-text whitespace-normal break-words",children:"Get jokes by mail â RiffTrax news, releases, and sales."})]}),(0,i.jsx)(R,{id:`${p}-error`,message:F,onResetClick:c}),(0,i.jsx)(N,{v2:J}),(0,i.jsxs)("button",{type:"submit",className:"btn btn-primary w-full",disabled:G||!$||!D||!L||!V,"aria-describedby":F?`${p}-error`:void 0,children:[G?(0,i.jsx)("span",{className:"loading loading-spinner loading-sm"}):null,G?"Creating accountâ¦":"Create account"]}),l&&(0,i.jsxs)("p",{className:"mt-4 text-sm text-center text-base-content/70",children:["Already have an account?"," ",(0,i.jsx)("button",{type:"button",onClick:l,className:"font-semibold text-primary hover:underline",children:"Sign in"})]}),(0,i.jsx)(P,{formName:"register",action:"register",recaptchaV3Key:d,lastOutcome:H,onSimulateBot:()=>Q(u)})]})]})},V=({titleId:e,onBack:t,recaptchaV3Key:a,cooldownUntil:r,onCooldownStart:n})=>{let l=(0,o.useId)(),c=b("request_new_password"),[d,m]=(0,o.useState)(""),[p,g]=(0,o.useState)(""),[f,_]=(0,o.useState)(""),[$,T]=(0,o.useState)(!1),[D,L]=(0,o.useState)(null),B="enforce"===x("request_new_password"),M=w({onToken:e=>W(e,!0),onGiveUp:()=>g(k),onExpired:()=>g(j)}),[V,q]=(0,o.useState)(0);(0,o.useEffect)(()=>{let e=()=>Math.max(0,Math.ceil((r-Date.now())/1e3));if(q(e()),r<=Date.now())return;let t=setInterval(()=>{let a=e();q(a),a<=0&&clearInterval(t)},1e3);return()=>clearInterval(t)},[r]);let W=(0,o.useCallback)(async(e=null,t=null===e)=>{var r,l,o;if(g(""),_(""),null===e&&M.showV2)return void g(y(M));if(t){let t=d.includes("@")?S(d):d?d.startsWith(" ")?"The username cannot begin with a space.":d.endsWith(" ")?"The username cannot end with a space.":d.includes(" ")?"The username cannot contain multiple spaces in a row.":C.test(d)?null:"The username contains an illegal character.":"You must enter a username.";if(t){g(t),null!==e&&M.reset();return}}T(!0);let i=null!=e?e:"";if(null===e&&c&&a)try{i=await v(a,"request_new_password")}catch(e){}try{await s.post("/api/dante/user/request_new_password",{json:{name:d,recaptcha:i}}).json(),_("If that username or email matches an account, reset instructions are on their way."),n(Date.now()+3e4),L({path:"/api/dante/user/request_new_password",token:i,status:"ok",ok:!0})}catch(a){let e=await (null==(r=a.response)||null==(l=r.json)?void 0:l.call(r).cat
1ch(()=>null)),t=h(null==e?void 0:e.message)||h(null==e?void 0:e.form_errors);g(t||"Could not send reset email. Please try again."),L({path:"/api/dante/user/request_new_password",token:i,status:(null==(o=a.response)?void 0:o.status)||"error",ok:!1,message:t,reason:null==e?void 0:e.recaptcha_reason,score:null==e?void 0:e.recaptcha_score}),B&&(null==e?void 0:e.recaptcha_reason)?M.show():M.reset()}finally{T(!1)}},[d,c,B,M,a,n]),U=(0,o.useCallback)(e=>(e.preventDefault(),W()),[W]);return(0,i.jsxs)("form",{onSubmit:U,noValidate:!0,children:[(0,i.jsx)(E,{id:e,title:"Reset your password",subtitle:"Enter your email address (or username) and we'll send you a link to set a new password."}),(0,i.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,i.jsx)(A,{id:`${l}-reset-name`,label:"Email address (or username)",value:d,onChange:m,autoComplete:"username",disabled:$}),(0,i.jsx)(I,{message:f}),(0,i.jsx)(R,{id:`${l}-error`,message:p}),(0,i.jsx)(N,{v2:M}),(0,i.jsxs)("button",{type:"submit",className:"btn btn-primary w-full",disabled:$||V>0||!d,"aria-describedby":p?`${l}-error`:void 0,"aria-label":V>0?"Resend reset email":void 0,children:[$?(0,i.jsx)("span",{className:"loading loading-spinner loading-sm"}):null,$?"Sendingâ¦":V>0?(0,i.jsx)("span",{"aria-hidden":"true",children:`Can resend in ${V}s`}):"Send reset email"]}),(0,i.jsx)("button",{type:"button",className:"btn btn-ghost btn-sm",onClick:t,children:"â Back to sign in"}),(0,i.jsx)(P,{formName:"reset",action:"request_new_password",recaptchaV3Key:a,lastOutcome:D,onSimulateBot:()=>W(u)})]})]})},q=({url:e,onKnownEmail:t,sideBySide:a=!1})=>{let r=(0,o.useId)(),[n,l]=(0,o.useState)(""),[c,u]=(0,o.useState)(""),[d,m]=(0,o.useState)(!1),p=(0,o.useCallback)(async a=>{if(a.preventDefault(),n&&!d){m(!0),u("");try{let a=await s.post(e,{json:{mail:n}}).json();if((null==a?void 0:a.status)==="guest"&&a.redirect){window.location.href=a.redirect;return}if((null==a?void 0:a.status)==="account"){null==t||t(a.mail||n),m(!1);return}u((null==a?void 0:a.error)||"Something went wrong. Please try again.")}catch(e){u("Something went wrong. Please try again.")}m(!1)}},[n,d,e,t]);return(0,i.jsxs)("form",{onSubmit:p,noValidate:!0,className:"mt-6 pt-5 border-t border-base-300"+(a?" md:mt-0 md:pt-0 md:border-t-0 md:border-l md:pl-8":""),children:[(0,i.jsxs)("div",{className:"mb-3",children:[(0,i.jsx)("h3",{className:"text-lg font-bold",children:"Continue as guest"}),(0,i.jsx)("p",{className:"text-sm text-base-content/70 mt-1",children:"Weâll email your receipt and download links, and set up an account you can claim later."})]}),(0,i.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,i.jsx)(A,{id:`${r}-mail`,label:"Email address",type:"email",value:n,onChange:l,autoComplete:"email",disabled:d}),(0,i.jsx)(R,{id:`${r}-error`,message:c}),(0,i.jsxs)("button",{type:"submit",className:"btn btn-outline btn-primary w-full",disabled:d||!n,"aria-describedby":c?`${r}-error`:void 0,children:[d?(0,i.jsx)("span",{className:"loading loading-spinner loading-sm"}):null,d?"One momentâ¦":"Continue to checkout"]})]})]})},W=({mode:e="modal",defaultTab:t=$,titleId:a,onSuccess:s,onClose:r,guestCheckoutUrl:n,checkoutContext:c=!1})=>{var u,d;let m=(0,o.useId)(),p=e=>`${m}-tab-${e}`,h=`${m}-tabpanel`,[x,f]=(0,o.useState)(t),[v,w]=(0,o.useState)(!1),[y,j]=(0,o.useState)(""),[k,N]=(0,o.useState)(""),[C,S]=l("dante.pwResetCooldownUntil",0),_=C>Date.now()?C:0,E=null==(u=window.Drupal)||null==(u=u.settings)?void 0:u.recaptchaV3Key,A=null==(d=window.Drupal)||null==(d=d.settings)?void 0:d.registerBlurb,R=(0,o.useRef)(null);(0,o.useEffect)(()=>{b()&&E&&(e=>{if(document.getElementById(g))return;let t=document.createElement("script");t.id=g,t.src=`https://www.google.com/recaptcha/api.js?render=${e}`,t.async=!0,document.head.appendChild(t)})(E)},[E]);let I=(0,o.useCallback)(e=>{var t,a;let s=R.current,r=s&&s.getBoundingClientRect().top<80;if(f(e),!r)return;let n=null==(t=(a=window).matchMedia)?void 0:t.call(a,"(prefers-reduced-motion: reduce)").matches;requestAnimationFrame(()=>{if(!R.current)return;let e=R.current.getBoundingClientRect().top+window.scrollY-80;window.scrollTo({top:Math.max(0,e),behavior:n?"auto":"smooth"})})},[]),P=c&&!!n,B=[{key:$,label:"Sign in"},{key:T,label:"Create account"}];return(0,i.jsxs)("div",{ref:R,className:"modal"===e?"p-6":"embedded"===e?"p-4":"p-0",children:[c&&x!==D&&
1!v&&(0,i.jsxs)("div",{className:"mb-5 text-center",children:[(0,i.jsx)("h2",{className:"text-2xl font-bold",children:"Finish your order"}),(0,i.jsx)("p",{className:"text-sm text-base-content/70 mt-1",children:n?"Sign in, create an account, or continue as a guest.":"Sign in or create an account to finish your order."})]}),(0,i.jsxs)("div",{className:P?"md:grid md:grid-cols-2 md:gap-8":"",children:[(0,i.jsxs)("div",{children:[x!==D&&!v&&(0,i.jsx)("div",{role:"tablist","aria-label":"Sign in or create an account",onKeyDown:e=>{if("ArrowLeft"!==e.key&&"ArrowRight"!==e.key)return;e.preventDefault();let t=B.findIndex(e=>e.key===x);I(("ArrowRight"===e.key?B[(t+1)%B.length]:B[(t-1+B.length)%B.length]).key)},className:"grid grid-cols-2 gap-1 p-1 mb-6 rounded-full bg-base-200 border border-base-300",children:B.map(({key:e,label:t})=>{let a=x===e;return(0,i.jsx)("button",{id:p(e),role:"tab",type:"button","aria-selected":a,"aria-controls":h,tabIndex:a?0:-1,onClick:()=>I(e),className:"rounded-full py-2 text-sm font-semibold transition-all duration-150 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/60 "+(a?"bg-primary text-primary-content shadow-sm":"text-base-content/70 hover:text-base-content hover:bg-base-100"),children:t},e)})}),x===T&&!v&&(null==A?void 0:A.text)&&(0,i.jsxs)("p",{className:"mb-5 text-center text-sm text-base-content/70",children:[A.text,A.linkUrl&&A.linkText&&(0,i.jsxs)(i.Fragment,{children:[" ",(0,i.jsx)("a",{href:A.linkUrl,className:"font-semibold text-primary hover:underline",children:A.linkText})]})]}),(0,i.jsxs)("div",{...x!==D&&!v?{id:h,role:"tabpanel","aria-labelledby":p(x)}:null,children:[x===$&&(0,i.jsx)(L,{titleId:a,onSuccess:s,onClose:r,onForgotPassword:()=>I(D),recaptchaV3Key:E,initialUsername:y,notice:k,subtitle:c?"Sign in to pick up where you left off.":void 0}),x===T&&(0,i.jsx)(M,{mode:e,titleId:a,onSuccess:s,onClose:r,onRegistered:()=>w(!0),onSwitchToLogin:()=>I($),onSwitchToReset:()=>I(D),recaptchaV3Key:E}),x===D&&(0,i.jsx)(V,{titleId:a,onBack:()=>I($),recaptchaV3Key:E,cooldownUntil:_,onCooldownStart:S})]})]}),n&&x!==D&&!v&&(0,i.jsx)(q,{url:n,sideBySide:P,onKnownEmail:e=>{j(e),N("You already have an account with that email. Sign in to continue."),I($)}})]})]})};export{W as LoginForm};
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.