import{j as n,ds as m,Y as d,h as l,i as o,dm as u,ar as r,dt as b,w as h,G as x,aw as j,di as v,az as p,ax as A,dj as k}from"./app-BgLa5dit.js";import{S as f}from"./AvyxFUsd.chunk.js";const g=e=>({application:o.SUBJECTS,action:l.Subjects.EDIT_AUDIENCE,args:[e.presentationId,e.masterId]}),L=e=>({application:o.SUBJECTS,action:l.Subjects.EDIT_LEVEL,args:[e.id]}),S=(e,i)=>{const s=e.backboneAudienceIds;return i.filter(t=>s.includes(t.id))};function I({showLevels:e}){return n.jsx("thead",{children:n.jsxs("tr",{children:[n.jsx("th",{children:"Audiences"}),!!e&&n.jsx("th",{children:"Mapped Backbone Audience(s)"})]})})}function y({audience:e,levels:i}){return n.jsxs("tr",{children:[n.jsx("td",{children:n.jsx(d,{appLink:g(e),children:e.name})}),n.jsx("td",{children:i.map(s=>n.jsx(d,{appLink:L(s),className:"me-2",children:s.name},s.id))})]})}function T({audiences:e,levels:i}){return n.jsxs(m,{responsive:!0,bordered:!0,children:[n.jsx(I,{showLevels:!!e.length}),n.jsx("tbody",{children:e.length?e.map(s=>n.jsx(y,{audience:s,levels:S(s,i)},s.masterId)):n.jsx("tr",{children:n.jsx("td",{children:"This presentation has no audiences."})})})]})}function w({objectAudiences:e,presentationAudiences:i}){return e.filter(s=>i.some(t=>t.masterId===s.masterId))}function E({presentationAudiences:e,objectLevels:i,objectAudiences:s}){if(!e||!i||!s)return[];const t=i.map(a=>a.id);return e.filter(a=>h.intersection(a.backboneAudienceIds,t).length||s.some(c=>c.masterId===a.masterId))}function N(e){const i=e.objectLevels&&e.presentations&&e.levels&&e.currentPresentation,s=i&&e.presentationAudiences,t=u.singularizeMemberType(e.memberType),a=E(e);return i?n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"border-bottom pb-3 mb-3",children:[n.jsx("h6",{children:"Backbone Audiences"}),n.jsx("p",{children:`Select which backbone audiences this ${t} is mapped to.`}),n.jsx("p",{children:"To see how backbone audiences correspond to audiences, scroll down to the audience-backbone audience mappings table."}),n.jsx(F,{initialValues:{backboneAudienceIds:e.objectLevels.map(c=>c.id)},saveLevels:e.saveLevels,levels:e.levels,memberType:e.memberType})]}),n.jsx("h6",{children:"Audiences"}),n.jsx("p",{children:`Select a presentation to view its audiences and map them to this ${t}.`}),n.jsx("div",{className:"w-50 pb-3",children:n.jsx(b,{presentations:e.presentations,currentPresentationId:e.currentPresentation.id,setCurrentPresentation:e.setCurrentPresentation})}),s?n.jsxs(n.Fragment,{children:[n.jsx("p",{children:"Audience to backbone audience mappings for this presentation are displayed below."}),n.jsx(T,{levels:e.levels,audiences:e.presentationAudiences}),n.jsx("p",{children:`Only the audiences which are mapped to a backbone audience that this ${t} is mapped to are displayed below.`}),!!a.length&&n.jsx(f,{initialValues:{audienceIds:w(e).map(c=>c.masterId)},saveAudiences:e.saveAudiences,audiences:a})]}):n.jsx("div",{className:"text-center p-5",children:n.jsx(r,{as:"div",animation:"border",role:"status"})})]}):n.jsx("div",{className:"text-center pt-5",children:n.jsx(r,{as:"div",animation:"border",role:"status"})})}function C(e){const i=u.singularizeMemberType(e.memberType),s=j(),t=v(s);return n.jsxs(p,{children:[n.jsx(A,{label:"Backbone Audience(s)",as:"select",name:"backboneAudienceIds",id:"level-ids",multiple:!0,size:e.levels.length,value:s.values.backboneAudienceIds,children:e.levels.map(a=>n.jsx("option",{value:a.id,children:a.name},a.id))}),n.jsxs("p",{children:[n.jsx("strong",{children:"Note:"}),` When removing a ${i} from a backbone audience, that backbone audience's mapped audiences `,n.jsx("strong",{children:"will not"})," be automatically removed from."]}),n.jsx("div",{className:"d-flex justify-content-end",children:n.jsx(k,{showSpinner:s.isSubmitting,type:"submit",disabled:!t,children:"Save Backbone Audience"})})]})}function F(e){const i=({backboneAudienceIds:s},t)=>e.saveLevels(s,!1,t);return n.jsx(x,{initialValues:e.initialValues,onSubmit:i,children:n.jsx(C,{levels:e.levels,memberType:e.memberType})})}export{N as E};
//# sourceMappingURL=KB6Isaz1.chunk.js.map
