import{aI as s,ao as t,c4 as V,az as O,aj as B,bN as $,L as K,b5 as T,bC as X,f as R,e as w,gY as H,bq as M,m as J,v as U}from"./app-k0jcl5PQ.js";import{F as q}from"./kLXBNYk1.chunk.js";import{L as Y}from"./CIOPWeNI.chunk.js";import{C as z}from"./_XP6hjk3.chunk.js";import"./BCKXZxoz.chunk.js";const G="_input_dicjr_1",Q="_codeInputContainer_dicjr_5",F={input:G,codeInputContainer:Q},W=/^[0-9]$/,Z=/^\d+$/,E=8;function ee(x){const[a,b]=s.useState(""),[i,C]=s.useState(""),[u,y]=s.useState(""),[l,j]=s.useState(""),[f,P]=s.useState(""),S=s.useRef(null),g=s.useRef(null),d=s.useRef(null),L=s.useRef(null),A=s.useRef(null);s.useEffect(()=>{const e=(a||"X")+(i||"X")+(u||"X")+(l||"X")+(f||"X");x.onChange(e)},[a,i,u,l,f]);const n={"verify-1":{getNext:()=>n["verify-2"],getPrevious:()=>null,value:a,setState:b,focus:()=>S.current.focus()},"verify-2":{getNext:()=>n["verify-3"],getPrevious:()=>n["verify-1"],value:i,setState:C,focus:()=>g.current.focus()},"verify-3":{getNext:()=>n["verify-4"],getPrevious:()=>n["verify-2"],value:u,setState:y,focus:()=>d.current.focus()},"verify-4":{getNext:()=>n["verify-5"],getPrevious:()=>n["verify-3"],value:l,setState:j,focus:()=>L.current.focus()},"verify-5":{getNext:()=>null,getPrevious:()=>n["verify-4"],value:f,setState:P,focus:()=>A.current.focus()}};function v(e,k){var c,D;if(!W.test(e.key)&&e.keyCode!==E)return;const r=n[k];if(e.keyCode===E){r.setState(""),(c=r.getPrevious())==null||c.focus();return}if(e.currentTarget.selectionStart>0){const o=r.getNext();if(!o)return;o.setState(e.key),o.getNext()?o.getNext().focus():o.focus();return}r.setState(e.key),(D=r.getNext())==null||D.focus()}function m(e,k){e.preventDefault();const r=e.clipboardData.getData("text").trim();if(!Z.test(r))return;const c=r.split("");if(c.length===6){let p=n["verify-1"];for(const I of c)p.setState(I),p=p.getNext(),p==null||p.focus();return}let o=n[k];o.value&&o.getNext()&&(o=o.getNext());do o.focus(),o.setState(c.shift()),o=o.getNext();while(c.length&&o)}const h={className:`form-control h-100 fw-semibold mx-1 text-center ${F.input} ${x.hasError?"is-invalid":""}`,autoCorrect:"off",inputMode:"numeric",pattern:"[0-9]*",autoCapitalize:"off",autoComplete:"off"};return t.jsxs("fieldset",{className:`${F.codeInputContainer} d-flex justify-content-between`,"aria-describedby":"codeInputError",children:[t.jsx("input",{onPaste:e=>m(e,"verify-1"),onKeyDown:e=>v(e,"verify-1"),value:a,ref:S,onChange:()=>{},autoComplete:"off",...h}),t.jsx("input",{onPaste:e=>m(e,"verify-2"),onKeyDown:e=>v(e,"verify-2"),value:i,ref:g,onChange:()=>{},...h}),t.jsx("input",{onPaste:e=>m(e,"verify-3"),onKeyDown:e=>v(e,"verify-3"),value:u,ref:d,onChange:()=>{},...h}),t.jsx("input",{onPaste:e=>m(e,"verify-4"),onKeyDown:e=>v(e,"verify-4"),value:l,ref:L,onChange:()=>{},...h}),t.jsx("input",{onPaste:e=>m(e,"verify-5"),onKeyDown:e=>v(e,"verify-5"),value:f,ref:A,onChange:()=>{},...h})]})}const te="_logo_1o64u_1",oe="_formContainer_1o64u_5",se="_backButton_1o64u_8",_={logo:te,formContainer:oe,backButton:se},ne="classrooms.joinClassroomPrompt",N=K.encloseNamespace(ne),ae={application:w.LAUNCHPAD,action:R.Launchpad.LOGIN_LANDING,params:{showJoinCode:!0}},ie={application:w.DASHBOARD,action:R.Dashboard.HOME,args:[null]},re="X";function pe(){var g;const x=V(),[a,b]=s.useState(""),[i,C]=s.useState(""),[u,y]=s.useState(!1),l=O(B.currentUser());$({title:N("title")});function j(d){C(""),b(d)}function f(){U.trigger({application:w.LAUNCHPAD,action:R.Launchpad.JOIN_CLASSROOM,args:[a]})}function P(){C(N("invalid")),y(!1)}function S(d){d.preventDefault(),y(!0),J(x,z.checkJoinCode(a,f,P))}return t.jsx(Y,{children:t.jsx("div",{className:`${_.formContainer} m-auto`,children:t.jsxs("form",{onSubmit:S,children:[t.jsxs("div",{className:"text-center position-relative mb-3",children:[t.jsx("span",{className:`${_.backButton} position-absolute`,children:t.jsx(T,{appLink:(g=l.data)!=null&&g.isAuthenticated?ie:ae,svg:X})}),t.jsx("span",{className:`${_.logo} d-inline-block`,children:t.jsx(H,{})})]}),t.jsx("p",{className:"text-center",children:N("enterClassCode")}),t.jsxs("div",{className:"mx-4",children:[t.jsx(ee,{onChange:j,hasError:!!i}),!!i&&t.jsx(q,{name:"codeInput",children:i})]}),t.jsx(M,{showSpinner:u,className:"d-block w-75 mt-3 mx-auto btn-lg",variant:"dark",type:"submit",disabled:a.includes(re),children:N("next")})]})})})}export{pe as JoinClassroomPromptView};
//# sourceMappingURL=CG9Dalvt.chunk.js.map
