import{af as u,ag as m,ah as h,ai as p,ab as x,ac as s,aj as o,ak as l,J as c,j as t,al as g,B as d}from"./index-BX768Frx.js";import{a as b}from"./use-api-CjnAIHV2.js";import{M as j}from"./main-B6XIaWoX.js";import"./useQuery-DHwdh6Ld.js";import"./useBaseQuery-DCSHiJ5h.js";const f=async({email:i,redirect:a})=>(await u("/api/authentication/login/email",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:i,redirect:a})}),null),w=m({URL:h()}),y=async({redirect:i})=>{let a;const n="/api/authentication/login/github",e=await u(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({redirect:i})});try{a=await e.json()}catch{throw new Error(`the API endpoint ${n} returned HTTP/${e.status} with an invalid JSON payload`)}return w.parse(a)};function T(){const{returnUrl:i}=p.useSearch(),a=x({defaultValues:{email:""},onSubmit:async({value:n})=>{const e=`${window.location.origin}/${s.path}`,r=await o(()=>f({email:n.email,redirect:e}),l);if(r.error)throw c({content:{children:r.error.toString(),variant:"error"}}),r.error}});return b({status:"logged_in",returnUrl:i}),t.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:t.jsx("div",{className:"mt-10 sm:mx-auto sm:w-full sm:max-w-[480px]",children:t.jsx("div",{className:"bg-white px-6 py-12 shadow-sm sm:rounded-lg sm:px-12 dark:bg-neutral-800",children:t.jsx(a.Subscribe,{selector:n=>n.isSubmitted,children:n=>n?t.jsx("div",{children:t.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",t.jsx("br",{}),t.jsx("button",{type:"button",className:"cursor-pointer text-xs underline",onClick:e=>{e.preventDefault(),a.reset()},children:"or login with a different email address"}),"."]})}):t.jsxs(t.Fragment,{children:[t.jsxs("form",{className:"space-y-6",onSubmit:e=>{e.preventDefault(),e.stopPropagation(),a.handleSubmit()},children:[t.jsx(a.Field,{name:"email",validators:{onSubmit:({value:e})=>{if(!/^\S+@\S+\.\S+$/.test(e))return"Please enter a valid email address"}},children:e=>t.jsx(g,{label:"Email address",placeholder:"nestor@plakar.io",isRequired:!0,isInvalid:e.state.meta.errors.length>0,value:e.state.value,onBlur:e.handleBlur,onChange:e.handleChange})}),t.jsx(a.Subscribe,{selector:e=>[e.canSubmit,e.isSubmitting],children:([e,r])=>t.jsx(d,{type:"submit",variant:"primary",isDisabled:!e,className:"w-full",children:r?"...":"Send magic link"})})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"relative mt-10",children:[t.jsx("div",{"aria-hidden":"true",className:"absolute inset-0 flex items-center",children:t.jsx("div",{className:"w-full border-t border-gray-200"})}),t.jsx("div",{className:"relative flex justify-center text-sm/6 font-medium",children:t.jsx("span",{className:"bg-white px-6 text-neutral-800 dark:bg-neutral-800 dark:text-neutral-100",children:"Or continue with"})})]}),t.jsx("div",{className:"mt-6 grid grid-cols-2 gap-4",children:t.jsx(d,{leftIcon:"github",variant:"secondary",onPress:async()=>{const e=`${window.location.origin}/${s.path}?returnUrl=${encodeURIComponent(i)}`,r=await o(()=>y({redirect:e}),l);if(r.error){c({content:{children:r.error.toString(),variant:"error"}});return}window.location.href=r.data.URL},children:"GitHub"})})]})]})})})})})}export{T as component};
