import{ai as x,aa as g,ah as l,P as c,j as e,Y as d,ab as p,aj as u,ak as b,k as m}from"./index-CHfgriyV.js";import{M as j}from"./main-D1eRPv4V.js";import{a as f,b as S}from"./mutations-B6Dg9yD6.js";import{a as v}from"./use-api-DB20qjVm.js";import"./useMutation-DgMLlnbr.js";function E(){const{returnUrl:o}=x.useSearch(),n=f(),i=S(),a=g({defaultValues:{email:""},onSubmit:async({value:t})=>{const s=`${window.location.origin}/${l.path}`;i.mutate({email:t.email,redirect:s},{onError:r=>{c({content:{children:r instanceof Error?r.message:"An error occurred",variant:"error"}})}})}}),h=()=>{const t=`${window.location.origin}/${l.path}?returnUrl=${encodeURIComponent(o)}`;n.mutate({redirect:t},{onSuccess:s=>{window.location.assign(s.URL)},onError:s=>{c({content:{children:s instanceof Error?s.message:"An error occurred",variant:"error"}})}})};return v({status:"logged_in",returnUrl:o}),e.jsx(j,{title:"Sign in to protect your backups",description:"Set up instant alerts to catch backup issues early — and get access to new features as we roll them out.",children:e.jsx(d,{className:"mt-10 sm:mx-auto sm:w-full sm:max-w-[480px]",children:e.jsx(d.Content,{padding:"xl",children:i.isSuccess?e.jsx("div",{children:e.jsxs("p",{className:"text-center font-semibold text-neutral-800 dark:text-neutral-100",children:["Check your email for a magic link to sign in",e.jsx("br",{}),e.jsx("button",{type:"button",className:"cursor-pointer text-xs underline",onClick:t=>{t.preventDefault(),i.reset(),a.reset()},children:"or login with a different email address"}),"."]})}):e.jsxs(e.Fragment,{children:[e.jsxs(p,{handleSubmit:a.handleSubmit,className:"space-y-6",children:[e.jsx(a.Field,{name:"email",validators:{...u,onSubmit:({value:t})=>{const s=u.onSubmit({value:t});if(s)return s;if(!/^\S+@\S+\.\S+$/.test(t))return"Please enter a valid email address"}},children:t=>e.jsx(b,{label:"Email address",placeholder:"nestor@plakar.io",isRequired:!0,isInvalid:t.state.meta.errors.length>0,value:t.state.value,onBlur:t.handleBlur,onChange:t.handleChange})}),e.jsx(a.Subscribe,{selector:t=>[t.canSubmit,t.isSubmitting],children:([t,s])=>e.jsx(m,{type:"submit",variant:"primary",isDisabled:!t,className:"w-full",isPending:s,children:"Send magic link"})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"relative my-8",children:[e.jsx("div",{"aria-hidden":"true",className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-gray-200"})}),e.jsx("div",{className:"relative flex justify-center text-sm/6 font-medium",children:e.jsx("span",{className:"text-primary bg-primary px-6",children:"Or continue with"})})]}),e.jsx(m,{className:"w-full",leftIcon:"github",variant:"secondary",onPress:h,isPending:n.isPending||n.isSuccess,children:"GitHub"})]})]})})})})}export{E as component};
