import{w as y,f as b,e as j,l as R,L as w}from"./chunk-EVOBXE3Y-Bmgys8-c.js";import{j as e}from"./jsx-runtime-hUI6LOBV.js";import{r as i}from"./index-CFdT0RIo.js";import{u as N,L as C}from"./loading-Cf-_cX4u.js";import{a as _,B as S}from"./button-BYp3RcB5.js";import{L as D}from"./product-tE_ZTgJf.js";import{u as k}from"./workshop-config-BNvMPSev.js";import{u as T,o as d,s as c,l as u}from"./schemas-Bn3zadsT.js";import"./index-BiGqsMpe.js";import"./misc-BNcbB3dR.js";import"./tooltip-CoTdGGXz.js";import"./index-ZNADqOyW.js";import"./root-loader-ByAKsmmv.js";import"./pe-BRA_K7Pt.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"66e9b849450b819e11683314a547a341cb57f7d0"};var s=new t.Error().stack;s&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[s]="2ceaab23-fa2d-4745-b6c9-e16fa18840c3",t._sentryDebugIdIdentifier="sentry-dbid-2ceaab23-fa2d-4745-b6c9-e16fa18840c3")}catch{}})();const r={USER_CODE_RECEIVED:"USER_CODE_RECEIVED",AUTH_RESOLVED:"AUTH_RESOLVED",AUTH_REJECTED:"AUTH_REJECTED"},L=d({type:u(r.USER_CODE_RECEIVED),code:c(),url:c()}),A=d({type:u(r.AUTH_RESOLVED)}),U=d({type:u(r.AUTH_REJECTED),error:c().optional().default("Unknown error")}),I=T([L,A,U]),Q={getSitemapEntries:()=>null},X=y(function(){const{product:{displayName:s}}=k(),o=b(),[h,x]=i.useState(!1),[f,E]=i.useState(null),[n,g]=i.useState(null),m=j(),p=R(),l=N("/login-sse");return i.useEffect(()=>{if(!l)return;const v=JSON.parse(l),a=I.safeParse(v);if(!a.success){console.error(a.error.flatten());return}switch(a.data.type){case r.USER_CODE_RECEIVED:{g(a.data);break}case r.AUTH_RESOLVED:{p.revalidate().then(()=>m("/"));break}case r.AUTH_REJECTED:{E(a.data.error);break}}},[l,m,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(D,{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:[n?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:n.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(_,{varient:"primary",to:n.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(C,{className:"justify-center",children:"Waiting for confirmation"}),e.jsxs("p",{className:"pt-2",children:["Please open"," ",e.jsx("a",{href:n.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(o.Form,{method:"POST",children:e.jsx(S,{varient:"primary",type:"submit",children:o.state==="idle"&&o.data?.status!=="pending"?"Retrieve Auth Code":"Retrieving Auth Code..."})})]}),f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-foreground-destructive mt-4",children:["There was an error: ",e.jsx("pre",{children:f})]}),e.jsxs("div",{className:"text-foreground-destructive mt-4",children:["Please try again or"," ",e.jsx(w,{to:"/support",className:"underline",children:"contact support"})," ","if the problem persists."]})]}):null]})]})})});export{X as default,Q as handle};
//# sourceMappingURL=login-CjJUgGco.js.map
