import{ao as t,aI as P,bc as E,aO as H,ap as _,aq as A,ei as $,bq as q,aC as D,v as B,L as O,bN as G,az as N,ak as v,ay as F,p as V,bY as Y,f as z,e as K,c4 as M,dL as U,d as J,m as R}from"./app-k0jcl5PQ.js";import{A as Q}from"./BlBosctA.chunk.js";import{O as y}from"./BzSUSuAL.chunk.js";import{u as W}from"./Drs278fZ.chunk.js";import{P as X}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";function Z({width:e=60,height:a=24,count:i=6,align:u="left"}){const r=u==="center"?"justify-content-center":"justify-content-start";return t.jsx("ul",{className:`d-flex flex-wrap ps-0 ${r}`,children:Array(i).fill(null).map((c,d)=>t.jsx("li",{className:"partial-loading-background mb-1 rounded-pill list-unstyled",style:{height:`${a}px`,width:`${e}px`,marginRight:"0.25rem"}},d))})}const ee="_audienceList_p9fwe_1",te={audienceList:ee},I="subjects.audiencePreferences";function se(e){const[a,i]=P.useState([]),[u,r]=P.useState(!1),[c,d]=P.useState(e.bulkPreferencesState),f=y.hasBulkSelectedLevels(c),L=E();P.useEffect(()=>{var s;i(((s=e.preselections)==null?void 0:s.map(n=>n.masterId))??[])},[e.preselections]);const[k,j]=W(()=>{r(!1),e.isOnboarding||L.success(O.getPhrase(I,"success")),e.nextAppLink&&B.trigger(e.nextAppLink)});function o(s){return e.preselections?e.preselections.map(m=>m.masterId).sort().toString()!==s.sort().toString():!1}function l(){return e.bulkPreferencesState!==c}function g(){if(!a.length&&!f)return!1;const s=l()||o(a);return!(!e.isOnboarding&&!s)}function h(){var w;if(!g())return;if(!o(a)&&!l()){e.nextAppLink&&B.trigger(e.nextAppLink);return}r(!0);const s=a.filter(x=>{var S;return!((S=e.preselections)!=null&&S.find(C=>C.masterId===x))}).map(x=>{var S;return(S=e.options)==null?void 0:S.find(C=>C.masterId===x)}),n=(w=e.preselections)==null?void 0:w.filter(x=>!a.includes(x.masterId));let m=0;s!=null&&s.length&&m++,n!=null&&n.length&&m++,l()&&m++,j(m),e.saveChanges(s,n,c,k,()=>{L.error(O.getPhrase(I,"error")),r(!1)})}function p(s){const n=D.addOrRemoveImmutable(a,s.masterId);i(n)}function b(){const s=y.getNextBulkState(c,"audiences");d(s),y.hasBulkSelectedLevels(s)&&i([])}return t.jsx(H.Provider,{value:I,children:t.jsxs("form",{className:"d-flex flex-column gap-3",children:[t.jsx("div",{className:"position-relative",children:t.jsx("ul",{className:_("d-flex flex-wrap mb-0 ps-0 py-3 list-unstyled",te.audienceList),children:e.options.map(s=>t.jsx("li",{children:t.jsx(Q,{audience:s,highlight:a.includes(s.masterId),setAudience:p,isDisabled:f})},s.masterId))})}),t.jsxs("div",{className:"d-flex flex-column align-items-start gap-3",children:[t.jsxs("div",{className:"d-flex me-3",children:[t.jsx("p",{onClick:b,className:"me-2 mb-0 fw-bold",children:t.jsx(A,{phrase:"allLevels"})}),t.jsx($,{onClick:b,on:f,hideOutline:!0})]}),t.jsx(q,{variant:"dark",disabled:!g(),onClick:h,showSpinner:u,children:t.jsx(A,{phrase:e.isOnboarding?"next":"save"})})]})]})})}function ae(){return t.jsx("div",{className:"w-100 mx-auto py-3",children:t.jsx(Z,{})})}const T="settings.yearGroup",ne=O.encloseNamespace(T);function je(){var j;G({title:ne("pageTitle")});const e=N(v.availablePresentations()),a=N(v.allLevelPreferences()),i=N(v.myLevelPreferences()),{bulkOnboardingPreferencesState:u,isLoadingSettings:r,updateUserSetting:c}=F(V.PreferencesSettings),d=!!((j=a.data)!=null&&j.length)&&Y.shouldShowAudiences(a.data);P.useEffect(()=>{a.hasCompleted&&(d||B.trigger({application:K.SETTINGS,action:z.Settings.TOPIC_PREFERENCES},{replace:!0}))},[a.hasCompleted]);const f=M();function L(o,l,g,h,p){if(g!==u){const b={name:J.BulkOnboardingPreferencesState,value:g,kind:U.Setting};c(b,h,p)}o!=null&&o.length&&R(f,v.followLevels(o,h,p)),l!=null&&l.length&&R(f,v.unfollowLevels(l,h,p))}const k=!!a.hasCompleted&&!!i.hasCompleted&&!r;return t.jsxs(X,{availablePresentations:e.data,audiences:a.data,children:[t.jsx("p",{className:"mt-3",children:t.jsx(A,{namespace:T,phrase:"info"})}),k&&d?t.jsx(se,{options:a.data,preselections:i.data,bulkPreferencesState:u,saveChanges:L}):t.jsx(ae,{})]})}export{je as YearGroupProfileView};
//# sourceMappingURL=CLamb7Cq.chunk.js.map
