import{aI as i,bc as C,ao as s,aO as E,gy as I,bS as G,bT as R,bq as F,L as A,v as P,ap as H,aq as b,ba as M,f as T,e as k,b5 as Y,bb as B,bK as D,ge as U,az as N,ak as L,b0 as _,bN as q,fO as z,bY as $}from"./app-k0jcl5PQ.js";import{a as K}from"./BcYgJJPz.chunk.js";import{P as V}from"./BpwqQXZV.chunk.js";import{u as W}from"./CECGJrz_.chunk.js";import{O as J,P as Q}from"./Kb3MNbLP.chunk.js";import"./DwDhXSrj.chunk.js";import"./EHuWazu9.chunk.js";import"./CCtuxSlD.chunk.js";import"./CPXlV0fg.chunk.js";import"./ApI7cEru.chunk.js";import"./DXxHdeNz.chunk.js";import"./CpGXOT1_.chunk.js";import"./DkDkjje4.chunk.js";import"./hKqzfsO4.chunk.js";import"./fstW5ZQE.chunk.js";import"./9ls1F1Ve.chunk.js";import"./DRKUY7jf.chunk.js";import"./BzSUSuAL.chunk.js";const j="subjects.schoolLevelSelector",h=A.encloseNamespace(j);function X(e){var f;const[r,o]=i.useState(!1),[n,g]=i.useState((f=e.currentSchoolLevel)==null?void 0:f.id),[l,c]=i.useState(!0),u=C();i.useEffect(()=>{e.isOnboarding&&e.currentSchoolLevel&&c(!1)},[e.isOnboarding,e.currentSchoolLevel]);function v(t){var a;c(((a=e.currentSchoolLevel)==null?void 0:a.id)===t.id),g(t.id)}function S(){var a;if(l)return;if(((a=e.currentSchoolLevel)==null?void 0:a.id)===n&&e.nextAppLink){P.trigger(e.nextAppLink);return}o(!0);const t=e.schoolLevels.find(x=>x.id===n);e.saveChanges(t,d,p)}function d(){if(o(!1),!e.isOnboarding){u.success(h("success")),c(!0);return}e.nextAppLink&&P.trigger(e.nextAppLink)}function p(){o(!1),u.error(A.getPhrase(j,"error"))}function m(){return e.isOnboarding?e.nextAppLink?h("next"):h("getStarted"):h("save")}return s.jsxs(E.Provider,{value:j,children:[s.jsx("form",{children:s.jsx("ul",{className:"row list-unstyled d-flex w-100",children:e.schoolLevels.map(t=>{var a;return t.type!==I.Subject?s.jsx(i.Fragment,{},t.id):s.jsx("li",{className:"col-md-4 col-12 pb-3 m-0",children:s.jsx(K,{data:t,coverUrl:G.createUrl((a=t.cover)==null?void 0:a.url,{size:R.Medium})||"",isSelected:n===t.id,onClick:()=>v(t)})},t.id)})})}),s.jsx(F,{variant:"dark",disabled:l,onClick:S,showSpinner:r,children:m()})]})}const y="settings.yearGroupAlert";function Z(e){return s.jsxs("div",{role:"alert",className:H("d-flex justify-content-between align-items-center bg-light-blue rounded p-2",e.className),children:[s.jsxs("div",{children:[s.jsx(b,{namespace:y,phrase:"body"})," ",s.jsx(M,{appLink:{application:k.SETTINGS,action:T.Settings.YEAR_GROUP_PROFILE},className:"text-info",children:s.jsx(b,{namespace:y,phrase:"link"})}),"."]}),s.jsx(Y,{svg:B,className:"text-blue",onClick:e.onDismiss})]})}const w="settings.schoolLevel",ee=A.encloseNamespace(w);function xe(){const{availablePresentations:e,hasCompleted:r}=D(),{setPreferredPresentation:o}=U(),{teachingLevel:n,setTeachingLevelFromPresentationAsync:g,isLoaded:l}=W(),c=N(L.allLevelPreferences()),u=N(L.availablePresentations()),v=_(),[S,d]=i.useState(!1);q({title:ee("pageTitle")});const p=e==null?void 0:e.find(t=>z.getMappedPresentationLevel(t.learningLevel)===(n==null?void 0:n.value)),{hasAnySubjectPresentations:m}=J.hasManyPresentationTypes(e);i.useEffect(()=>{r&&(m||P.trigger({application:k.SETTINGS,action:T.Settings.ABOUT_ME_PROFILE},{replace:!0}))},[r]);async function f(t,a,x){try{await Promise.all([o(t),g(t)]);const O=await v(L.allLevelPreferences());$.shouldShowAudiences(O)&&d(!0),a()}catch{x()}}return s.jsxs(Q,{availablePresentations:u.data,audiences:c.data,children:[S&&s.jsx(Z,{className:"mt-3",onDismiss:()=>d(!1)}),s.jsx("p",{className:"mt-3",children:s.jsx(b,{namespace:w,phrase:"info"})}),r&&m&&l?s.jsx(X,{schoolLevels:e,currentSchoolLevel:p,saveChanges:f}):s.jsx(V,{count:2})]})}export{xe as SchoolLevelProfileView};
//# sourceMappingURL=xUOWo-T1.chunk.js.map
