import{w as y,c as j,m as b,h as R,L as N}from"./chunk-UIGDSWPH-C8mvmDRm.js";import{j as e}from"./jsx-runtime-CbGirg_M.js";import{r as a}from"./index-BoRhKTB8.js";import{u as w}from"./use-event-source-ZDun4YKa.js";import{a as C,B as S}from"./button-D9Cejd2c.js";import{L as T}from"./loading-DGPrsY7f.js";import{L as _}from"./product-B2Y0C1YC.js";import{u as k}from"./workshop-config-C0r84dtp.js";import{aJ as D,o as c,s as l,l as d}from"./types-s0-I03ry.js";import"./misc-D4V-U9nd.js";import"./index-BN_canAo.js";import"./tooltip-DpaM3OdK.js";import"./index-BJDrpBtR.js";import"./root-loader-AwLG1D86.js";import"./pe-D6_3VIe8.js";(function(){try{var u=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};u.SENTRY_RELEASE={id:"28ce3948dcef68c9e8b5be7c5619a3bd17c18150"}}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}}=k(),i=j(),[h,x]=a.useState(!1),[m,E]=a.useState(null),[o,g]=a.useState(null),f=b(),p=R(),n=w("/login-sse");return a.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(()=>f("/"));break}case t.AUTH_REJECTED:{E(r.data.error);break}}},[n,f,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(_,{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:[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 ",s,". Click verify code below to open the verification page."]})]}),e.jsx(C,{varient:"primary",to:o.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: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 ",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..."})})]}),m?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-foreground-destructive mt-4",children:["There was an error: ",e.jsx("pre",{children:m})]}),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-CUsfkrfw.js.map
