import{bc as U,b2 as v,ax as j,V as C,az as E,aj as w,dr as F,aX as V,b3 as N,aJ as R,v as b,f as k,e as q,ao as i,aF as D,L as M,aq as Y,aP as _,n as h,o as B,p as H,W as z,E as O,r as W,i4 as G,i7 as J,A as g,cj as f}from"./app-k0jcl5PQ.js";import{u as K}from"./Cbx9Mhpo.chunk.js";import{S as X}from"./BejFPyFL.chunk.js";import{a as Z}from"./BxvNJmZk.chunk.js";import"./DQeiaRoX.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 S="playlists.addUploadToPlaylist",r=M.encloseNamespace(S),m=s=>h.getUserPlaylists(new G(J.AtoZ,s));function Ae(s){const c=U(),p=v(),[o,u]=j(C.UPLOAD_PLAYLISTS,{}),n=E(w.currentUser()),l=F(e=>m(e).key),{uploadingVideos:x}=K({categoryId:+s.categoryId}),a=x.find(e=>e.uploadId===s.id),{isLoaded:A}=V();N(m,e=>{p(m(e))});const y=(e,t)=>{const d=o[s.id]||[];u(s.id,[...d,e.id]),c.success({heading:f.Success,type:g.Success,message:r("success",{video:a.name,playlist:e.name,escapeText:!0})}),t&&s.closePopup()},I=e=>{const t=o[s.id]||[];u(s.id,t.filter(d=>d!==e.id)),c.success({heading:f.Success,type:g.Success,message:r("successRemove",{video:a.name,playlist:e.name,escapeText:!0})})},L=e=>{p(h.createPlaylist(n.data.id,{name:e},t=>{!t||!t.id||(B.logUserAction({id:t.id},{actionType:W.Create,entity:O.Playlist,workflowPhase:z.Complete,location:H.Popup}),y(t,!0))},()=>{c.error(r("createError",{playlist:e,escapeText:!0})),s.closePopup()}))},T=e=>{var t;if((t=o[s.id])!=null&&t.includes(e.id)){I(e);return}y(e)};R.useEffect(()=>{a!=null&&a.videoId&&(b.trigger({application:q.PLAYLISTS,action:k.Playlists.ADD_TO_PLAYLIST,args:[a.videoId]}),s.closePopup())},[a]);const P=!!l.items&&!l.nextCursor&&!!n.data&&A;return i.jsx(D,{title:r("heading"),closePopup:s.closePopup,showLoadingSpinner:!P||screen===null,children:P?i.jsxs(i.Fragment,{children:[l.items.length?i.jsx("div",{className:"mb-2",children:i.jsx(Y,{namespace:S,phrase:"selectPlaylist",options:{video:a==null?void 0:a.name}})}):i.jsx(Z,{headingClassName:"h4",imageSize:"small",className:"py-2",hideButton:!0,imgSrc:_.EmptyStates.Playlists.PLAYLISTS_PUBLIC}),i.jsx(X,{playlists:l.items,currentUserId:n.data.id,onSelectPlaylist:T,isVideoInPlaylist:e=>{var t;return(t=o[s.id])==null?void 0:t.includes(e.id)},createPlaylist:L})]}):i.jsx(i.Fragment,{})})}export{Ae as AddUploadToPlaylistView};
//# sourceMappingURL=DT1wjkYI.chunk.js.map
