import{k as M,l as K,o as l,r as g,p as O,ct as s,w as W,aV as V,j as t,h as X,ar as Q,aT as Y,aj as d,aR as z,s as p,dw as D,dx as E}from"./app-BgLa5dit.js";import{O as J}from"./B-fq6xxv.chunk.js";import{S as Z}from"./BSa28HTr.chunk.js";import{E as q}from"./kJGoOu-N.chunk.js";import{T as $,S as L}from"./CEzAQXMv.chunk.js";import"./EZim8aq-.chunk.js";import"./BfMtaC_g.chunk.js";import"./w68yffRy.chunk.js";function h(a,o){return Y.useMemo(()=>d.getTagsByType(a,o),[a==null?void 0:a.length])}function re(a){var I,N,k,w;const o=M(),i=K(),y=l(z.currentUser()),S=l(g.clip(a.clipId)),f=l(O.getAssemblyLineVideo(a.clipId)),c=l(g.clipTagsByType(a.clipId,[s.Normal,s.Pedagogy,s.Hidden,s.Skill])),r=h((I=c.data)==null?void 0:I.data,s.Normal),b=h((N=c.data)==null?void 0:N.data,s.Pedagogy),x=h((k=c.data)==null?void 0:k.data,s.Skill),R=h((w=c.data)==null?void 0:w.data,s.Hidden),F=W.toObject(r,"id"),j=l(V.pedagogyTags()),A=l(V.skillTags());async function H(e,n){await o(p.updateContentPipelineVideo(a.clipId,{hasPedagogyTags:e.hasTagType})),await o(p.addContentPipelineVideoComment(a.clipId,"bypassPedagogyTags",e.bypassCategory,e.bypassReason)),n()}async function B(e,n){await o(p.updateContentPipelineVideo(a.clipId,{hasSkillTags:e.hasTagType})),await o(p.addContentPipelineVideoComment(a.clipId,"bypassSkillTags",e.bypassCategory,e.bypassReason)),n()}function C(e){var n;return(n=e.results)==null?void 0:n.filter(u=>!F[u.id])}function P(e,n){if(e=e.trim(),!!e.length){if(!d.isValidTagSearch(e)){i.error(`Tag ${e} is not valid`);return}if(!d.isValidTagLength(e)){i.error(`Tag must be less than ${D} characters`);return}if(n===s.Normal){if(d.getTagByName(r,e)){i.error(`Tag <strong>${e}</strong> already exists on this video.`);return}if(!d.canAddNormalTag(r)){i.error(`Maximum number of Keyword Tags (<strong>${E}</strong>) have been added.`);return}}o(g.createTag(a.clipId,e,n,()=>i.success(`<strong>${e}</strong> has been created and added.`),()=>i.error(`Failed to create '${e}'.`)))}}function T(e){if(e.tagType===s.Normal&&!d.canAddNormalTag(r)){i.error(`Maximum number of Keyword Tags (<strong>${E}</strong>) have been added.`);return}o(g.associateTag(a.clipId,e,()=>i.success(`<strong>${e.name}</strong> has been added.`),()=>i.error(`Failed to add '${e.name}'.`)))}function m(e){o(g.dissociateTag(a.clipId,e,()=>i.success(`<strong>${e.name}</strong> has been removed.`),()=>i.error(`Failed to remove <strong>${e.name}</strong>.`)))}function U(e){if(d.getTagById(b,e.id)){m(e);return}T(e)}function _(e){if(d.getTagById(x,e.id)){m(e);return}T(e)}function v(e,n){const u=e.trim();return d.isValidTagSearch(u)?Z.searchTags(u,n):null}const G=j.hasCompleted&&A.hasCompleted&&S.hasCompleted;return t.jsxs(t.Fragment,{children:[!!y.data&&t.jsx(q,{clipId:a.clipId,activeAction:X.Clips.EDIT_CLIP_TAGS,currentUser:y.data}),t.jsx(J,{object:S.data}),G?t.jsxs(t.Fragment,{children:[t.jsx($,{type:s.Pedagogy,onSubmit:H,allTags:j.data,tags:b,onToggleTag:U,heading:"Pedagogy tags",description:"Select tags to indicate how this clip should be used",contentPipelineVideo:f.data}),t.jsx($,{type:s.Skill,onSubmit:B,allTags:A.data,tags:x,onToggleTag:_,heading:"Skill tags",description:"Select tags to indicate why this clip is useful",contentPipelineVideo:f.data}),t.jsxs("div",{className:"row",children:[t.jsx("div",{className:"col-lg-6",children:t.jsx(L,{title:"Keyword Tags",placeholder:"Add a keyword tag",onRemove:m,tagList:r,onSuggestionDependencies:[r],onSuggestionSelected:T,getRemoteUrl:e=>v(e,s.Normal),formatRemoteSuggestions:e=>C(e),onSubmit:e=>P(e,s.Normal)})}),t.jsx("div",{className:"col-lg-6",children:t.jsx(L,{title:"Hidden Tags",placeholder:"Add a hidden tag",onRemove:m,tagList:R,onSuggestionDependencies:[R],onSuggestionSelected:T,getRemoteUrl:e=>v(e,s.Hidden),formatRemoteSuggestions:e=>C(e),onSubmit:e=>P(e,s.Hidden)})})]})]}):t.jsx("div",{className:"text-center p-5",children:t.jsx(Q,{as:"div",animation:"border",role:"status"})})]})}export{re as EditClipTagsView};
//# sourceMappingURL=d3ED3XtX.chunk.js.map
