import{g as _,a as S,r as f,u as k,j as e,s as R,c as E,b as w,$ as j,n as M,B as C,T as u,a0 as I,o as T}from"./render-BEL5IN7j.js";import{L as N}from"./Layout-BnY4rqXE.js";import{R as A}from"./RequiredTextField-egwBrnFU.js";import{g as F}from"./utils-MPtJ5ynp.js";import{A as b}from"./Alert-DGyy5JNc.js";import{B as y}from"./Button-CGPZXh3G.js";import{G as v}from"./Grid-CY2FZLhF.js";import{D as O}from"./Dialog-CGu6k_Gi.js";import"./Container-BJA-Qv7d.js";import"./Link-u7JOT8iP.js";import"./TextField-9E0h2GEt.js";import"./Select-DyY0x5OK.js";import"./formControlState-YO0xWqIm.js";import"./isMuiElement-e1vpiHuY.js";function P(a){return _("MuiCardMedia",a)}S("MuiCardMedia",["root","media","img"]);const z=a=>{const{classes:o,isMediaComponent:l,isImageComponent:r}=a;return w({root:["root",l&&"media",r&&"img"]},P,o)},D=R("div",{name:"MuiCardMedia",slot:"Root",overridesResolver:(a,o)=>{const{ownerState:l}=a,{isMediaComponent:r,isImageComponent:d}=l;return[o.root,r&&o.media,d&&o.img]}})({display:"block",backgroundSize:"cover",backgroundRepeat:"no-repeat",backgroundPosition:"center",variants:[{props:{isMediaComponent:!0},style:{width:"100%"}},{props:{isImageComponent:!0},style:{objectFit:"cover"}}]}),U=["video","audio","picture","iframe","img"],L=["picture","img"],B=f.forwardRef(function(o,l){const r=k({props:o,name:"MuiCardMedia"}),{children:d,className:g,component:t="div",image:c,src:n,style:x,...p}=r,s=U.includes(t),h=!s&&c?{backgroundImage:`url("${c}")`,...x}:x,m={...r,component:t,isMediaComponent:s,isImageComponent:L.includes(t)},i=z(m);return e.jsx(D,{className:E(i.root,g),as:t,role:!s&&c?"img":void 0,ref:l,style:h,ownerState:m,src:s?c||n:void 0,...p,children:d})}),$=({course_title:a,course_slug:o,organization_id:l,endpoint:r,onCancle:d,onComplete:g})=>{const t=j.useRef(""),[c,n]=j.useState(""),[x,p]=j.useState(!1),{localeMessages:s}=M(),h=()=>{const i=t.current.value;return i?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(i)?(n(""),!0):(n(s.email_invalid),!1):(n(s.email_required),!1)},m=()=>{h()&&(p(!0),fetch(r,{method:"POST",headers:{"Content-Type":"application/json","X-CSRFToken":F("csrftoken")},body:JSON.stringify({email:t.current.value,course_slug:o,organization_id:l})}).then(i=>{if(!i.ok)throw new Error("Network response was not ok");return i.json()}).then(i=>{p(!1),g()}).catch(i=>{p(!1),n(s.enrollment_failed)}))};return e.jsxs(C,{sx:{padding:4,minWidth:"400px"},children:[e.jsxs(u,{variant:"h3",children:[" ",s.enrol_for_course.replace("COURSE_NAME",a)]}),x?e.jsx(u,{variant:"body1",sx:{mt:2},children:e.jsx(I,{enableTrackSlot:!0,size:"30px"})}):e.jsxs(e.Fragment,{children:[c&&e.jsx(b,{severity:"error",sx:{mt:2},children:c}),e.jsx(A,{label:s.email,name:"email",type:"email",fullWidth:!0,margin:"normal",inputRef:t,onKeyDown:i=>{i.key==="Enter"&&m()}}),e.jsx("input",{type:"hidden",name:"course_slug",value:o}),e.jsxs(C,{sx:{mt:2,textAlign:"right"},children:[e.jsx(y,{variant:"outlined",sx:{mx:1},onClick:d,children:s.cancel}),e.jsx(y,{variant:"contained",color:"primary",type:"submit",onClick:m,children:s.submit})]})]})]})};function G(){const[a,o]=f.useState(!1),[l,r]=f.useState(null),[d,g]=f.useState([]),{organization:t,enrollApiUrl:c,localeMessages:n}=M();f.useEffect(()=>{for(let s of t.courses)s.enrolled=!1;g(t.courses)},[]);const x=s=>{r(e.jsx($,{course_title:s.title,course_slug:s.slug,organization_id:t.id,endpoint:c,onCancle:()=>{o(!1),r(null)},onComplete:()=>p(s)})),o(!0)},p=s=>{o(!1),r(null);let h=d.map(m=>m.id===s.id?{...m,enrolled:!0}:m);g(h)};return e.jsxs(N,{children:[t.logo_url&&e.jsx("img",{src:t.logo_url,alt:`${t.name} Logo`,style:{maxWidth:"200px",height:"auto"}}),e.jsx(u,{variant:"h1",children:t.name}),e.jsx(u,{variant:"body1",dangerouslySetInnerHTML:{__html:t.description}}),e.jsxs(C,{my:4,children:[e.jsxs(u,{variant:"h2",children:[n.courses,":"]}),t.courses.length>0?e.jsx(v,{container:!0,columnSpacing:2,rowSpacing:6,alignItems:"stretch",children:d.map(s=>e.jsx(v,{size:{xs:12,md:6},display:"flex",children:e.jsxs(C,{p:2,border:1,borderRadius:2,sx:{height:"100%",width:"100%"},children:[e.jsx(B,{component:s.image?"img":"div",image:s.image,sx:{height:360,backgroundColor:"grey.300",objectFit:"cover"}}),e.jsx(u,{variant:"h3",sx:{pt:2},children:s.title}),e.jsx(y,{variant:"contained",color:"primary",rel:"noopener noreferrer",sx:{mt:1,mb:2},onClick:()=>x(s),disabled:s.enrolled,children:n.enroll_now}),e.jsx(u,{variant:"body2",dangerouslySetInnerHTML:{__html:s.description}}),s.enrolled&&e.jsx(b,{severity:"success",sx:{mt:2},children:n.enrollment_success})]},s.id)},s.id))}):e.jsx(u,{variant:"body2",children:n.no_courses_available})]}),e.jsx(O,{open:a,onClose:()=>o(!1),children:l})]})}T({children:e.jsx(G,{})});
//# sourceMappingURL=organization-B2Lnwl_q.js.map
