import{j as e}from"./query-vendor-CZu0EHPe.js";import{r,u as O,f as U,L as i}from"./react-vendor-0bvDbF03.js";import{e as _,u as B,S as V,P as J,a3 as K,B as n,a4 as re}from"./index-C-Kzd2Hj.js";import{I}from"./input-CDtLJ4Eq.js";import{C as Y}from"./checkbox-DCFR9tsl.js";import{G as H,F as Q,X as Z,M as $}from"./SocialIcons-DWGIwkB0.js";import{u as ee}from"./i18n-vendor-Bg2yf_Zw.js";import{M as se}from"./mail-BcYROgZQ.js";import{E as te}from"./eye-off-BQIUsZ5B.js";import{E as ae}from"./eye-Dy-5iICj.js";import"./supabase-vendor-CNV44oIa.js";import"./helmet-vendor-NlTFkN97.js";const fe=()=>{const{t:s}=ee("auth"),{getLocalizedPath:o}=_(),[g,G]=r.useState(""),[l,E]=r.useState(""),[h,X]=r.useState(!1),[x,k]=r.useState(!1),[p,L]=r.useState(!1),[N,v]=r.useState(!1),[b,y]=r.useState(!1),c=O(),d=U(),m=window.location.pathname.includes("reset-password"),{signIn:F,signInWithGoogle:u,signInWithFacebook:f,signInWithTwitter:A,signInWithMicrosoft:R,user:C,isLoading:T}=B();r.useEffect(()=>{if(C){const a=d.state?.redirectTo,t=sessionStorage.getItem("pendingAuthRedirect");a?c(a):t?(sessionStorage.removeItem("pendingAuthRedirect"),c(t)):c("/stories")}},[C,c,d.state]);const[W,S]=r.useState(null);r.useEffect(()=>{S(null)},[g,l]);const M=async a=>{a.preventDefault();try{await F(g,l)}catch(t){console.error("Login error:",t),S("invalid_credentials")}},j=()=>{const a=d.state?.redirectTo;a&&sessionStorage.setItem("pendingAuthRedirect",a)},w=async()=>{try{k(!0),j(),await u()}catch(a){console.error("Google sign in error:",a)}finally{k(!1)}},q=async()=>{try{L(!0),j(),await f()}catch(a){console.error("Facebook sign in error:",a)}finally{L(!1)}},z=async()=>{try{v(!0),j(),await A()}catch(a){console.error("X sign in error:",a)}finally{v(!1)}},D=async()=>{try{y(!0),j(),await R()}catch(a){console.error("Microsoft sign in error:",a)}finally{y(!1)}};return e.jsxs("div",{className:"min-h-screen flex items-center justify-center px-4 py-12 bg-page-surface",children:[e.jsx(V,{title:s(m?"meta.resetPassword.title":"meta.login.title"),description:s(m?"meta.resetPassword.description":"meta.login.description"),keywords:m?void 0:s("meta.login.keywords"),canonical:m?window.location.pathname:"/login",noIndex:!0}),e.jsx("div",{className:"page-card overflow-hidden max-w-md w-full",children:e.jsxs("div",{className:"p-6 sm:p-8",children:[e.jsx("div",{className:"flex justify-center mb-8",children:e.jsxs(i,{to:"/",className:"flex items-center gap-2",children:[e.jsx("img",{src:"https://cdn.storysparkle.org/logo_assets/favicon.webp",alt:"StorySparkle Logo",width:32,height:32,decoding:"async",className:"h-8 w-8"}),e.jsx(J,{variant:"auth"})]})}),e.jsx("h1",{className:"text-2xl font-bold mb-6 text-center",children:s("login.title")}),W&&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(i,{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(i,{to:o("/signup"),className:"text-nature-red hover:underline",children:s("login.noAccountYet")})})]})]}),e.jsxs("form",{onSubmit:M,className:"space-y-4",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(se,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(I,{id:"email",type:"email",placeholder:"you@example.com",className:"pl-10",value:g,onChange:a=>G(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(i,{to:"/reset-password",className:"text-xs text-nature-coral hover:underline",children:s("login.forgotPassword")})]}),e.jsxs("div",{className:"relative",children:[e.jsx(K,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(I,{id:"password",type:h?"text":"password",placeholder:"•••••••",className:"pl-10 pr-10",value:l,onChange:a=>E(a.target.value),required:!0}),e.jsx("button",{type:"button",tabIndex:-1,onClick:()=>X(!h),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-muted-foreground hover:text-foreground",children:h?e.jsx(te,{className:"h-4 w-4"}):e.jsx(ae,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Y,{id:"remember"}),e.jsx("label",{htmlFor:"remember",className:"text-sm text-muted-foreground",children:s("login.rememberMe")})]}),e.jsx(n,{type:"submit",variant:"primary",size:"pill",className:"w-full",disabled:T,children:T?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.jsxs("div",{className:"mt-6",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-white px-2 text-muted-foreground",children:s("login.orContinueWith")})})]}),e.jsxs("div",{className:"mt-4 grid grid-cols-2 gap-3",children:[e.jsxs(n,{variant:"outline",className:"w-full",onClick:w,disabled:x,children:[e.jsx(H,{className:"mr-2 h-6 w-6",alt:"Sign in with Google"}),x?"...":"Google"]}),e.jsxs(n,{variant:"outline",className:"w-full",onClick:q,disabled:p,children:[e.jsx(Q,{className:"mr-2 h-6 w-6",alt:"Sign in with Facebook"}),p?"...":"Facebook"]}),e.jsxs(n,{variant:"outline",className:"w-full",onClick:z,disabled:N,children:[e.jsx(Z,{className:"mr-2 h-6 w-6",alt:"Sign in with X"}),N?"...":"X"]}),e.jsxs(n,{variant:"outline",className:"w-full",onClick:D,disabled:b,children:[e.jsx($,{className:"mr-2 h-6 w-6",alt:"Sign in with Microsoft"}),b?"...":"Microsoft"]})]})]}),e.jsxs("p",{className:"mt-6 text-center text-sm text-muted-foreground",children:[s("login.noAccount")," ",e.jsx(i,{to:o("/signup"),state:d.state,className:"text-nature-coral font-medium hover:underline",children:s("login.signUpLink")})]})]})})]})},je=()=>{const{t:s}=ee("auth"),{getLocalizedPath:o}=_(),[g,G]=r.useState(""),[l,E]=r.useState(""),[h,X]=r.useState(""),[x,k]=r.useState(!1),[p,L]=r.useState(!1),[N,v]=r.useState(!1),[b,y]=r.useState(!1),[c,d]=r.useState(!1),[m,F]=r.useState(!1),u=O(),f=U(),{signUp:A,signInWithGoogle:R,signInWithFacebook:C,signInWithTwitter:T,signInWithMicrosoft:W,user:S,isLoading:M}=B();r.useEffect(()=>{if(S){const t=f.state?.redirectTo,P=sessionStorage.getItem("pendingAuthRedirect");t?u(t):P?(sessionStorage.removeItem("pendingAuthRedirect"),u(P)):u("/stories")}},[S,u,f.state]);const j=async t=>{if(t.preventDefault(),!!p)try{await A(l,h,"reader",g),u(o("/verify-email"),{state:{email:l},replace:!0})}catch(P){console.error("Sign up error:",P)}},w=()=>{const t=f.state?.redirectTo;t&&sessionStorage.setItem("pendingAuthRedirect",t)},q=async()=>{try{v(!0),w(),await R()}catch(t){console.error("Google sign in error:",t)}finally{v(!1)}},z=async()=>{try{y(!0),w(),await C()}catch(t){console.error("Facebook sign in error:",t)}finally{y(!1)}},D=async()=>{try{d(!0),w(),await T()}catch(t){console.error("X sign in error:",t)}finally{d(!1)}},a=async()=>{try{F(!0),w(),await W()}catch(t){console.error("Microsoft sign in error:",t)}finally{F(!1)}};return e.jsxs("div",{className:"min-h-screen flex items-center justify-center px-4 py-12 bg-page-surface",children:[e.jsx(V,{title:s("meta.signup.title"),description:s("meta.signup.description"),keywords:s("meta.signup.keywords",{defaultValue:""})||void 0,canonical:"/signup"}),e.jsx("div",{className:"page-card overflow-hidden max-w-md w-full",children:e.jsxs("div",{className:"p-6 sm:p-8",children:[e.jsx("div",{className:"flex justify-center mb-8",children:e.jsxs(i,{to:"/",className:"flex items-center gap-2",children:[e.jsx("img",{src:"https://cdn.storysparkle.org/logo_assets/favicon.webp",alt:"StorySparkle Logo",width:32,height:32,decoding:"async",className:"h-8 w-8"}),e.jsx(J,{variant:"auth"})]})}),e.jsx("h1",{className:"text-2xl font-bold mb-2 text-center",children:s("signup.title")}),e.jsx("p",{className:"text-muted-foreground text-center text-sm mb-6",children:s("signup.subtitle")}),e.jsxs("form",{onSubmit:j,className:"space-y-4",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(re,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(I,{id:"name",placeholder:"John Doe",className:"pl-10",value:g,onChange:t=>G(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(se,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(I,{id:"signup-email",type:"email",placeholder:"you@example.com",className:"pl-10",value:l,onChange:t=>E(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(K,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-muted-foreground h-4 w-4"}),e.jsx(I,{id:"signup-password",type:x?"text":"password",placeholder:"Create a strong password",className:"pl-10 pr-10",value:h,onChange:t=>X(t.target.value),required:!0}),e.jsx("button",{type:"button",tabIndex:-1,onClick:()=>k(!x),className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-muted-foreground hover:text-foreground",children:x?e.jsx(te,{className:"h-4 w-4"}):e.jsx(ae,{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(Y,{id:"terms",className:"mt-1",checked:p,onCheckedChange:t=>L(t===!0),required:!0}),e.jsxs("label",{htmlFor:"terms",className:"text-sm text-muted-foreground",children:[s("signup.agreeToTerms")," ",e.jsx(i,{to:o("/terms"),className:"text-nature-coral hover:underline",children:s("signup.termsOfService")})," ",s("signup.and")," ",e.jsx(i,{to:o("/privacy"),className:"text-nature-coral hover:underline",children:s("signup.privacyPolicy")}),s("signup.agreeToTermsEnd")]})]}),e.jsx(n,{type:"submit",variant:"primary",size:"pill",className:"w-full",disabled:M||!p,children:M?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.jsxs("div",{className:"mt-6",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-white px-2 text-muted-foreground",children:s("signup.orContinueWith")})})]}),e.jsxs("div",{className:"mt-4 grid grid-cols-2 gap-3",children:[e.jsxs(n,{variant:"outline",className:"w-full",onClick:q,disabled:N,children:[e.jsx(H,{className:"mr-2 h-6 w-6",alt:"Sign up with Google"}),N?"...":"Google"]}),e.jsxs(n,{variant:"outline",className:"w-full",onClick:z,disabled:b,children:[e.jsx(Q,{className:"mr-2 h-6 w-6",alt:"Sign up with Facebook"}),b?"...":"Facebook"]}),e.jsxs(n,{variant:"outline",className:"w-full",onClick:D,disabled:c,children:[e.jsx(Z,{className:"mr-2 h-6 w-6",alt:"Sign up with X"}),c?"...":"X"]}),e.jsxs(n,{variant:"outline",className:"w-full",onClick:a,disabled:m,children:[e.jsx($,{className:"mr-2 h-6 w-6",alt:"Sign up with Microsoft"}),m?"...":"Microsoft"]})]})]}),e.jsxs("p",{className:"mt-6 text-center text-sm text-muted-foreground",children:[s("signup.haveAccount")," ",e.jsx(i,{to:o("/login"),state:f.state,className:"text-nature-coral font-medium hover:underline",children:s("signup.signInLink")})]})]})})]})};export{fe as LoginPage,je as SignupPage};