import{l as R,k as F,R as d,o as j,j as e,dO as x,aR as k,S as P}from"./app-BgLa5dit.js";import{C as w}from"./BfMtaC_g.chunk.js";import{C as A,M as T}from"./CV1yHwBc.chunk.js";import{C as q}from"./CsJ10TwK.chunk.js";import{C as N}from"./q-IBKcuF.chunk.js";import{u as B,g as I}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";function te(o){const n=R(),f=F(),[s,p]=d.useState(),[a,u]=d.useState(),[v,c]=d.useState(!1),S=j(N.customer(o.customerId)),m=j(k.currentUser()),{availableCurriculumPresentations:C,customerCurriculumPresentations:h}=B(o.customerId);function g(){if(!s)return;const t=P.addCustomerToPresentation(o.customerId,s.id);f(t).then(()=>n.success("Successfully saved customer curriculum presentations.")).catch(l=>{var r;return n.error(((r=l.responseJSON)==null?void 0:r.message)||"Failed to add curriculum presentation.")}).finally(()=>{c(!1),p(null)})}function b(){if(!a)return;const t=P.removeCustomerFromPresentation(o.customerId,a.id);f(t).then(()=>n.success("Successfully removed the curriculum presentation.")).catch(l=>{var r;return n.error(((r=l.responseJSON)==null?void 0:r.message)||"Failed to remove curriculum presentation.")}).finally(()=>u(null))}if(!(!!m.data&&!!C.data&&!!h.data))return e.jsx(e.Fragment,{});const i=w.isDev(m.data),y=i&&s;return e.jsxs(e.Fragment,{children:[e.jsx(q,{customer:S.data}),!i&&e.jsx(A,{}),e.jsx("h2",{className:"mt-3 font-size-normal fw-bold",children:"Curriculum Presentations"}),e.jsx(T,{availablePresentations:I(C.data,m.data),currentPresentations:h.data,onSelectPresentation:t=>p(t),removePresentation:t=>u(t),canEdit:i}),e.jsx("div",{className:"d-flex justify-content-end align-items-center pt-3",children:i&&e.jsx("button",{className:"btn btn-dark",onClick:()=>c(!0),disabled:!y,children:"Save"})}),v&&e.jsxs(x,{title:"Confirmation needed",onClickConfirm:g,closePopup:()=>c(!1),confirmButtonVariant:"dark",children:[e.jsx("p",{children:"Are you sure you want enable Topics for this customer and add it to the following presentations:"}),e.jsx("ul",{children:s&&e.jsxs("li",{children:[e.jsx("strong",{children:"Curriculum Presentation:"})," ",s.name]})})]}),a&&e.jsx(x,{title:"Confirmation needed",onClickConfirm:b,closePopup:()=>u(null),confirmButtonVariant:"dark",children:e.jsxs("p",{children:["Are you sure you want to remove this customer from ",e.jsx("strong",{children:a.name}),"?"]})})]})}export{te as ManageCustomerCurriculumView};
//# sourceMappingURL=DHoAMBj-.chunk.js.map
