import{a as w,j as e}from"./vendor-query-Brcc40-Y.js";import{u as v,b as k,s as p}from"./vendor-form-BQNAly2Z.js";import{u as S,a as L,I as g,B as E,t as N}from"./index-tN-ddyeb.js";import{b as P,L as x}from"./vendor-react-DP6BW_9B.js";import{A}from"./AuthLayout-DounjrD9.js";import{G as C,A as I}from"./GoogleAuthButton-N4KE3YsZ.js";import"./vendor-utils-ui5PHgZB.js";import"./vendor-zustand-CVDiRiMG.js";const M=k({email:p().email("Enter a valid email address"),password:p().min(1,"Password is required")});function V({open:s}){return s?e.jsxs("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]}):e.jsx("svg",{className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"})})}function B(s){var t;const r=(t=s==null?void 0:s.response)==null?void 0:t.data;return r?{message:Array.isArray(r.message)?r.message[0]:r.message,code:r.code}:{}}function q(){var c,u;const[s,r]=w.useState(!1),[o]=P(),t=S(),a=L(),n=o.get("error")==="google_auth_failed",h=o.get("email")??"",{register:l,handleSubmit:f,getValues:y,formState:{errors:d}}=v({resolver:N(M),defaultValues:{email:h}}),j=i=>t.mutate(i),m=t.error?B(t.error):{},b=m.code==="EMAIL_NOT_VERIFIED";return e.jsxs(A,{title:"Welcome back",subtitle:"Sign in to your Divyourday account",children:[e.jsx(C,{label:"Continue with Google"}),e.jsx(I,{}),e.jsxs("form",{onSubmit:f(j),noValidate:!0,className:"space-y-5",children:[e.jsx(g,{label:"Email address",type:"email",autoComplete:"email",placeholder:"you@example.com",error:(c=d.email)==null?void 0:c.message,...l("email")}),e.jsx(g,{label:"Password",type:s?"text":"password",autoComplete:"current-password",placeholder:"••••••••",error:(u=d.password)==null?void 0:u.message,rightElement:e.jsx("button",{type:"button",onClick:()=>r(i=>!i),className:"text-ink-muted hover:text-ink transition-colors","aria-label":s?"Hide password":"Show password",children:e.jsx(V,{open:s})}),...l("password")}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(x,{to:"/forgot-password",className:"text-sm text-primary hover:text-primary transition-colors",children:"Forgot password?"})}),(t.error||n)&&e.jsxs("div",{className:"rounded-xl border border-danger/30 bg-danger-subtle px-4 py-3 space-y-2",children:[e.jsx("p",{className:"text-sm text-danger",children:n?"Google sign-in failed. Please try again.":m.message??"Invalid email or password"}),b&&e.jsx("button",{type:"button",className:"text-sm font-medium text-primary hover:text-primary-hover disabled:opacity-60",disabled:a.isPending||a.isSuccess,onClick:()=>a.mutate(y("email")),children:a.isSuccess?"Verification email sent":a.isPending?"Sending…":"Resend verification email"})]}),e.jsx(E,{type:"submit",fullWidth:!0,size:"lg",loading:t.isPending,children:"Sign in"})]}),e.jsxs("p",{className:"mt-8 text-center text-sm text-ink-muted",children:["Don't have an account?"," ",e.jsx(x,{to:o.get("redirect")||o.get("email")?`/register?${o.toString()}`:"/register",className:"text-primary hover:text-primary-hover font-medium transition-colors",children:"Create one"})]})]})}export{q as default};
