import{ge as E,i1 as R,bN as D,hZ as q,b0 as B,az as j,ak as r,aI as v,ao as s,aq as i,r as P,dJ as L,aC as T}from"./app-k0jcl5PQ.js";import{A as z}from"./BlBosctA.chunk.js";import{u as F,a as H,O as d,b as K,c as S}from"./JiP4blAc.chunk.js";import{L as U}from"./C_Or9fFB.chunk.js";import{M as G}from"./Pc6wfgHx.chunk.js";import"./BZ-tsgAq.chunk.js";import"./CCKlkV4O.chunk.js";import"./CECGJrz_.chunk.js";import"./Cq8Wr_gd.chunk.js";const J="onboarding.audiencePreferences",V=q["audience-preferences"];function te(A){var h,g;const{onClickBack:k,completeStepAsync:y,onSaveError:C}=F(A.redirectUrl),{logEvent:l}=H(),{preferredPresentation:O}=E(),m=R();D({title:V.getPageTitle()});const f=B(),u=j(r.allLevelPreferences()),a=j(r.myLevelPreferences()),[n,p]=v.useState([]);v.useEffect(()=>{var e;!a.hasCompleted||!((e=a.data)!=null&&e.length)||p(a.data.map(o=>o.masterId))},[a.hasCompleted,(h=a.data)==null?void 0:h.length]);const c=m&&!n.length;function N(e){l(P.Select,L.SelectAudience,{audienceId:e.masterId,audienceName:e.name}),p(T.addOrRemoveImmutable(n,e.masterId))}async function w(){l(P.Click,L.Next,{audienceIds:n,skipped:c});try{if(!c){const e=[],o=(a.data||[]).map(t=>t.masterId),x=n.filter(t=>!o.includes(t)).map(t=>{var b;return(b=u.data)==null?void 0:b.find(M=>M.masterId===t)}).filter(t=>!!t),I=(a.data||[]).filter(t=>!n.includes(t.masterId));x.length&&e.push(f(r.followLevels(x))),I.length&&e.push(f(r.unfollowLevels(I))),await Promise.all(e)}await y()}catch{C()}}return s.jsxs(d,{namespace:J,children:[s.jsx(d.Left,{className:"bg-ultramarine d-flex flex-column align-items-end justify-content-center",children:s.jsx(U,{contentPosition:"right",children:s.jsx(G,{presentation:O})})}),s.jsxs(d.Right,{hasCustomButtons:!1,onClickNext:w,onClickBack:k,disableNext:!m&&!n.length,nextText:c?s.jsx(i,{phrase:"skip"}):void 0,children:[s.jsx(K,{children:s.jsx(i,{phrase:"heading"})}),s.jsx(S,{className:"mb-3",children:s.jsx(i,{phrase:"info"})}),s.jsx("ul",{className:"d-flex flex-wrap mb-0 ps-0 list-unstyled",children:(g=u.data)==null?void 0:g.map(e=>s.jsx(z,{audience:e,highlight:n.includes(e.masterId),setAudience:N,size:"lg"},e.masterId))}),s.jsx(S,{className:"mt-3",children:s.jsx(i,{phrase:"addMoreLater"})})]})]})}export{te as OnboardingAudiencePreferencesView};
//# sourceMappingURL=sTbnN9uD.chunk.js.map
