import{bc as _,l as G,aP as J,R as S,o as P,j as e,dO as I,aR as Q,S as L,aQ as x,L as W,g as X,h as Y,i as Z}from"./app-BgLa5dit.js";import{S as ee}from"./CcviYpBC.chunk.js";import{S as C}from"./BixyE8L-.chunk.js";import{C as te}from"./BfMtaC_g.chunk.js";import{C as se,M as O}from"./CV1yHwBc.chunk.js";import{S as N}from"./CReApwJh.chunk.js";import{C as ne}from"./CsJ10TwK.chunk.js";import{C as U}from"./q-IBKcuF.chunk.js";import{a as oe,b as ae}from"./DT_qugzF.chunk.js";import"./DFA8aJel.chunk.js";import"./DUpYPoLs.chunk.js";import"./EZim8aq-.chunk.js";import"./BD9MrUJP.chunk.js";import"./s6cGcwlA.chunk.js";import"./Zwjmkasg.chunk.js";import"./4qGb1BIY.chunk.js";import"./DnXDEnAR.chunk.js";import"./DpUpv6rY.chunk.js";import"./CG7zbly5.chunk.js";import"./m4aqaK_l.chunk.js";import"./MEkA24R1.chunk.js";import"./C53kfXmd.chunk.js";const re={clearOnlineEntitySettings(s,c,u,n,p){const f=`/api/cache?keys=${`settings:entity:${s}`}`;return{url:`/ajax/online/${c}?endpoint=${encodeURIComponent(f)}`,key:`settings:cache:${s}`,type:_.DELETE,success:u,error:n,always:p}}};function ke(s){const c=G(),u=J(),[n,p]=S.useState(),[a,f]=S.useState(),[h,g]=S.useState(),[M,l]=S.useState(!1),m=P(U.customer(s.customerId)),H=P(U.customerFormationTemplate(s.customerId)),T=P(Q.currentUser()),b=P(N.setting(s.customerId,C.Topics)),{availableTopicPresentations:v,customerTopicPresentations:y,availableStreamablePresentations:R,customerStreamablePresentations:A}=oe(s.customerId);function D(){const t=[];return n&&t.push(n),a&&t.push(a),t}function $(){const t=b.data.value?[]:[C.Topics,C.NewDashboards];return s.newCustomer&&t.push(C.MustCompleteOnboarding),t}function w(){if(s.newCustomer){alert("Successfully set up Topics for this customer."),W.PageLoad(X.getHref({application:Z.CUSTOMERS,action:Y.Customers.MANAGE_CUSTOMER_TOPICS,args:[s.customerId]}));return}l(!1),c.success("Successfully saved customer presentations.")}function B(){const t=D();if(!t.length)return;const r=$();let i=0,E=0;const z=t.length+(r.length?1:0);function k(){E++,j()}function j(){var F;if(i++,i!==z)return;if(E<i||!((F=m.data.country)!=null&&F.code)){l(!1),alert("Something went wrong while setting up Topics for this customer. Please contact to the Product Team so that they look into the issue.");return}if(!r.length){w(),p(null),f(null);return}const o=re.clearOnlineEntitySettings(s.customerId,m.data.country.code,w,()=>{l(!1),alert("Successfully set up Topics but failed to clear Online cache. Please contact to the Product Team so that they look into the issue.")});x(u,o)}const q=t.map(o=>L.addCustomerToPresentation(s.customerId,o.id,k,j));r.length&&q.push(N.updateSettings(s.customerId,r.map(o=>({name:o,value:!0,kind:ee.FeatureFlag})),k,j)),q.forEach(o=>x(u,o))}function K(){if(!h)return;const t=L.removeCustomerFromPresentation(s.customerId,h.id,()=>c.success("Successfully removed customer from presentation."),r=>{var i;return c.error(((i=r.responseJSON)==null?void 0:i.message)||"Failed to remove presentation.")},()=>g(null));x(u,t)}if(!(!!T.data&&!!b.data&&!!m.data&&!!H.hasCompleted&&!!v.data&&!!R.data&&!!y.data&&!!A.data))return e.jsx(e.Fragment,{});const d=te.isDev(T.data),V=d&&(n||a);return e.jsxs(e.Fragment,{children:[e.jsx(ne,{customer:m.data}),!d&&e.jsx(se,{}),e.jsx("h2",{className:"mt-3 font-size-normal fw-bold",children:"Topic Presentations"}),e.jsx(O,{availablePresentations:ae(v.data,T.data,m.data),currentPresentations:y.data,onSelectPresentation:t=>p(t),removePresentation:t=>g(t),canEdit:d}),e.jsx("h2",{className:"mt-3 font-size-normal fw-bold",children:"Streamable Presentations"}),e.jsx(O,{availablePresentations:R.data,currentPresentations:A.data,onSelectPresentation:t=>f(t),removePresentation:t=>g(t),canEdit:d}),e.jsx("div",{className:"d-flex justify-content-end align-items-center pt-3",children:d&&e.jsx("button",{className:"btn btn-dark",onClick:()=>l(!0),disabled:!V,children:"Save"})}),M&&e.jsxs(I,{title:"Confirmation needed",onClickConfirm:B,closePopup:()=>l(!1),children:[b.data.value?e.jsx("p",{children:"Are you sure you want to add this customer to:"}):e.jsx("p",{children:"Are you sure you want enable Topics for this customer and add it to the following presentations:"}),e.jsxs("ul",{children:[n&&e.jsxs("li",{children:[e.jsx("strong",{children:"Topic Presentation:"})," ",n.name]}),a&&e.jsxs("li",{children:[e.jsx("strong",{children:"Streamable Learning Presentation:"})," ",a.name]})]})]}),h&&e.jsx(I,{title:"Confirmation needed",onClickConfirm:K,closePopup:()=>g(null),children:e.jsxs("p",{children:["Are you sure you want to remove this customer from ",e.jsx("strong",{children:h.name}),"?"]})})]})}export{ke as ManageCustomerTopicsView};
//# sourceMappingURL=CQpLC0ht.chunk.js.map
