1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BivvAlv4.js","assets/capacitor-DSpR9wll.js"])))=>i.map(i=>d[i]); 2import{C as S,r as ne,_ as le}from"./capacitor-DSpR9wll.js";import{m as ce,k as de,r as l,j as e}from"./react-vendor-Q2BSRknM.js";import{u as ue}from"./query-BLOP9k_M.js";import{q as me,ab as pe,ae as he,u as fe,af as ge,a3 as we,a4 as xe,ag as ve,ah as ye,C as be,B as _,a5 as je,a6 as Ne,a7 as H,ai as K,U as C,R as k,aj as Q,s as x,ad as W}from"./index-BgCZMvjj.js";import{L as I,a4 as q,a5 as $,a6 as Z,W as z}from"./lucide-Ckh7y__x.js";import"./ui-radix-DzQ_orwq.js";import"./supabase-DoZmW4Yf.js";import"./date-utils-DaNoSKVa.js";const Ce="data:image/svg+xml,%3csvg%20width='168'%20height='118'%20viewBox='0%200%20168%20118'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3cpath%20fill-rule='evenodd'%20clip-rule='evenodd'%20d='M30.9902%2016.6313L0%20118L113.821%20117.89C124.076%20117.879%20133.124%20111.177%20136.123%20101.369L167.113%200L53.2925%200.11032C43.0366%200.120981%2033.9886%206.8235%2030.9902%2016.6313ZM32.8888%2094.0003L52.7879%2029.3272C53.7555%2026.1823%2056.6738%2024.0318%2059.9835%2024.0249L90.707%2023.9604L70.8079%2088.6336C69.8403%2091.7785%2066.922%2093.929%2063.6123%2093.9359L32.8888%2094.0003ZM115.6%2065.7963H85.0654L96.2223%2029.3306C97.1851%2026.1837%20100.089%2024.0319%20103.382%2024.0249L133.952%2023.9604L122.776%2060.4906C121.811%2063.6432%20118.899%2065.7963%20115.6%2065.7963Z'%20fill='white'/%3e%3c/svg%3e",T=Q().email("Please enter a valid email address"),Y=Q().min(6,"Password must be at least 6 characters"),ke="6cec7849-2af2-4961-b113-ffb699943939",Pe="https://oidc.pickleball.com/oauth2/auth",G=n=>{var o,f;const i=((o=n==null?void 0:n.message)==null?void 0:o.toLowerCase())||"",v=((f=n==null?void 0:n.code)==null?void 0:f.toLowerCase())||"";return i.includes("timeout")||i.includes("deadline exceeded")||i.includes("load failed")?"Connection timed out. Please check your internet connection and try again.":i.includes("network")||i.includes("fetch failed")?"Network error. Please check your internet connection.":i.includes("rate limit")||v.includes("rate_limit")?"Too many attempts. Please wait a moment and try again.":i.includes("invalid")||i.includes("credentials")?"Invalid email or password. Please check your credentials.":i.includes("already registered")||i.includes("already exists")?"This email is already registered. Please sign in instead.":(n==null?void 0:n.message)||"An error occurred. Please try again."};function Ae(){var j,R;const n=ce(),i=de(),{user:v}=me(),{toast:o}=pe();he();const f=fe(),{isLightTheme:J}=ge(),[d,p]=l.useState(!1),[E,g]=l.useState(!1),[w,L]=l.useState(""),[y,F]=l.useState(""),[h,D]=l.useState(!1),[P,X]=l.useState("signin"),A=l.useRef(null),B=l.useRef(null),{data:ee=!1}=ue({queryKey:["app_settings","sso_enabled"],queryFn:async()=>{const{data:t}=await x.from("app_settings").select("value").eq("key","sso_enabled").maybeSingle();return(t==null?void 0:t.value)!=="false"},staleTime:3e4});l.useEffect(()=>{var t;if(v){const s=((t=i.state)==null?void 0:t.returnTo)||"/";n(s,{replace:!0})}},[v,n,i.state]);const te=l.useRef(null),se=t=>{let s=(t==null?void 0:t.parentElement)??null;for(;s;){const a=getComputedStyle(s).overflowY;if((a==="auto"||a==="scroll")&&s.scrollHeight>s.clientHeight)return s;s=s.parentElement}return window},b=l.useCallback(t=>{const s=t.target,r=()=>{try{const a=window.visualViewport,u=s.getBoundingClientRect(),c=a?a.offsetTop+a.height:window.innerHeight,N=u.bottom-(c-24),M=se(s),V=U=>{M===window?window.scrollBy({top:U,behavior:"smooth"}):M.scrollBy({top:U,behavior:"smooth"})};N>0?V(N):u.top<80&&V(u.top-80)}catch{}};setTimeout(r,50),setTimeout(r,350),setTimeout(r,700)},[]),O=l.useCallback(t=>{var s;t.key==="Enter"&&(t.preventDefault(),(s=(P==="signup"?B:A).current)==null||s.focus())},[P]),ae=async t=>{t.preventDefault();const s=T.safeParse(w);if(!s.success){o({title:"Invalid Email",description:s.error.errors[0].message,variant:"destructive"});return}const r=Y.safeParse(y);if(!r.success){o({title:"Invalid Password",description:r.error.errors[0].message,variant:"destructive"});return}p(!0);try{const{error:a}=await x.auth.signUp({email:s.data,password:r.data,options:{emailRedirectTo:`${window.location.origin}/`}});if(a)throw a;o({title:"Account Created!",description:"Check your email to verify your account."})}
2catch(a){o({title:"Sign Up Failed",description:G(a),variant:"destructive"})}finally{p(!1)}},re=async t=>{var a;(a=t==null?void 0:t.preventDefault)==null||a.call(t);const s=T.safeParse(w);if(!s.success){o({title:"Invalid Email",description:s.error.errors[0].message,variant:"destructive"});return}const r=Y.safeParse(y);if(!r.success){o({title:"Invalid Password",description:r.error.errors[0].message,variant:"destructive"});return}p(!0);try{const{error:u}=await Promise.race([x.auth.signInWithPassword({email:s.data,password:r.data}),new Promise((c,m)=>setTimeout(()=>m(new Error("Connection timed out")),15e3))]);if(u)throw u;o({title:"Welcome back!",duration:1800})}catch(u){o({title:"Sign In Failed",description:G(u),variant:"destructive"})}finally{p(!1)}},oe=async()=>{g(!0);const t=S.isNativePlatform()?"com.cc.pbpulse.app://auth-callback":`${window.location.origin}/auth-callback`,s=crypto.randomUUID();sessionStorage.setItem("oidc_state",s),sessionStorage.setItem("oidc_redirect_uri",t),localStorage.setItem("oidc_state",s),localStorage.setItem("oidc_redirect_uri",t),Promise.allSettled([W.setItem("oidc_state",s),W.setItem("oidc_redirect_uri",t)]);const r=new URLSearchParams({client_id:ke,response_type:"code",redirect_uri:t,scope:"openid offline_access email",state:s}),a=`${Pe}?${r.toString()}`;if(S.isNativePlatform()){if(S.getPlatform()==="ios")try{const c=ne("ExternalBrowser");g(!1),c.openSafariView({url:a}).catch(m=>{console.error("[OIDC] Failed to open Safari view, falling back to system browser:",m),c.open({url:a}).catch(N=>{console.error("[OIDC] System browser also failed:",N),window.location.href=a})});return}catch(c){console.error("[OIDC] Failed to initialize external browser:",c),g(!1),window.location.href=a;return}try{const{Browser:c}=await le(async()=>{const{Browser:m}=await import("./index-BivvAlv4.js");return{Browser:m}},__vite__mapDeps([0,1]));g(!1),c.open({url:a,presentationStyle:"fullscreen"}).catch(m=>{console.error("[OIDC] Failed to open Custom Tab, falling back to WebView nav:",m),window.location.href=a});return}catch(c){console.error("[OIDC] Failed to initialize Capacitor Browser on Android:",c),g(!1),window.location.href=a;return}}window.location.href=a},ie=async()=>{const t=T.safeParse(w);if(!t.success){o({title:"Enter your email",description:"Please enter your email address first.",variant:"destructive"});return}p(!0);try{try{const{data:r}=await x.rpc("get_account_auth_provider",{_email:t.data});if(r==="pickleball_com"){o({title:"Use Pickleball.com to sign in",description:`This email is linked to Pickleball.com. There's no password to reset â tap "Continue with Pickleball.com" to sign in.`,duration:9e3});return}}catch(r){console.warn("[Auth] provider lookup failed, proceeding with reset:",r)}const{error:s}=await x.auth.resetPasswordForEmail(t.data,{redirectTo:`${window.location.origin}/reset-password`});if(s)throw s;o({title:"Reset Email Sent",description:"Check your inbox for a password reset link."})}catch(s){o({title:"Error",description:s.message,variant:"destructive"})}finally{p(!1)}};return e.jsxs(e.Fragment,{children:[f?e.jsx(we,{onAuthClick:()=>{}
2,alwaysVisible:!0,forceOpaqueBackground:!0}):e.jsx(xe,{onRefresh:()=>{},lastRefreshTime:null,onAuthClick:()=>{}}),e.jsxs("div",{ref:te,className:"min-h-dvh flex flex-col items-center justify-start px-4 overflow-y-auto",style:{background:"var(--gradient-page, hsl(var(--background)))",paddingTop:f&&(R=(j=window==null?void 0:window.Capacitor)==null?void 0:j.isNativePlatform)!=null&&R.call(j)?"calc(env(safe-area-inset-top, 0px) + 1.25rem)":"calc(env(safe-area-inset-top, 0px) + 5rem)",paddingBottom:"calc(env(safe-area-inset-bottom, 0px) + 60vh)"},onClick:t=>{var s;t.target===t.currentTarget&&((s=document.activeElement)==null||s.blur())},children:[e.jsxs("div",{className:"flex flex-col items-center mb-4 mt-0",children:[e.jsx("span",{className:"text-2xl font-bold tracking-tight text-foreground",children:"Every Day is"}),e.jsx("img",{src:J?ve:ye,alt:"MATCHDAY",className:"h-10 w-auto mt-0.5"}),e.jsx("p",{className:"text-sm text-muted-foreground text-center mt-2",children:"Follow scores. Get alerts. Make predictions."})]}),e.jsxs(be,{className:"w-full max-w-sm p-5 border border-border/50",children:[ee&&e.jsxs(e.Fragment,{children:[e.jsxs(_,{onClick:oe,disabled:E,className:"w-full h-10 font-semibold text-sm mb-4 text-white border-0",style:{backgroundColor:"hsl(258, 65%, 58%)"},children:[E?e.jsx(I,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx("img",{src:Ce,alt:"",className:"h-6 w-6 mr-1.5"}),"Sign in with Pickleball.com"]}),e.jsxs("div",{className:"relative my-4",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t border-border/50"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-card px-2 text-muted-foreground",children:"or continue with email"})})]})]}),e.jsxs(je,{value:P,onValueChange:X,children:[e.jsxs(Ne,{className:"grid w-full grid-cols-2 mb-4",children:[e.jsx(H,{value:"signin",className:"data-[state=active]:bg-gradient-to-br data-[state=active]:from-primary data-[state=active]:to-primary/80 data-[state=active]:text-primary-foreground",children:"Sign In"}),e.jsx(H,{value:"signup",className:"data-[state=active]:bg-gradient-to-br data-[state=active]:from-primary data-[state=active]:to-primary/80 data-[state=active]:text-primary-foreground",children:"Sign Up"})]}),e.jsx(K,{value:"signin",children:e.jsxs("form",{onSubmit:re,className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"signin-email",className:"text-sm",children:"Email"}),e.jsxs("div",{className:"relative",children:[e.jsx(q,{className:"absolute left-3 top-3 h-4 w-4 text-muted-foreground"}),e.jsx(k,{id:"signin-email",type:"email",inputMode:"email",enterKeyHint:"next",placeholder:"[email protected]",value:w,onChange:t=>
2L(t.target.value),onKeyDown:O,onFocus:b,className:"pl-10",autoComplete:"email",disabled:d})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"signin-password",className:"text-sm",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx($,{className:"absolute left-3 top-3 h-4 w-4 text-muted-foreground"}),e.jsx(k,{ref:A,id:"signin-password",type:h?"text":"password",enterKeyHint:"done",placeholder:"â¢â¢â¢â¢â¢â¢",value:y,onChange:t=>F(t.target.value),onFocus:b,className:"pl-10 pr-10",autoComplete:"current-password",disabled:d}),e.jsx("button",{type:"button",onClick:()=>D(!h),className:"absolute right-3 top-3 text-muted-foreground hover:text-foreground",children:h?e.jsx(Z,{className:"h-4 w-4"}):e.jsx(z,{className:"h-4 w-4"})})]})]}),e.jsxs(_,{type:"submit",className:"w-full",disabled:d,children:[d?e.jsx(I,{className:"h-4 w-4 mr-2 animate-spin"}):null,d?"Signing In...":"Sign In"]}),e.jsx("button",{type:"button",onClick:ie,className:"text-xs text-muted-foreground hover:text-primary w-full text-center mt-2",children:"Forgot password?"})]})}),e.jsx(K,{value:"signup",children:e.jsxs("form",{onSubmit:ae,className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"signup-email",className:"text-sm",children:"Email"}),e.jsxs("div",{className:"relative",children:[e.jsx(q,{className:"absolute left-3 top-3 h-4 w-4 text-muted-foreground"}),e.jsx(k,{id:"signup-email",type:"email",inputMode:"email",enterKeyHint:"next",placeholder:"[email protected]",value:w,onChange:t=>
2L(t.target.value),onKeyDown:O,onFocus:b,className:"pl-10",autoComplete:"email",disabled:d})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"signup-password",className:"text-sm",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx($,{className:"absolute left-3 top-3 h-4 w-4 text-muted-foreground"}),e.jsx(k,{ref:B,id:"signup-password",type:h?"text":"password",enterKeyHint:"done",placeholder:"6+ characters",value:y,onChange:t=>F(t.target.value),onFocus:b,className:"pl-10 pr-10",autoComplete:"new-password",disabled:d}),e.jsx("button",{type:"button",onClick:()=>D(!h),className:"absolute right-3 top-3 text-muted-foreground hover:text-foreground",children:h?e.jsx(Z,{className:"h-4 w-4"}):e.jsx(z,{className:"h-4 w-4"})})]})]}),e.jsxs(_,{type:"submit",className:"w-full",disabled:d,children:[d?e.jsx(I,{className:"h-4 w-4 mr-2 animate-spin"}):null,d?"Creating Account...":"Create Account"]})]})})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-4 text-[11px] text-muted-foreground/60",children:[e.jsx("a",{href:"mailto:[email protected]",className:"hover:text-muted-foreground transition-colors",children:"Contact"}),e.jsx("span",{children:"·"}),e.jsx("a",{href:"https://pblfg.com/privacy",target:"_blank",rel:"noopener noreferrer",className:"hover:text-muted-foreground transition-colors",children:"Privacy Policy"})]})]})]})}export{Ae 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.