import{w as y,c as j,m as b,j as R,L as N}from"./chunk-UIGDSWPH-fNK8sKgt.js";import{j as e}from"./jsx-runtime-C_974cfT.js";import{r as o}from"./index-BDZD4X5K.js";import{u as w}from"./use-event-source-CuGNSRa_.js";import{a as C,B as S}from"./button-C4PPjTg6.js";import{L as T}from"./loading-B_A7E1hQ.js";import{L as k}from"./product-CJaUV7TJ.js";import{u as _}from"./workshop-config-C5QE7ew3.js";import{aJ as D,o as c,s as l,l as d}from"./types-D4aTVJpv.js";import"./misc-BOyXKFuR.js";import"./index-bXLUfgPf.js";import"./tooltip-Dl4Bqfpf.js";import"./index-L8976fcQ.js";import"./root-loader-BZ1M-egm.js";import"./pe-D3b-z7vI.js";(function(){try{var m=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};m.SENTRY_RELEASE={id:"3ea6c863933c57219be78eb06addfb47859d8df2"}}catch{}})();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()}),A=c({type:d(t.AUTH_RESOLVED)}),U=c({type:d(t.AUTH_REJECTED),error:l().optional().default("Unknown error")}),V=D([L,A,U]),X={getSitemapEntries:()=>null},Z=y(function(){const{product:{displayName:s}}=_(),i=j(),[h,x]=o.useState(!1),[f,E]=o.useState(null),[a,g]=o.useState(null),u=b(),p=R(),n=w("/login-sse");return o.useEffect(()=>{if(!n)return;const v=JSON.parse(n),r=V.safeParse(v);if(!r.success){console.error(r.error.flatten());return}switch(r.data.type){case t.USER_CODE_RECEIVED:{g(r.data);break}case t.AUTH_RESOLVED:{p.revalidate().then(()=>u("/"));break}case t.AUTH_REJECTED:{E(r.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(k,{className:"h-16 w-16"}),e.jsxs("h1",{className:"pt-5 text-2xl font-semibold md:text-3xl",children:["Login to ",s]}),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 ",s,". Click verify code below to open the verification page."]})]}),e.jsx(C,{varient:"primary",to:a.url,target:"_blank",rel:"noreferrer",onClick:()=>x(!0),children:"Verify Auth Code"}),h?e.jsxs("div",{className:"justify-center pt-5 text-center opacity-60",children:[e.jsx(T,{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 ",s,", 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 ",s,"."]})]}),e.jsx(i.Form,{method:"POST",children:e.jsx(S,{varient:"primary",type:"submit",children:i.state==="idle"&&i.data?.status!=="pending"?"Retrieve Auth Code":"Retrieving Auth Code..."})})]}),f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-4 text-red-500",children:["There was an error: ",e.jsx("pre",{children:f})]}),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-Dbh-e98X.js.map
