import{j as e}from"./query-vendor-CZu0EHPe.js";import{r,u as K,f as O,L as h}from"./react-vendor-0bvDbF03.js";import{B,e as U,u as V,S as J,a3 as Y,a4 as se}from"./index-DEpNou_V.js";import{I as L}from"./input-BSL1lW-a.js";import{C as _}from"./checkbox-CQ04i8h-.js";import{A as H}from"./AuthScreenLayout-DL_3uMIA.js";import{G as te,F as ae,X as re,M as oe}from"./SocialIcons-DWGIwkB0.js";import{u as D}from"./i18n-vendor-Bg2yf_Zw.js";import{M as Q}from"./mail-CfO5b6mD.js";import{E as Z}from"./eye-off-B2yMnWvW.js";import{E as $}from"./eye-B2--pB_Q.js";import"./supabase-vendor-CNV44oIa.js";import"./helmet-vendor-NlTFkN97.js";import"./arrow-left-CIUyrgBf.js";const ee=({onGoogle:s,onFacebook:o,onX:c,onMicrosoft:y,loading:n,dividerKey:N})=>{const{t:i}=D("auth"),w=[{name:"Google",Icon:te,onClick:s,busy:n.google},{name:"Facebook",Icon:ae,onClick:o,busy:n.facebook},{name:"X",Icon:re,onClick:c,busy:n.x},{name:"Microsoft",Icon:oe,onClick:y,busy:n.microsoft}];return e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t border-border"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-page-surface px-2 text-muted-foreground",children:i(N)})})]}),e.jsx("div",{className:"mt-3 grid grid-cols-4 gap-2",children:w.map(({name:l,Icon:p,onClick:d,busy:m})=>e.jsx(B,{variant:"outline",className:"h-11 w-full",onClick:d,disabled:m,"aria-label":i("continueWithProvider",{provider:l,defaultValue:"Continue with {{provider}}"}),title:l,children:m?e.jsx("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-nature-coral border-t-transparent"}):e.jsx(p,{className:"h-6 w-6",alt:""})},l))})]})},be=()=>{const{t:s}=D("auth"),{getLocalizedPath:o}=U(),[c,y]=r.useState(""),[n,N]=r.useState(""),[i,w]=r.useState(!1),[l,p]=r.useState(!1),[d,m]=r.useState(!1),[A,I]=r.useState(!1),[E,S]=r.useState(!1),x=K(),u=O(),f=window.location.pathname.includes("reset-password"),{signIn:F,signInWithGoogle:g,signInWithFacebook:j,signInWithTwitter:G,signInWithMicrosoft:X,user:T,isLoading:C}=V();r.useEffect(()=>{if(T){const a=u.state?.redirectTo,t=sessionStorage.getItem("pendingAuthRedirect");a?x(a):t?(sessionStorage.removeItem("pendingAuthRedirect"),x(t)):x(o("/stories"))}},[T,x,u.state,o]);const[R,k]=r.useState(null);r.useEffect(()=>{k(null)},[c,n]);const P=async a=>{a.preventDefault();try{await F(c,n)}catch(t){console.error("Login error:",t),k("invalid_credentials")}},v=()=>{const a=u.state?.redirectTo;a&&sessionStorage.setItem("pendingAuthRedirect",a)},b=async()=>{try{p(!0),v(),await g()}catch(a){console.error("Google sign in error:",a)}finally{p(!1)}},W=async()=>{try{m(!0),v(),await j()}catch(a){console.error("Facebook sign in error:",a)}finally{m(!1)}},q=async()=>{try{I(!0),v(),await G()}catch(a){console.error("X sign in error:",a)}finally{I(!1)}},z=async()=>{try{S(!0),v(),await X()}catch(a){console.error("Microsoft sign in error:",a)}finally{S(!1)}};return e.jsxs(H,{art:"login",title:s("login.title"),children:[e.jsx(J,{title:s(f?"meta.resetPassword.title":"meta.login.title"),description:s(f?"meta.resetPassword.description":"meta.login.description"),keywords:f?void 0:s("meta.login.keywords"),canonical:f?window.location.pathname:"/login",noIndex:!0}),R&&e.jsxs("div",{className:"mb-4 rounded-lg border border-destructive/30 bg-destructive/5 p-4 text-sm",children:[e.jsx("p",{className:"font-medium text-destructive mb-2",children:s("login.errorTitle")}),e.jsxs("ul",{className:"space-y-1.5 text-muted-foreground",children:[e.jsx("li",{children:e.jsx(h,{to:o("/reset-password"),className:"text-nature-red hover:underline",children:s("login.forgotPassword")})}),e.jsx("li",{children:s("login.checkVerification")}),e.jsx("li",{children:e.jsx(h,{to:o("/signup"),className:"text-nature-red hover:underline",children:s("login.noAccountYet")})})]})]}),e.jsxs("form",{onSubmit:P,className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"email",className:"text-sm font-medium",children:s("login.email")}),e.jsxs("div",{className:"relative",children:[e.jsx(Q,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(L,{id:"email",type:"email",placeholder:"you@example.com",className:"pl-10",value:c,onChange:a=>y(a.target.value),required:!0})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("label",{htmlFor:"password",className:"text-sm font-medium",children:s("login.password")}),e.jsx(h,{to:o("/reset-password"),className:"text-xs text-nature-coral hover:underline",children:s("login.forgotPassword")})]}),e.jsxs("div",{className:"relative",children:[e.jsx(Y,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(L,{id:"password",type:i?"text":"password",placeholder:"•••••••",className:"pl-10 pr-10",value:n,onChange:a=>N(a.target.value),required:!0}),e.jsx("button",{type:"button",tabIndex:-1,onClick:()=>w(!i),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-muted-foreground hover:text-foreground",children:i?e.jsx(Z,{className:"h-4 w-4"}):e.jsx($,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{id:"remember"}),e.jsx("label",{htmlFor:"remember",className:"text-sm text-muted-foreground",children:s("login.rememberMe")})]}),e.jsx(B,{type:"submit",variant:"primary",size:"pill",className:"w-full",disabled:C,children:C?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),s("login.signingIn")]}):s("login.signIn")})]}),e.jsx(ee,{onGoogle:b,onFacebook:W,onX:q,onMicrosoft:z,loading:{google:l,facebook:d,x:A,microsoft:E},dividerKey:"login.orContinueWith"}),e.jsxs("p",{className:"mt-4 text-center text-sm text-muted-foreground",children:[s("login.noAccount")," ",e.jsx(h,{to:o("/signup"),state:u.state,className:"text-nature-coral font-medium hover:underline",children:s("login.signUpLink")})]})]})},ye=()=>{const{t:s}=D("auth"),{getLocalizedPath:o}=U(),[c,y]=r.useState(""),[n,N]=r.useState(""),[i,w]=r.useState(""),[l,p]=r.useState(!1),[d,m]=r.useState(!1),[A,I]=r.useState(!1),[E,S]=r.useState(!1),[x,u]=r.useState(!1),[f,F]=r.useState(!1),g=K(),j=O(),{signUp:G,signInWithGoogle:X,signInWithFacebook:T,signInWithTwitter:C,signInWithMicrosoft:R,user:k,isLoading:P}=V();r.useEffect(()=>{if(k){const t=j.state?.redirectTo,M=sessionStorage.getItem("pendingAuthRedirect");t?g(t):M?(sessionStorage.removeItem("pendingAuthRedirect"),g(M)):g(o("/stories"))}},[k,g,j.state,o]);const v=async t=>{if(t.preventDefault(),!!d)try{await G(n,i,"reader",c),g(o("/verify-email"),{state:{email:n},replace:!0})}catch(M){console.error("Sign up error:",M)}},b=()=>{const t=j.state?.redirectTo;t&&sessionStorage.setItem("pendingAuthRedirect",t)},W=async()=>{try{I(!0),b(),await X()}catch(t){console.error("Google sign in error:",t)}finally{I(!1)}},q=async()=>{try{S(!0),b(),await T()}catch(t){console.error("Facebook sign in error:",t)}finally{S(!1)}},z=async()=>{try{u(!0),b(),await C()}catch(t){console.error("X sign in error:",t)}finally{u(!1)}},a=async()=>{try{F(!0),b(),await R()}catch(t){console.error("Microsoft sign in error:",t)}finally{F(!1)}};return e.jsxs(H,{art:"signup",title:s("signup.title"),children:[e.jsx(J,{title:s("meta.signup.title"),description:s("meta.signup.description"),keywords:s("meta.signup.keywords",{defaultValue:""})||void 0,canonical:"/signup"}),e.jsxs("form",{onSubmit:v,className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"name",className:"text-sm font-medium",children:s("signup.readerName")}),e.jsxs("div",{className:"relative",children:[e.jsx(se,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(L,{id:"name",placeholder:"John Doe",className:"pl-10",value:c,onChange:t=>y(t.target.value),required:!0})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"signup-email",className:"text-sm font-medium",children:s("signup.email")}),e.jsxs("div",{className:"relative",children:[e.jsx(Q,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(L,{id:"signup-email",type:"email",placeholder:"you@example.com",className:"pl-10",value:n,onChange:t=>N(t.target.value),required:!0})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"signup-password",className:"text-sm font-medium",children:s("signup.password")}),e.jsxs("div",{className:"relative",children:[e.jsx(Y,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(L,{id:"signup-password",type:l?"text":"password",placeholder:"Create a strong password",className:"pl-10 pr-10",value:i,onChange:t=>w(t.target.value),required:!0}),e.jsx("button",{type:"button",tabIndex:-1,onClick:()=>p(!l),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-muted-foreground hover:text-foreground",children:l?e.jsx(Z,{className:"h-4 w-4"}):e.jsx($,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("signup.passwordRequirements")})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(_,{id:"terms",className:"mt-1",checked:d,onCheckedChange:t=>m(t===!0),required:!0}),e.jsxs("label",{htmlFor:"terms",className:"text-sm text-muted-foreground",children:[s("signup.agreeToTerms")," ",e.jsx(h,{to:o("/terms"),className:"text-nature-coral hover:underline",children:s("signup.termsOfService")})," ",s("signup.and")," ",e.jsx(h,{to:o("/privacy"),className:"text-nature-coral hover:underline",children:s("signup.privacyPolicy")}),s("signup.agreeToTermsEnd")]})]}),e.jsx(B,{type:"submit",variant:"primary",size:"pill",className:"w-full",disabled:P||!d,children:P?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 border-2 border-white border-t-transparent rounded-full animate-spin"}),s("signup.creatingAccount")]}):s("signup.createAccount")})]}),e.jsx(ee,{onGoogle:W,onFacebook:q,onX:z,onMicrosoft:a,loading:{google:A,facebook:E,x,microsoft:f},dividerKey:"signup.orContinueWith"}),e.jsxs("p",{className:"mt-4 text-center text-sm text-muted-foreground",children:[s("signup.haveAccount")," ",e.jsx(h,{to:o("/login"),state:j.state,className:"text-nature-coral font-medium hover:underline",children:s("signup.signInLink")})]})]})};export{be as LoginPage,ye as SignupPage};