import{l as k,k as I,R as b,o as A,j as e,E as V,C as j,e9 as C,Y as v,h as P,i as T,Q as _,af as D,cx as B,cy as E,a9 as l}from"./app-BgLa5dit.js";import{D as f}from"./BE59vaMU.chunk.js";import{u as F}from"./kHNgJL0M.chunk.js";import"./KIVqng-q.chunk.js";const L="_item_1jfk8_1",R="_openInNewTab_1jfk8_1",w={item:L,openInNewTab:R};function G(n){var u,p,m,g,x;const i=F(n.dashboardId),r=k(),S=I(),[N,h]=b.useState(!1),[a,o]=b.useState([]),t=A(f.dashboardUnusedVideos(n.dashboardId));async function y(){try{h(!0),await S(f.addUnusedVideos(n.dashboardId,a)),r.success("Successfully added new videos to the dashboard."),n.closePopup()}catch{r.error("Something went wrong, please try again.")}finally{h(!1)}}return e.jsx(V,{size:"lg",title:"Add unused videos",showLoadingSpinner:!i.data,closePopup:n.closePopup,children:!!i.data&&e.jsxs("div",{className:"mb-2",children:[e.jsxs("div",{className:"d-flex justify-content-between",children:[e.jsxs("p",{children:["Select the videos you want to add to ",e.jsx("strong",{children:i.data.name}),". AI will allocate them to the appropriate widget."]}),!!((u=t.data)!=null&&u.length)&&e.jsx(j,{id:"add-all-videos",label:"Bulk select",className:"flex-shrink-0",checked:a.length===((p=t.data)==null?void 0:p.length),onChange:()=>{var s,d;a.length===((s=t.data)==null?void 0:s.length)?o([]):o(((d=t.data)==null?void 0:d.map(c=>c.id))||[])}})]}),e.jsx("div",{className:"mb-2",children:t.isFetching?e.jsx(C,{}):(m=t.data)!=null&&m.length?(g=t.data)==null?void 0:g.map(s=>e.jsxs("div",{className:"d-flex align-items-center justify-content-between",children:[e.jsxs("div",{className:`d-flex ${w.item}`,children:[e.jsx(j,{id:s.id,checked:a.includes(s.id),className:"mb-2",label:s.name,onChange:()=>{const d=a.includes(s.id);o(d?a.filter(c=>c!==s.id):[...a,s.id])}}),e.jsx(v,{openInNewTab:!0,className:w.openInNewTab,appLink:{application:T.VIDEOS,action:P.Videos.EDIT_VIDEO,args:[s.id]},children:e.jsx(_,{className:"svg-container cursor-pointer",svg:D})})]}),e.jsx(B,{type:E.Status,data:s.status})]},s.id)):e.jsx("p",{children:"No unused videos found for this dashboard."})}),e.jsxs(l,{children:[e.jsx(l.Cancel,{onClick:n.closePopup}),e.jsx(l.Submit,{text:"Add videos",variant:"dark",onClick:y,showSpinner:N,disabled:!((x=t.data)!=null&&x.length)||!a.length})]})]})})}export{G as AddUnusedVideosView};
//# sourceMappingURL=BmdMVHwT.chunk.js.map
