import{w as g,f as j,e as y,l as C,L as N}from"./chunk-EPOLDU6W-BCLmut3y.js";import{j as e}from"./jsx-runtime-C5WNSv3b.js";import{r as a}from"./index-CqIc3cxq.js";import{u as R}from"./use-event-source-BuD4_2SF.js";import{a as S,B as b}from"./button-Cd-ekki5.js";import{L as w}from"./loading-CDNzW5oO.js";import{L as _}from"./product-CvyMpYD_.js";import{u as k}from"./workshop-config-Zfc8zU0x.js";import{u as D,o as c,s as l,l as d}from"./schemas-Uj5SZtvt.js";import"./misc-W4055b-0.js";import"./index-CdzVFL-Z.js";import"./tooltip-Tlsyx2YO.js";import"./index-vDCSPjrM.js";import"./root-loader-BOzEMapJ.js";import"./pe-CIZUOJMr.js";const t={USER_CODE_RECEIVED:"USER_CODE_RECEIVED",AUTH_RESOLVED:"AUTH_RESOLVED",AUTH_REJECTED:"AUTH_REJECTED"},L=c({type:d(t.USER_CODE_RECEIVED),code:l(),url:l()}),T=c({type:d(t.AUTH_RESOLVED)}),A=c({type:d(t.AUTH_REJECTED),error:l().optional().default("Unknown error")}),U=D([L,T,A]),X={getSitemapEntries:()=>null},Z=g(function(){const{product:{displayName:r}}=k(),i=j(),[p,x]=a.useState(!1),[u,h]=a.useState(null),[o,E]=a.useState(null),m=y(),f=C(),n=R("/login-sse");return a.useEffect(()=>{if(!n)return;const v=JSON.parse(n),s=U.safeParse(v);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:{f.revalidate().then(()=>m("/"));break}case t.AUTH_REJECTED:{h(s.data.error);break}}},[n,m,f]),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(_,{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:[o?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:"bg-muted mb-3 w-full px-5 py-3 text-center text-lg font-bold",children:e.jsx("code",{children:o.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(S,{varient:"primary",to:o.url,target:"_blank",rel:"noreferrer",onClick:()=>x(!0),children:"Verify Auth Code"}),p?e.jsxs("div",{className:"justify-center pt-5 text-center opacity-60",children:[e.jsx(w,{className:"justify-center",children:"Waiting for confirmation"}),e.jsxs("p",{className:"pt-2",children:["Please open"," ",e.jsx("a",{href:o.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:"text-muted-foreground flex max-w-lg flex-col gap-3 pt-3 text-base",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(b,{varient:"primary",type:"submit",children:i.state==="idle"&&i.data?.status!=="pending"?"Retrieve Auth Code":"Retrieving Auth Code..."})})]}),u?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-foreground-destructive mt-4",children:["There was an error: ",e.jsx("pre",{children:u})]}),e.jsxs("div",{className:"text-foreground-destructive mt-4",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-mWjVXGbJ.js.map
