import{c4 as J,bc as O,az as u,aj as X,n as c,dr as C,b4 as Z,aX as _,b3 as k,ao as o,aF as K,L as M,aq as Q,aP as $,c5 as E,m as y,o as P,p as g,W as T,E as h,r as x,i4 as ee,i7 as te,T as U,f as j,e as N,A as R,cj as V,q}from"./app-k0jcl5PQ.js";import{R as se}from"./BigZ58nN.chunk.js";import{S as ae}from"./BejFPyFL.chunk.js";import{a as ie}from"./BxvNJmZk.chunk.js";import"./D1M9dqnr.chunk.js";import"./CnSDR2E3.chunk.js";import"./CGIhFPIn.chunk.js";import"./DLmnDxSd.chunk.js";import"./CW7x8M-z.chunk.js";import"./DzRq1F5-.chunk.js";import"./DV1GpLCe.chunk.js";import"./Di9d6zcy.chunk.js";import"./CKctgafI.chunk.js";import"./C3DvQ1wU.chunk.js";import"./CT_eJKNn.chunk.js";import"./BhYYYlpK.chunk.js";import"./FGhEvk_q.chunk.js";import"./WCBjpMHJ.chunk.js";import"./DoFMWlew.chunk.js";import"./CMnqIsoM.chunk.js";import"./Heb2_zCZ.chunk.js";const w="playlists.addToPlaylist",r=M.encloseNamespace(w),S=t=>c.getUserPlaylists(new ee(te.AtoZ,t)),f=(t,l)=>d=>c.getVideoPlaylists(t,l,d);function Ce(t){var I;const l=J(),d=O(),a=u(X.currentUser()),s=u(c.getVideoCandidate(t.videoId)),n=C(e=>S(e).key),p=C(e=>!!t.videoId&&!!a.data&&f(t.videoId,a.data.id)(e).key),F=u(((I=a.data)==null?void 0:I.isAuthenticated)&&Z.yearGroups(a.data.customerId)),{isLoaded:Y}=_(),A=!!p.items&&p.items.map(e=>e.id),b=e=>{E(l)(S(e))},D=e=>{E(l)(f(t.videoId,a.data.id)(e))};k(S,b),k(!!a.data&&f(t.videoId,a.data.id),!!a.data&&D);const L=(e,i)=>{const m=()=>{d.success({heading:V.Success,type:R.Success,message:r(i?"successNew":"success",{video:s.data.name,playlist:e.name,escapeText:!0}),appLink:{application:N.PLAYLISTS,action:j.Playlists.PLAYLIST,args:[null,e.id,U.slugify(e.name)]},appLinkText:r("goToPlaylist",{playlist:e.name,escapeText:!0}),appLinkClassName:"info-link"}),P.logUserAction({id:s.data.id,name:s.data.name,playlistId:e.id,playlistName:e.name},{actionType:x.Associate,entity:h.Video,descriptor:q.Playlist,workflowPhase:T.Complete,location:g.Popup}),se.addRecentlyAddedTo(a.data.id,{id:e.id}),i&&t.closePopup()},G=W=>{W.responseJSON.type==="playlist-limit-exceeded"?d.error(r("playlistLimitExceeded")):d.error(r("addError",{video:s.data.name,playlist:e.name,escapeText:!0}))};y(l,c.addToPlaylist(e.id,[s.data],m,G))},H=e=>{const i=()=>{d.success({heading:V.Success,type:R.Success,message:r("successRemove",{video:s.data.name,playlist:e.name,escapeText:!0}),appLink:{application:N.PLAYLISTS,action:j.Playlists.PLAYLIST,args:[null,e.id,U.slugify(e.name)]},appLinkText:r("goToPlaylist",{playlist:e.name,escapeText:!0}),appLinkClassName:"info-link"}),P.logUserAction({id:s.data.id,playlistId:e.id},{actionType:x.Dissociate,entity:h.Video,descriptor:q.Playlist,workflowPhase:T.Complete,location:g.Popup})},m=()=>{d.error(r("removeError",{video:s.data.name,playlist:e.name,escapeText:!0})),t.closePopup()};y(l,c.removePlaylistVideo(e.id,s.data.id,s.data.typeId,i,m))},B=e=>{y(l,c.createPlaylist(a.data.id,{name:e},i=>{!i||!i.id||(P.logUserAction({id:i.id},{actionType:x.Create,entity:h.Playlist,workflowPhase:T.Complete,location:g.Popup}),L(i,!0))},()=>{d.error(r("createError",{video:s.data.name,playlist:e,escapeText:!0})),t.closePopup()}))},z=e=>{if(A.includes(e.id)){H(e);return}L(e)},v=!!s.data&&!!n.items&&!n.nextCursor&&!!a.data&&!!p.items&&!p.nextCursor&&F.hasCompleted&&Y;return o.jsx(K,{title:r("heading"),closePopup:t.closePopup,showLoadingSpinner:!v||screen===null,children:v?o.jsxs(o.Fragment,{children:[n.items.length?o.jsx("div",{className:"mb-2",children:o.jsx(Q,{namespace:w,phrase:"selectPlaylist",options:{video:s.data.name}})}):o.jsx(ie,{headingClassName:"h4",imageSize:"small",className:"py-2",hideButton:!0,imgSrc:$.EmptyStates.Playlists.PLAYLISTS_PUBLIC}),o.jsx(ae,{playlists:n.items,currentUserId:a.data.id,onSelectPlaylist:z,isVideoInPlaylist:e=>A.includes(e.id),createPlaylist:B})]}):o.jsx(o.Fragment,{})})}export{Ce as AddToPlaylistView};
//# sourceMappingURL=Djz1USzc.chunk.js.map
