import{r as i,d as h,e as C,j as e}from"./index-Cdyla_OY.js";import{u as j}from"./use-event-source-C5YgVGej.js";import{z as t}from"./index-B8k-Gd1G.js";import{a as g,B as v}from"./button-DrREZEVu.js";import{L as R}from"./loading-B4dBNbEu.js";import{a as L}from"./components-B-E6uop2.js";import"./clsx-B-dksMZM.js";import"./client-hints-BdCVz-7u.js";const r={USER_CODE_RECEIVED:"USER_CODE_RECEIVED",AUTH_RESOLVED:"AUTH_RESOLVED",AUTH_REJECTED:"AUTH_REJECTED"},S=t.object({type:t.literal(r.USER_CODE_RECEIVED),code:t.string(),url:t.string()}),b=t.object({type:t.literal(r.AUTH_RESOLVED)}),w=t.object({type:t.literal(r.AUTH_REJECTED),error:t.string().optional().default("Unknown error")}),y=t.union([S,b,w]);function F(){var x;const s=L(),[u,E]=i.useState(!1),[n,f]=i.useState(null),[l,m]=i.useState(null),c=h(),d=C(),o=j("/login-sse");return i.useEffect(()=>{if(!o)return;const p=JSON.parse(o),a=y.safeParse(p);if(!a.success){console.error(a.error.flatten());return}switch(a.data.type){case r.USER_CODE_RECEIVED:{m(a.data);break}case r.AUTH_RESOLVED:{d.revalidate(),c("/");break}case r.AUTH_REJECTED:{f(a.data.error);break}}},[o,c,d]),e.jsx("main",{className:"flex h-full w-full flex-grow flex-col items-center justify-center p-10 text-center",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(_,{className:"h-16 w-16"}),e.jsx("h1",{className:"pt-5 text-2xl font-semibold md:text-3xl",children:"Authenticate with EpicWeb.dev"}),e.jsx("h2",{className:"max-w-sm pt-3 text-base text-gray-700 dark:text-gray-300",children:"If you have purchased Epic Web, you'll be able to watch videos, track progress, and more!"}),e.jsxs("div",{className:"flex w-full flex-col items-center pt-5",children:[l?e.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[e.jsxs("div",{className:"my-2 flex w-full flex-col items-center gap-2",children:[e.jsx("p",{className:"text-lg",children:"Your verification code is: "}),e.jsx("div",{className:"mb-3 w-full bg-gray-100 px-5 py-3 text-lg font-bold dark:bg-black/40",children:e.jsx("code",{children:l.code})})]}),e.jsx(g,{varient:"primary",to:l.url,target:"_blank",rel:"noreferrer",onClick:()=>E(!0),children:"Continue"}),u?e.jsx("div",{className:"pt-5 opacity-60",children:e.jsx(R,{children:"Waiting for confirmation"})}):null]}):e.jsx(s.Form,{method:"POST",children:e.jsx(v,{varient:"primary",type:"submit",children:s.state==="idle"&&((x=s.data)==null?void 0:x.status)!=="pending"?"Retrieve Code":"Retrieving Code..."})}),n?e.jsxs("div",{className:"mt-4 text-red-500",children:["There was an error: ",e.jsx("pre",{children:n})]}):null]})]})})}function _({className:s=""}){return e.jsxs("svg",{className:s,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[e.jsx("path",{d:"M12.438 11.5677C12.0131 11.8026 11.5249 12.0534 10.9784 12.3047C8.80704 13.3031 5.70429 14.314 1.986 14.3555L1.55773 14.3603L1.48003 13.9391C1.36509 13.316 1.29793 12.6714 1.29793 12.006C1.29793 6.10441 6.09863 1.30372 12.0002 1.30372C13.6287 1.30372 15.1745 1.66961 16.5585 2.32369L17.9801 1.59897C16.2189 0.582162 14.1769 0 12.0002 0C5.38709 0 0 5.38709 0 12.0002C0 14.6402 0.858474 17.0847 2.31072 19.0692C4.79741 18.6457 6.35749 17.6495 6.35749 17.6495C6.35749 17.6495 5.36137 19.2075 4.93785 21.6946C6.92114 23.1439 9.36321 24.0005 12.0002 24.0005C18.6134 24.0005 24.0005 18.6134 24.0005 12.0002C24.0005 9.82732 23.4199 7.78762 22.4053 6.02738L21.6818 7.44613C22.3364 8.83057 22.7025 10.3769 22.7025 12.006C22.7025 17.9076 17.9018 22.7083 12.0002 22.7083C11.3345 22.7083 10.6959 22.6411 10.0681 22.5264L9.646 22.4493L9.65079 22.0203C9.6923 18.2991 10.7031 15.1964 11.7016 13.0257C11.9527 12.4797 12.2033 11.9921 12.438 11.5677Z",fill:"url(#epicGradient)"}),e.jsx("path",{d:"M18.2525 9.31052L15.4992 8.50683L14.6953 5.74778L23.8291 0.171387L18.2525 9.31052Z",fill:"currentColor"}),e.jsx("defs",{children:e.jsxs("linearGradient",{id:"epicGradient",x1:"16.9703",y1:"7.03022",x2:"7.05798",y2:"16.948",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{stopColor:"#4F75FF"}),e.jsx("stop",{offset:"1",stopColor:"#30AFFF"})]})})]})}export{F as default};
//# sourceMappingURL=login-BK2nq-Ll.js.map
