import{dm as d,dl as h,i as f,h as C,dn as M,dp as v,R as b,dq as y,j as i,ar as j,ap as x,dr as A,ai as k,o as p,S as g,w as E}from"./app-BgLa5dit.js";import{O}from"./B-fq6xxv.chunk.js";import{C as P}from"./CTg_3F42.chunk.js";const T={getColumnActionsFunction(e,s,t,l){function a(o){const c=s===h.Clips?f.CLIPS:f.INTERACTIVES,u=s===h.Clips?C.Clips.REMOVE_CLIP_CLASSIFICATION:C.Interactives.REMOVE_INTERACTIVE_CLASSIFICATION;return(t==null?void 0:t.find(n=>n.id===o.id))?[{label:"Remove",button:!0,appLink:{application:c,action:u,args:[o.id,e,s]},className:"btn btn-danger"}]:[{label:"Add",button:!0,className:"btn btn-dark",onClick:()=>{l(o.id)}}]}return a},getOnSuccessMessage(e,s){const t=d.singularizeMemberType(s);switch(e){case"add":return`Successfully added ${t} to topic.`;case"remove":return`Successfully removed ${t} from topic.`;default:return""}},getOnErrorMessage(e,s){const t=d.singularizeMemberType(s);switch(e){case"add":return`Failed to add ${t} to topic.`;case"remove":return`Failed to remove ${t} from topic.`;default:return""}},getClassificationPathsNames(e={},s="->"){var t;return(t=Object.keys(e))==null?void 0:t.reduce((l,a)=>(e[a].forEach(c=>{const u=c.map(r=>r.map(n=>n.name).join(` ${s} `));l[a]=u}),l),{})}};function F(e){var u,r;const s=d.singularizeMemberType(e.memberType),t=T.getClassificationPathsNames(e.classificationsPaths),l=(u=e.availableClassifications)==null?void 0:u.map(n=>{const m=e.presentations.find(S=>S.id===n.presentationId);return{...n,path:t==null?void 0:t[n.id],presentation:(m==null?void 0:m.name)??"",presentationDescription:(m==null?void 0:m.description)??""}}).filter(n=>!!n.presentation).sort((n,m)=>n.presentation>m.presentation?1:-1),a=M.getColumnSet(v.ObjectClassificationMapping),o=b.useMemo(()=>y({columns:a,columnData:e.columnData}),[e.columnData]),c=((r=e.availableClassifications)==null?void 0:r.length)&&!Object.keys(e.classificationsPaths).length;return i.jsxs(i.Fragment,{children:[i.jsx("h2",{className:"h6",children:"Topics"}),i.jsx("p",{children:`Select which available presentations to add the ${s} into.`}),(()=>{var n;return c?i.jsx("div",{className:"text-center p-5",children:i.jsx(j,{as:"div",animation:"border",role:"status"})}):(n=e.availableClassifications)!=null&&n.length?i.jsx(x,{theme:P,columns:o,data:l,enableSort:!0}):i.jsx("p",{className:"py-3",children:i.jsx("em",{children:`There are no available topics for this ${s}.
                Please ensure you've mapped the ${s} to a backbone subject first`})})})()]})}function R(e){const s=d.singularizeMemberType(e.memberType),l={actions:T.getColumnActionsFunction(e.objectId,e.memberType,e.objectMappedClassifications,e.onAddToClassification)};function a(c,u,r){return e.onSaveBackboneClassification(c,r)}return e.backboneClassificationTree&&e.presentations&&e.objectMappedBackboneClassifications?i.jsxs(i.Fragment,{children:[i.jsx(O,{object:e.object}),i.jsx("h2",{className:"h6",children:"Backbone Subjects"}),i.jsx("p",{children:`Select which backbone subjects this ${s} is mapped to.`}),i.jsx(A,{initialValues:{backboneClassificationIds:e.objectMappedBackboneClassifications.map(c=>c.id)},presentationType:k.Subject,subjectTree:e.backboneClassificationTree,saveSubjects:a,memberType:h.Clips,saveBtnText:"Save Backbone Subjects",allowMultiple:!0}),i.jsx(F,{memberType:e.memberType,availableClassifications:e.availableClassifications,presentations:e.presentations,classificationsPaths:e.objectClassificationPaths,columnData:l})]}):i.jsx("div",{className:"text-center p-5",children:i.jsx(j,{as:"div",animation:"border",role:"status"})})}function $(e){var o;const[s,t]=b.useState({}),l=e==null?void 0:e.join(","),a=p((e==null?void 0:e.length)&&g.classificationPaths(e));return b.useEffect(()=>{var u;if(!a.hasCompleted)return;const c={};(u=a==null?void 0:a.data)==null||u.map(r=>{const n=E.last(r==null?void 0:r[0]);c[n.id]||(c[n.id]=[]),c[n.id].push(r)}),t(c)},[l,a.hasCompleted,(o=a.data)==null?void 0:o.length]),s}function w(e=[]){var o;const[s,t]=b.useState([]),l=e.join(","),a=p(e.length&&g.mappedClassificationFromBackboneClassification(e));return b.useEffect(()=>{var c;((c=a.data)==null?void 0:c.length)!==0&&a.hasCompleted&&t(a.data)},[l,a.hasCompleted,(o=a.data)==null?void 0:o.length]),s}export{T as C,R as E,$ as a,w as u};
//# sourceMappingURL=Ceadws6c.chunk.js.map
