import{R as p,j as e,B as u,T as n,a0 as _,n as b,r as m}from"./render-CsAa6Dr_.js";import{L as C}from"./Layout-BVMWwqFc.js";import{R as z}from"./RequiredTextField-Bz89YX4-.js";import{g as R,G as y}from"./utils-B_PI31II.js";import{A as M}from"./Alert-C1JjHWpG.js";import{B as f}from"./Button-DRzV9gyj.js";import{b as S}from"./Dialog-DXg9g5Sc.js";import"./Container-BAbMFKjx.js";const k=({course_title:g,course_slug:a,organization_id:x,endpoint:t,onCancle:i,onComplete:c})=>{const l=p.useRef(""),[d,s]=p.useState(""),[h,o]=p.useState(!1),v=()=>{const r=l.current.value;return r?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)?(s(""),!0):(s(localeMessages.email_invalid),!1):(s(localeMessages.email_required),!1)},j=()=>{v()&&(o(!0),fetch(t,{method:"POST",headers:{"Content-Type":"application/json","X-CSRFToken":R("csrftoken")},body:JSON.stringify({email:l.current.value,course_slug:a,organization_id:x})}).then(r=>{if(!r.ok)throw new Error("Network response was not ok");return r.json()}).then(r=>{o(!1),c()}).catch(r=>{o(!1),s(localeMessages.enrollment_failed)}))};return e.jsxs(u,{sx:{padding:4,minWidth:"400px"},children:[e.jsxs(n,{variant:"h3",children:[" ",localeMessages.enrol_for_course.replace("COURSE_NAME",g)]}),h?e.jsx(n,{variant:"body1",sx:{mt:2},children:e.jsx(_,{enableTrackSlot:!0,size:"30px"})}):e.jsxs(e.Fragment,{children:[d&&e.jsx(M,{severity:"error",sx:{mt:2},children:d}),e.jsx(z,{label:localeMessages.email,name:"email",type:"email",fullWidth:!0,margin:"normal",inputRef:l,onKeyDown:r=>{r.key==="Enter"&&j()}}),e.jsx("input",{type:"hidden",name:"course_slug",value:a}),e.jsxs(u,{sx:{mt:2,textAlign:"right"},children:[e.jsx(f,{variant:"outlined",sx:{mx:1},onClick:i,children:localeMessages.cancel}),e.jsx(f,{variant:"contained",color:"primary",type:"submit",onClick:j,children:localeMessages.submit})]})]})]})};function E(){const[g,a]=m.useState(!1),[x,t]=m.useState(null),[i,c]=m.useState([]);m.useEffect(()=>{for(let s of organization.courses)s.enrolled=!1;c(organization.courses)},[]);const l=s=>{t(e.jsx(k,{course_title:s.title,course_slug:s.slug,organization_id:organization.id,endpoint:enrollApiUrl,onCancle:()=>{a(!1),t(null)},onComplete:()=>d(s)})),a(!0)},d=s=>{a(!1),t(null);let h=i.map(o=>o.id===s.id?{...o,enrolled:!0}:o);c(h)};return e.jsxs(C,{children:[organization.logo_url&&e.jsx("img",{src:organization.logo_url,alt:`${organization.name} Logo`,style:{maxWidth:"200px",height:"auto"}}),e.jsx(n,{variant:"h1",children:organization.name}),e.jsx(n,{variant:"body1",dangerouslySetInnerHTML:{__html:organization.description}}),e.jsxs(u,{my:4,children:[e.jsxs(n,{variant:"h2",children:[localeMessages.courses,":"]}),organization.courses.length>0?e.jsx(y,{container:!0,spacing:2,children:i.map(s=>e.jsx(y,{size:{xs:12,md:6},children:e.jsxs(u,{mb:2,p:2,border:1,borderRadius:2,sx:{minHeight:"100%"},children:[e.jsx(n,{variant:"h3",children:s.title}),e.jsx(f,{variant:"contained",color:"primary",rel:"noopener noreferrer",sx:{mt:1,mb:2},onClick:()=>l(s),disabled:s.enrolled,children:localeMessages.enroll_now}),e.jsx(n,{variant:"body2",dangerouslySetInnerHTML:{__html:s.description}}),s.enrolled&&e.jsx(M,{severity:"success",sx:{mt:2},children:localeMessages.enrollment_success})]},s.id)},s.id))}):e.jsx(n,{variant:"body2",children:localeMessages.no_courses_available})]}),e.jsx(S,{open:g,onClose:()=>a(!1),children:x})]})}b({children:e.jsx(E,{})});
//# sourceMappingURL=organization-Jg9sWWSJ.js.map
