import{A as e,O as r,W as t,_t as s,gt as o,lt as n,mt as a,n as i,o as l,pt as c,yt as u}from"./render-cqdoDfd9.js";import{t as d}from"./Box-pvlRBLzs.js";import{t as m}from"./Typography-8v555lWC.js";import{t as p}from"./Paper-DtiadJnq.js";import{t as f}from"./Button-D-nJohaT.js";import{t as x}from"./Dialog-BdfDhNhZ.js";import{t as h}from"./Alert-BpUkH7Nx.js";import{t as j}from"./utils-C0ZHLGh_.js";import{t as _}from"./RequiredTextField-P1YoYBsM.js";function g(e){return a("MuiCard",e)}t("MuiCard",["root"]);var v=u(s()),y=n(),C=e=>{const{classes:r}=e;return c({root:["root"]},g,r)},k=e(p,{name:"MuiCard",slot:"Root"})({overflow:"hidden"}),w=v.forwardRef(function(e,t){const s=r({props:e,name:"MuiCard"}),{className:n,raised:a=!1,...i}=s,l={...s,raised:a};return(0,y.jsx)(k,{className:o(C(l).root,n),elevation:a?8:void 0,ref:t,ownerState:l,...i})}),S=({course_title:e,course_slug:r,organization_id:t,endpoint:s,onCancle:o,onComplete:n,autoFocusEmail:a=!1})=>{const c=v.useRef(""),[u,p]=v.useState(""),[g,C]=v.useState(!1),[k,w]=v.useState(j("csrftoken")),[S,b]=v.useState(!1),{localeMessages:T}=i();(0,v.useEffect)(()=>{k||b(!0)},[]),v.useEffect(()=>{if(!a)return;const e=setTimeout(()=>{c.current?.focus()},150);return()=>clearTimeout(e)},[a]);const E=()=>{(()=>{const e=c.current.value;return e?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)?(p(""),!0):(p(T.email_invalid),!1):(p(T.email_required),!1)})()&&(C(!0),fetch(s,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-CSRFToken":k},body:JSON.stringify({email:c.current.value,course_slug:r,organization_id:t})}).then(e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()}).then(e=>{C(!1),n()}).catch(e=>{C(!1),p(T.enrollment_failed)}))};return(0,y.jsxs)(d,{sx:{padding:4},children:[(0,y.jsxs)(m,{variant:"h3",children:[" ",T.enrol_for_course.replace("COURSE_NAME",e)]}),g?(0,y.jsx)(m,{variant:"body1",sx:{mt:2},children:(0,y.jsx)(l,{enableTrackSlot:!0,size:"30px"})}):(0,y.jsxs)(y.Fragment,{children:[u&&(0,y.jsx)(h,{severity:"error",sx:{mt:2},children:u}),(0,y.jsx)(_,{label:T.email,name:"email",type:"email",fullWidth:!0,margin:"normal",inputRef:c,onKeyDown:e=>{"Enter"===e.key&&E()}}),(0,y.jsx)("input",{type:"hidden",name:"course_slug",value:r}),(0,y.jsxs)(d,{sx:{mt:2,textAlign:"right"},children:[(0,y.jsx)(f,{variant:"outlined",sx:{mx:1},onClick:o,children:T.cancel}),(0,y.jsx)(f,{variant:"contained",color:"primary",type:"submit",onClick:E,children:T.submit})]})]}),(0,y.jsx)(x,{open:S,onClose:()=>b(!1),children:(0,y.jsxs)(d,{sx:{padding:4},children:[(0,y.jsx)(m,{variant:"h6",children:T.in_app_browser_or_disabled_cookies}),(0,y.jsx)(f,{variant:"contained",color:"primary",onClick:()=>window.location.reload(),children:T.continue})]})})]})};export{w as n,S as t};