import{j as e}from"./vendor-radix-DNp60FuA.js";import{r as d,j as H,L as C}from"./vendor-react-DL0tRKZA.js";import{u as q}from"./index.esm-Djp0AcWf.js";import{t as S,s as L,u as W,B as M,p as E}from"./index-DbhEjV5W.js";import{I as O}from"./input-BB7xZgTE.js";import{C as R,c as D,a as G,e as J}from"./card-D8WTMV8f.js";import{F as K,a as F,b as U,c as A,d as V}from"./form-B40qC90I.js";import{A as h,a as f}from"./alert-By0Cm1U4.js";import{P as Q}from"./password-input-BycF9bkH.js";import{C as _}from"./clock-BbD_GbdK.js";import{C as T}from"./circle-check-big-Z9rEE01O.js";import{M as X}from"./mail-LeGJPHXY.js";import{T as Z}from"./triangle-alert-CiUGUU8g.js";import"./vendor-supabase-B4f4CcZD.js";import"./vendor-query-CKQAY9LX.js";import"./vendor-charts-CPng-d0O.js";import"./label-BaEEUFvK.js";import"./auth-validation-Pa3ShdjD.js";import"./eye-off-DMaBMyBk.js";import"./eye-DIFaUC5Z.js";const ee=()=>{const[g,m]=d.useState(!1);return{resendVerification:async w=>{var k,N,b;if(!w)return S({variant:"destructive",title:"Error",description:"Email address is required to resend verification."}),!1;m(!0);try{const a=()=>`${window.location.origin}/auth/callback`,{error:t}=await L.auth.resend({type:"signup",email:w,options:{emailRedirectTo:a()}});if(t){console.error("Resend verification error:",t);let u="Failed to resend verification email. Please try again.";return(k=t.message)!=null&&k.includes("rate limit")||(N=t.message)!=null&&N.includes("too many")?u="Too many requests. Please wait a moment before trying again.":(b=t.message)!=null&&b.includes("User not found")&&(u="No account found with this email address."),S({variant:"destructive",title:"Resend Failed",description:u}),!1}else return S({title:"Verification Email Sent",description:"Please check your inbox for the verification link."}),!0}catch(a){return console.error("Resend verification error:",a),S({variant:"destructive",title:"Error",description:"An unexpected error occurred. Please try again."}),!1}finally{m(!1)}},isResending:g}};function we(){const[g]=H(),[m,o]=d.useState(""),[w,k]=d.useState(""),[N,b]=d.useState(!1),[a,t]=d.useState(null),[u,x]=d.useState(null),{signIn:B,user:se,loading:Y}=W(),{resendVerification:$,isResending:I}=ee(),P=g.get("verified")==="1",i=q({defaultValues:{email:g.get("email")||"",password:""}});if(d.useEffect(()=>{(async()=>{var j,v;const l=localStorage.getItem("auth_login_blocked_until");if(!l)return;const p=new Date(l).getTime(),s=Date.now(),c=p-s;if(c<=0){localStorage.removeItem("auth_login_blocked_until");return}t(l),x(Math.ceil(c/1e3));const r=2*60*1e3;if(c<r)try{const y=await L.functions.invoke("rate-limit-check",{body:{endpoint:"auth_login",maxAttempts:10,windowMinutes:15,blockMinutes:30}});(j=y.data)!=null&&j.allowed?(localStorage.removeItem("auth_login_blocked_until"),t(null),x(null)):(v=y.data)!=null&&v.blocked_until&&(t(y.data.blocked_until),x(Math.ceil((new Date(y.data.blocked_until).getTime()-s)/1e3)))}catch(y){console.debug("Rate limit server sync skipped (network issue):",y)}})()},[]),d.useEffect(()=>{if(!a)return;const n=setInterval(()=>{const l=new Date(a).getTime(),p=Date.now(),s=Math.ceil((l-p)/1e3);s<=0?(localStorage.removeItem("auth_login_blocked_until"),t(null),x(null),o("")):x(s)},1e3);return()=>clearInterval(n)},[a]),Y)return e.jsxs("section",{className:"h-screen flex items-center justify-center relative overflow-hidden bg-[url('../../assets/images/hero/bg.jpg')] bg-no-repeat bg-center bg-cover",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60"}),e.jsx("div",{className:"container relative z-10",children:e.jsx("div",{className:"flex justify-center",children:e.jsx(R,{className:"relative overflow-hidden bg-black/40 backdrop-blur-xl shadow-[0_0_40px_rgba(168,85,247,0.15)] border border-white/10 rounded-2xl w-full max-w-md",children:e.jsx(D,{className:"p-6 flex items-center justify-center min-h-[200px]",children:e.jsxs("div",{className:"text-center",children:[e.jsx(_,{className:"h-8 w-8 animate-spin mx-auto mb-4 text-primary"}),e.jsx("p",{className:"text-muted-foreground",children:e.jsx("span",{children:"Loading..."})})]})})})})})]});const z=async n=>{var l,p;if(o(""),k(""),b(!1),a){const s=new Date(a).getTime(),c=Date.now();if(s>c){const r=Math.ceil((s-c)/6e4);o(`You're temporarily blocked due to too many attempts. Try again in ${r} minute${r!==1?"s":""}.`);return}else localStorage.removeItem("auth_login_blocked_until"),t(null),x(null)}try{const{error:s,needsEmailVerification:c,rateLimit:r}=await B(n.email,n.password);if(s){if((s==null?void 0:s.code)==="rate_limited"){console.debug("[Login] Rate limited:",r);const v=r!=null&&r.blockedUntil?Math.ceil((new Date(r.blockedUntil).getTime()-Date.now())/6e4):null;o(v?`You're temporarily blocked due to too many attempts. Try again in ${v} minute${v!==1?"s":""}.`:"Too many login attempts. Please try again later."),r!=null&&r.blockedUntil&&(localStorage.setItem("auth_login_blocked_until",r.blockedUntil),t(r.blockedUntil),x(Math.ceil((new Date(r.blockedUntil).getTime()-Date.now())/1e3)));return}console.error("Login error:",s);let j="Sign in failed. Please check your credentials.";(l=s.message)!=null&&l.includes("Invalid login credentials")?j="Invalid email or password. Please check your credentials and try again.":(p=s.message)!=null&&p.includes("Email not confirmed")&&(b(!0),j="Please verify your email address before signing in. Check your inbox for the verification link."),o(j)}else c?(b(!0),o("Please verify your email address before signing in. Check your inbox for the verification link.")):k("Signed in successfully! Redirecting...")}catch(s){console.error("Unexpected login error:",s),o("An unexpected error occurred. Please try again.")}};return e.jsxs("section",{className:"h-screen flex items-center justify-center relative overflow-hidden bg-[url('../../assets/images/hero/bg.jpg')] bg-no-repeat bg-center bg-cover",children:[e.jsx("div",{className:"absolute inset-0 bg-black/60"}),e.jsx("div",{className:"container relative z-10",children:e.jsx("div",{className:"flex justify-center",children:e.jsxs(R,{className:"relative overflow-hidden bg-black/40 backdrop-blur-xl shadow-[0_0_40px_rgba(168,85,247,0.15)] border border-white/10 rounded-2xl w-full max-w-md",children:[e.jsxs(G,{className:"p-6 pb-2",children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("img",{src:"/talenthunter-logo.webp",className:"w-[200px]",alt:"Talent Hunter Logo"})}),e.jsx("h1",{className:"my-6 text-xl font-semibold text-center text-foreground",children:"Sign In"})]}),e.jsxs(D,{className:"px-6",children:[P&&e.jsxs(h,{className:"mb-4 border-green-500/50 text-green-600",children:[e.jsx(T,{className:"h-4 w-4"}),e.jsx(f,{children:e.jsx("span",{children:"Email verified successfully! You can now sign in to your account."})})]}),g.get("email")&&!P&&e.jsxs(h,{className:"mb-4 border-blue-500/50 text-blue-600",children:[e.jsx(T,{className:"h-4 w-4"}),e.jsx(f,{children:e.jsx("span",{children:"Welcome! Your account has been created. Please sign in with your credentials."})})]}),g.get("session_expired")==="true"&&e.jsxs(h,{className:"mb-4 border-amber-500 bg-amber-50 dark:bg-amber-950/20",children:[e.jsx(_,{className:"h-4 w-4 text-amber-600"}),e.jsx(f,{className:"text-amber-800 dark:text-amber-200",children:"Your session has expired due to inactivity. Please sign in again to continue where you left off."})]}),N&&e.jsxs(h,{variant:"destructive",className:"mb-4",children:[e.jsx(X,{className:"h-4 w-4"}),e.jsxs(f,{className:"flex items-center justify-between",children:[e.jsx("span",{children:"Please verify your email address to sign in."}),e.jsx(M,{variant:"outline",size:"sm",onClick:()=>$(i.getValues("email")),disabled:I,className:"ml-2 border-destructive/20 hover:bg-destructive/10",children:I?e.jsx("span",{children:"Sending..."}):e.jsx("span",{children:"Resend Email"})})]})]}),m&&a&&u&&e.jsxs(h,{className:"mb-4 border-amber-500 bg-amber-50 dark:bg-amber-950/20",children:[e.jsx(_,{className:"h-4 w-4 text-amber-600"}),e.jsxs(f,{className:"text-amber-800 dark:text-amber-200",children:[e.jsx("div",{children:e.jsx("span",{children:m})}),e.jsx("div",{className:"mt-2 font-mono text-sm",children:e.jsxs("span",{children:["Try again in: ",Math.floor(u/60),"m ",u%60,"s"]})})]})]}),m&&!a&&!N&&e.jsxs(h,{variant:"destructive",className:"mb-4",children:[e.jsx(Z,{className:"h-4 w-4"}),e.jsx(f,{children:e.jsx("span",{children:m})})]}),w&&e.jsxs(h,{className:"mb-4 border-primary/50 text-primary",children:[e.jsx(T,{className:"h-4 w-4"}),e.jsx(f,{children:e.jsx("span",{children:w})})]}),e.jsx(K,{...i,children:e.jsxs("form",{onSubmit:i.handleSubmit(z),className:"space-y-4",children:[e.jsx(F,{control:i.control,name:"email",render:({field:n})=>e.jsxs(U,{children:[e.jsx(A,{className:"font-semibold",children:"Email Address *"}),e.jsx(V,{children:e.jsx(O,{type:"email",autoComplete:"email",placeholder:"name@example.com",className:E("focus:border-primary focus:ring-1 focus:ring-primary",i.formState.errors.email&&"border-destructive focus:border-destructive focus:ring-destructive"),...n})})]})}),e.jsx(F,{control:i.control,name:"password",render:({field:n})=>e.jsxs(U,{children:[e.jsx(A,{className:"font-semibold",children:"Password *"}),e.jsx(V,{children:e.jsx(Q,{autoComplete:"current-password",placeholder:"Password",className:E("focus:border-primary focus:ring-1 focus:ring-primary",i.formState.errors.password&&"border-destructive focus:border-destructive focus:ring-destructive"),...n})})]})}),e.jsx("div",{className:"text-right",children:e.jsx(C,{to:"/auth/reset-password",className:"text-sm text-primary hover:text-primary/80 transition-colors",children:"Forgot Password?"})}),e.jsx(M,{type:"submit",disabled:i.formState.isSubmitting,className:"w-full bg-primary hover:bg-primary/90 text-primary-foreground font-semibold py-2 disabled:opacity-50",children:i.formState.isSubmitting?e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"}),e.jsx("span",{children:"Signing In..."})]}):e.jsx("span",{children:"Sign In"})}),e.jsxs("div",{className:"text-center",children:[e.jsx("span",{className:"text-muted-foreground",children:"Don't have an account? "}),e.jsx(C,{to:"/auth/signup",className:"text-foreground font-bold hover:text-primary transition-colors",children:"Create Account"})]})]})})]}),e.jsx(J,{className:"px-6 py-4 bg-slate-50 dark:bg-slate-800",children:e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 text-center w-full",children:"© 2025–2026 Talent Hunter. Design & Develop by IFC Technologies."})})]})})})]})}export{we as default};