1import{Q as O,av as U,u as D,r as o,aw as G,ax as z,j as t,m as L,v as J,L as N,y as $,ay as q,z as k,x as v,az as K,aA as Q,aB as W,aC as Y,aD as V,aE as X}from"./index-BGXoFh6q.js";import{L as Z,a as ee,b as te,c as ae,d as S,f as C,e as re,g as se}from"./LoginPageShell-CwkKq07c.js";import{E as oe}from"./eye-off-Dc5RdcvL.js";import{E as ne}from"./eye-DgTf4wSM.js";const P=$({email:k().trim().email().max(320),password:k().min(1).max(2e3),rememberMe:q()});function he(){const T=O(),m=U.useLoaderData(),{t:e,i18n:A}=D(),l=A.language?.startsWith("ar"),[b,_]=o.useState("signin"),[g,B]=o.useState(""),[u,y]=o.useState(""),[s,F]=o.useState(!1),[p,R]=o.useState(!1),[x,w]=o.useState(!1),c=o.useMemo(()=>G("athlete",m.athlete,l,{signInTo:e("athleteLogin.signInTo"),portalTitle:e("athleteLogin.gmsTitle"),portalSubtitle:e("athleteLogin.gmsSubtitle"),intro:e("athleteLogin.intro"),heroTagline:e("athleteLogin.heroTagline"),heroSlogan:e("athleteLogin.heroSlogan"),emailPlaceholder:e("athleteLogin.placeholders.email"),submitLabel:e("athleteLogin.submit"),backHome:e("athleteLogin.backHome")}),[m.athlete,l,e]),r=o.useMemo(()=>z(m.athlete,l,{tabSignin:e("athleteLogin.tabs.signin"),tabRegister:e("athleteLogin.tabs.register"),tabForgot:e("athleteLogin.tabs.forgot"),registerBody:e("athleteLogin.register.body"),registerCta:e("athleteLogin.register.cta"),forgotBody:e("athleteLogin.forgot.body"),forgotCta:e("athleteLogin.forgot.openGms"),forgotEmailLabel:e("athleteLogin.forgot.emailLabel"),contactCta:e("athleteLogin.forgot.contactPage")}),[m.athlete,l,e]),f=o.useMemo(()=>{const a=P.safeParse({email:g,password:u,rememberMe:s});if(a.success)return null;const n={};for(const d of a.error.issues){const i=String(d.path?.[0]??"");n[i]||(n[i]=e(i==="email"?"athleteLogin.errors.invalidEmail":"athleteLogin.errors.passwordRequired"))}return n},[g,u,s,e]),I=a=>{switch(a.error){case"invalid_credentials":return e("athleteLogin.errors.invalidCredentials");case"account_suspended":return e("athleteLogin.errors.accountSuspended");case"session_error":return e("athleteLogin.errors.sessionError");case"gms_unavailable":return e("athleteLogin.errors.gmsUnavailable");case"server_config":return e("athleteLogin.errors.serverConfig");default:return a.message||e("athleteLogin.errors.signInFailed")}},M=async a=>{a.preventDefault();const n=P.safeParse({email:g,password:u,rememberMe:s});if(!n.success){v.error(e("athleteLogin.errors.checkEntries"));return}w(!0);try{const d=await fetch("/api/athlete/login",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(n.data)}),i=await d.text();let h={};try{h=i?JSON.parse(i):{}}catch{}if(!d.ok)throw new Error(I(h));if(!h?.access_token)throw new Error(e("athleteLogin.errors.invalidResponse"));K(h.access_token,s);const j=h.refresh_token;
1Q(s&&j?j:null,s);const E=h.athlete?.email?.trim()||g;W(Y({},E),s);try{if(await V(h.access_token,E,s),!s)try{localStorage.removeItem(X)}catch{}}catch{}v.success(e("athleteLogin.success")),T({to:"/athlete",replace:!0})}catch(d){const i=d instanceof Error?d.message:e("athleteLogin.errors.signInFailed");v.error(i)}finally{w(!1),y("")}},H=[{id:"signin",label:r.tabSignin},{id:"register",label:r.tabRegister},{id:"forgot",label:r.tabForgot}];return t.jsx(Z,{isAr:l,children:t.jsxs(ee,{children:[t.jsxs(te,{isAr:l,children:[t.jsx(ae,{content:c,isAr:l}),t.jsx("nav",{className:"mt-8 flex flex-wrap items-stretch rounded-2xl border border-white/60 bg-white/30 p-1 shadow-inner backdrop-blur-sm","aria-label":e("athleteLogin.authNav"),children:H.map(a=>{const n=b===a.id;return t.jsx("button",{type:"button",onClick:()=>_(a.id),className:["relative flex-1 min-w-[7rem] rounded-xl px-3 py-2.5 text-sm font-semibold transition-all duration-300 sm:px-4",n?"bg-gradient-to-r from-brand-red via-brand-gold to-brand-green text-white shadow-lg shadow-brand-red/25":"text-brand-navy/65 hover:bg-white/50 hover:text-brand-navy"].join(" "),children:a.label},a.id)})}),b==="signin"&&t.jsxs(L.form,{onSubmit:M,className:"mt-10 space-y-6",initial:{opacity:0}
1,animate:{opacity:1},children:[t.jsx(S,{id:"athlete-email",label:e("athleteLogin.fields.email"),error:f?.email,children:t.jsx("input",{id:"athlete-email",type:"email",autoComplete:"email",value:g,onChange:a=>B(a.target.value),className:C,placeholder:c.emailPlaceholder})}),t.jsx(S,{id:"athlete-password",label:e("athleteLogin.fields.password"),error:f?.password,children:t.jsxs("div",{className:"relative",children:[t.jsx("input",{id:"athlete-password",type:p?"text":"password",autoComplete:"current-password",value:u,onChange:a=>y(a.target.value),className:`${C} pe-12`}),t.jsx("button",{type:"button",onClick:()=>R(a=>!a),className:"absolute end-3 top-1/2 -translate-y-1/2 rounded-md p-1.5 text-brand-navy/50 transition hover:text-brand-navy","aria-label":e(p?"athleteLogin.hidePassword":"athleteLogin.showPassword"),children:p?t.jsx(oe,{className:"h-4 w-4"}):t.jsx(ne,{className:"h-4 w-4"})})]})}),t.jsxs("label",{className:"flex cursor-pointer items-center gap-2.5 text-sm text-brand-navy/70",children:[t.jsx("input",{type:"checkbox",checked:s,onChange:a=>F(a.target.checked),className:"h-4 w-4 rounded border-brand-navy/20 accent-brand-gold"}),e("athleteLogin.rememberMe")]}),t.jsxs(re,{disabled:x||!!f,children:[x&&t.jsx(J,{className:"h-4 w-4 animate-spin"}),x?e("athleteLogin.submitting"):c.submitLabel]})]}),b==="register"&&t.jsxs(L.div,{className:"mt-10 space-y-6 text-brand-navy/75",initial:{opacity:0}
1,animate:{opacity:1},children:[t.jsx("p",{className:"text-sm leading-relaxed",children:r.registerBody}),t.jsx("a",{href:r.registerUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex w-full items-center justify-center rounded-xl bg-gradient-to-r from-brand-red via-brand-gold to-brand-green py-3.5 text-sm font-bold uppercase tracking-wide text-white shadow-lg transition hover:brightness-110",children:r.registerCta})]}),b==="forgot"&&t.jsxs(L.div,{className:"mt-10 space-y-4 text-sm text-brand-navy/75",initial:{opacity:0},animate:{opacity:1},children:[t.jsx("p",{children:r.forgotBody}),t.jsx("a",{href:r.forgotPasswordUrl,target:"_blank",rel:"noopener noreferrer",className:"inline-flex w-full items-center justify-center rounded-xl bg-gradient-to-r from-brand-red via-brand-gold to-brand-green py-3 text-sm font-bold text-white transition hover:brightness-110",children:r.forgotCta}),t.jsxs("p",{children:[r.forgotEmailLabel," ",t.jsx("a",{href:`mailto:${r.contactEmail}`,className:"font-medium text-brand-gold hover:underline",children:r.contactEmail})]}),t.jsx(N,{to:r.contactUsPath,className:"inline-flex w-full items-center justify-center rounded-xl border border-white/80 bg-white/50 py-3 text-sm font-semibold text-brand-navy shadow-sm backdrop-blur-sm transition hover:bg-white/80",children:r.contactCta})]}),t.jsx("p",{className:"mt-8 text-center text-xs text-brand-navy/55",children:t.jsx(N,{to:"/",className:"underline-offset-2 transition hover:text-brand-navy hover:underline",children:c.backHome})})]}),t.jsx(se,{heroSrc:c.heroImageUrl,heroAlt:e("athleteLogin.heroAlt"),heroTagline:c.heroTagline,heroSlogan:c.heroSlogan})]})})}export{he as component};
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.