import{w as v,c as j,m as y,j as C,L as N}from"./chunk-UIGDSWPH-BWkP6tD5.js";import{j as e}from"./jsx-runtime-C5WNSv3b.js";import{r as o}from"./index-Az39ZADK.js";import{u as R}from"./use-event-source-CrGUTTzj.js";import{a as b,B as k}from"./button-Ds94YjAg.js";import{L as S}from"./loading-DyvhEH4Q.js";import{L as w}from"./product-CGPgWFTC.js";import{u as T}from"./workshop-config-DCYN9tG7.js";import{aJ as _,o as c,s as l,l as d}from"./types-Cl2NuNg4.js";import"./misc-BapXpylh.js";import"./index-_LzGTKVC.js";import"./tooltip-C2AQeNhD.js";import"./index-CjiomtK6.js";import"./root-loader-C5P2c7MU.js";import"./pe-Bs-DFNma.js";const t={USER_CODE_RECEIVED:"USER_CODE_RECEIVED",AUTH_RESOLVED:"AUTH_RESOLVED",AUTH_REJECTED:"AUTH_REJECTED"},D=c({type:d(t.USER_CODE_RECEIVED),code:l(),url:l()}),L=c({type:d(t.AUTH_RESOLVED)}),A=c({type:d(t.AUTH_REJECTED),error:l().optional().default("Unknown error")}),U=_([D,L,A]),X={getSitemapEntries:()=>null},Z=v(function(){const{product:{displayName:r}}=T(),i=j(),[f,x]=o.useState(!1),[m,h]=o.useState(null),[a,E]=o.useState(null),u=y(),p=C(),n=R("/login-sse");return o.useEffect(()=>{if(!n)return;const g=JSON.parse(n),s=U.safeParse(g);if(!s.success){console.error(s.error.flatten());return}switch(s.data.type){case t.USER_CODE_RECEIVED:{E(s.data);break}case t.AUTH_RESOLVED:{p.revalidate().then(()=>u("/"));break}case t.AUTH_REJECTED:{h(s.data.error);break}}},[n,u,p]),e.jsx("main",{className:"flex h-full w-full grow flex-col items-center justify-center p-10",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(w,{className:"h-16 w-16"}),e.jsxs("h1",{className:"pt-5 text-2xl font-semibold md:text-3xl",children:["Login to ",r]}),e.jsxs("div",{className:"flex w-full flex-col items-center pt-5",children:[a?e.jsxs("div",{className:"flex w-full max-w-md 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-center text-lg font-bold dark:bg-black/40",children:e.jsx("code",{children:a.code})}),e.jsxs("p",{className:"text-base",children:["You'll use this to verify your device on ",r,". Click verify code below to open the verification page."]})]}),e.jsx(b,{varient:"primary",to:a.url,target:"_blank",rel:"noreferrer",onClick:()=>x(!0),children:"Verify Auth Code"}),f?e.jsxs("div",{className:"justify-center pt-5 text-center opacity-60",children:[e.jsx(S,{className:"justify-center",children:"Waiting for confirmation"}),e.jsxs("p",{className:"pt-2",children:["Please open"," ",e.jsx("a",{href:a.url,target:"_blank",className:"underline",children:"your auth page"})," ","in a new tab to continue."]})]}):null]}):e.jsxs("div",{className:"flex flex-col items-center gap-8",children:[e.jsxs("div",{className:"flex max-w-lg flex-col gap-3 pt-3 text-base text-gray-700 dark:text-gray-300",children:[e.jsxs("p",{children:["If you have access to this workshop on ",r,", you'll be able to watch videos, track progress, run tests, view the diffs, and more!"]}),e.jsxs("p",{children:["First you need to authenticate your device by requesting an access code and verifying on ",r,"."]})]}),e.jsx(i.Form,{method:"POST",children:e.jsx(k,{varient:"primary",type:"submit",children:i.state==="idle"&&i.data?.status!=="pending"?"Retrieve Auth Code":"Retrieving Auth Code..."})})]}),m?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-4 text-red-500",children:["There was an error: ",e.jsx("pre",{children:m})]}),e.jsxs("div",{className:"mt-4 text-red-500",children:["Please try again or"," ",e.jsx(N,{to:"/support",className:"underline",children:"contact support"})," ","if the problem persists."]})]}):null]})]})})});export{Z as default,X as handle};
//# sourceMappingURL=login-yLggg23y.js.map
