import{k as q,l as Q,o as c,s as n,p as Y,ct as s,w as z,aV as F,j as t,h as _,F as v,ar as J,aT as Z,aj as d,aR as $,dw as ee,dx as B}from"./app-BgLa5dit.js";import{O as ae}from"./B-fq6xxv.chunk.js";import{S as te}from"./BSa28HTr.chunk.js";import{S as se}from"./CJf3ETiT.chunk.js";import{E as ie}from"./RTbqjc8Y.chunk.js";import{T as U,S as G}from"./CEzAQXMv.chunk.js";import"./EZim8aq-.chunk.js";import"./BfMtaC_g.chunk.js";import"./w68yffRy.chunk.js";const f="videos.editVideoTags",l=v.encloseNamespace(f);function y(a,o){return Z.useMemo(()=>d.getTagsByType(a,o),[a==null?void 0:a.length])}function ue(a){var C,w,L,H;const o=q(),x=Q(),V=c($.currentUser()),j=c(n.video(a.videoId)),p=c(Y.getAssemblyLineVideo(a.videoId)),T=c(n.videoTagsByType(a.videoId,[s.Normal,s.Pedagogy,s.Hidden,s.Skill])),r=y((C=T.data)==null?void 0:C.data,s.Normal),R=y((w=T.data)==null?void 0:w.data,s.Pedagogy),A=y((L=T.data)==null?void 0:L.data,s.Skill),I=y((H=T.data)==null?void 0:H.data,s.Hidden),O=z.toObject(r,"id"),P=c(F.pedagogyTags()),b=c(F.skillTags());function N(e){var i;return(i=e.results)==null?void 0:i.filter(h=>!O[h.id])}function g(e,i){x.error(v.getPhrase(f,e,i))}function S(e,i){x.success(v.getPhrase(f,e,i))}async function D(e,i){await o(n.updateContentPipelineVideo(a.videoId,{hasPedagogyTags:e.hasTagType})),await o(n.addContentPipelineVideoComment(a.videoId,"bypassPedagogyTags",e.bypassCategory,e.bypassReason)),i()}async function K(e,i){await o(n.updateContentPipelineVideo(a.videoId,{hasSkillTags:e.hasTagType})),await o(n.addContentPipelineVideoComment(a.videoId,"bypassSkillTags",e.bypassCategory,e.bypassReason)),i()}function E(e,i){if(e=e.trim(),!!e.length){if(!d.isValidTagSearch(e)){g("notValid",{query:e});return}if(!d.isValidTagLength(e)){g("invalidTagLength",{length:ee});return}if(i===s.Normal){if(d.getTagByName(r,e)){g("alreadyExists",{query:e});return}if(!d.canAddNormalTag(r)){g("maxKeywordTags",{maxKeywordTags:B});return}}o(n.createTag(a.videoId,e,i,()=>S("created",{query:e}),()=>g("failedCreate",{query:e})))}}function m(e){if(e.tagType===s.Normal&&!d.canAddNormalTag(r)){g("maxKeywordTags",{maxKeywordTags:B});return}o(n.associateTag(a.videoId,e,()=>S("added",{query:e.name}),()=>g("failedAdd",{query:e.name})))}function u(e){o(n.dissociateTag(a.videoId,e,()=>S("removed",{query:e.name}),()=>g("failedRemove",{query:e.name})))}function M(e){if(d.getTagById(R,e.id)){u(e);return}m(e)}function W(e){if(d.getTagById(A,e.id)){u(e);return}m(e)}function k(e,i){const h=e.trim();return d.isValidTagSearch(h)?te.searchTags(h,i):null}const X=P.hasCompleted&&b.hasCompleted&&j.hasCompleted&&p.hasCompleted;return t.jsxs(t.Fragment,{children:[!!V.data&&t.jsx(t.Fragment,{children:a.context==="streamable"?t.jsx(se,{videoId:a.videoId,activeAction:_.StreamableLearning.EDIT_VIDEO_TAGS}):t.jsx(ie,{videoId:a.videoId,activeAction:_.Videos.EDIT_VIDEO_TAGS,currentUser:V.data})}),t.jsx(ae,{object:j.data}),X?t.jsxs(t.Fragment,{children:[t.jsx(U,{type:s.Pedagogy,onSubmit:D,allTags:P.data,tags:R,onToggleTag:M,heading:l("pedagogyTags"),description:l("pedagogyDescription"),contentPipelineVideo:p.data}),t.jsx(U,{type:s.Skill,onSubmit:K,allTags:b.data,tags:A,onToggleTag:W,heading:l("skillTags"),description:l("skillDescription"),contentPipelineVideo:p.data}),t.jsxs("div",{className:"row",children:[t.jsx("div",{className:"col-lg-6",children:t.jsx(G,{title:l("keywordTags"),placeholder:l("addTagPlaceholder"),onRemove:u,tagList:r,onSuggestionDependencies:[r],onSuggestionSelected:m,getRemoteUrl:e=>k(e,s.Normal),formatRemoteSuggestions:e=>N(e),onSubmit:e=>E(e,s.Normal)})}),t.jsx("div",{className:"col-lg-6",children:t.jsx(G,{title:l("hiddenTags"),placeholder:l("addHiddenTagPlaceholder"),onRemove:u,tagList:I,onSuggestionDependencies:[I],onSuggestionSelected:m,getRemoteUrl:e=>k(e,s.Hidden),formatRemoteSuggestions:e=>N(e),onSubmit:e=>E(e,s.Hidden)})})]})]}):t.jsx("div",{className:"text-center p-5",children:t.jsx(J,{as:"div",animation:"border",role:"status"})})]})}export{ue as EditVideoTagsView};
//# sourceMappingURL=CM2cx2e0.chunk.js.map
