import{R as b,j as t,ej as N,Y as S,h as m,i as d,Q as _,av as q,bE as O,dk as k,k as D,l as A,o as R,aC as y,bg as M,aJ as F,e9 as U,ek as B}from"./app-BgLa5dit.js";import{D as z}from"./C4BcftDO.chunk.js";import{T as x}from"./lZO4aq5x.chunk.js";import{u as $}from"./8Im-OACs.chunk.js";import{C as p}from"./c3I67AiW.chunk.js";import{H}from"./wvigAl7i.chunk.js";import{C as P}from"./C2cKa2R1.chunk.js";import{C as Y,a as G}from"./8iu0vnCW.chunk.js";import{C as K}from"./q-IBKcuF.chunk.js";import{s as W}from"./BwqtY1B8.chunk.js";import"./C8_78Eqq.chunk.js";import"./g56uS58q.chunk.js";import"./3nM7jLnE.chunk.js";import"./CPXlV0fg.chunk.js";import"./ChrB5FYK.chunk.js";import"./DR2FaZH9.chunk.js";import"./KUnagq9Z.chunk.js";import"./DULWIWQR.chunk.js";import"./CCcwLDvu.chunk.js";import"./DDfKZ_ng.chunk.js";import"./DUpYPoLs.chunk.js";import"./EZim8aq-.chunk.js";import"./BD9MrUJP.chunk.js";import"./s6cGcwlA.chunk.js";import"./Zwjmkasg.chunk.js";import"./4qGb1BIY.chunk.js";import"./DnXDEnAR.chunk.js";import"./DpUpv6rY.chunk.js";import"./CG7zbly5.chunk.js";import"./m4aqaK_l.chunk.js";import"./MEkA24R1.chunk.js";import"./C53kfXmd.chunk.js";const J="_endCell_xtg38_13",Q={endCell:J},C=N(),h={customerName:()=>C.accessor(e=>e,{id:"customerName",header:"Name",cell:e=>t.jsx(S,{className:"text-info",appLink:{application:d.CRM_STUDIO,action:m.CrmStudio.CUSTOMER_OVERVIEW,args:[e.getValue().customerId]},children:e.getValue().customerName}),size:200}),cvcId:()=>C.accessor("crmId",{id:"crmId",header:"CVC ID",cell:e=>t.jsx(H,{value:e.getValue(),applink:null}),size:80}),libraryRequestEnabled:e=>C.accessor(r=>r,{id:"libraryRequestEnabled",header:"Enable library requests",cell:r=>t.jsx(O,{on:r.getValue().libraryRequestEnabled,onClick:()=>e(r.getValue().customerId,!r.getValue().libraryRequestEnabled),disabled:!e}),size:240}),remove:e=>C.accessor(r=>r,{id:"remove",header:" ",cell:r=>t.jsx("div",{className:Q.endCell,children:t.jsx(S,{appLink:{application:d.CRM_STUDIO,action:m.CrmStudio.REMOVE_LIBRARY_SUBSCRIBER,args:[r.getValue().customerId,e]},children:t.jsx(_,{svg:q})})}),size:24})};function X(e){const[r,i]=b.useState(e.data);b.useEffect(()=>{e.isFetching||i(e.data)},[e.isFetching]);const c=b.useCallback(async(n,l)=>{i(u=>u.map(a=>a.customerId===n?{...a,libraryRequestEnabled:l}:a));try{await e.onToggleLibraryRequestEnabled(n,l)}catch{i(a=>a.map(o=>o.customerId===n?{...o,libraryRequestEnabled:!l}:o))}},[]),g=b.useMemo(()=>[h.customerName(),h.cvcId(),h.libraryRequestEnabled(c),h.remove(e.libraryId)],[c,e.libraryId]);return!r||!r.length?t.jsx(t.Fragment,{}):t.jsx(x,{data:r,columns:g,theme:p})}function Z(e,r){var i;return e?[{title:r==="shared"?"Shared library name":"Customer library name",value:e.name||"-"},{title:"Status",value:e.status?M[F[e.status]]:"-"},{title:"Number of videos",value:e.videos.pagination.totalItems},{title:"Library owner",value:(i=e.owner)!=null&&i.name?t.jsx(S,{className:"text-info",appLink:{application:d.CRM_STUDIO,action:m.CrmStudio.CUSTOMER_OVERVIEW,args:[e.owner.id]},children:e.owner.name}):"-"}]:[]}const ee={...p,row:`${p.row} ${W.compactRow}`,cell:`${p.cell} pt-1 pb-1`,header:"d-none"};function Oe(e){const r=k(),i=D(),c=A(),g=R(K.customer(e.id)),n=R(y.getLibrary(e.libId));function l(s){return y.getLibrarySubscribers(e.libId,s)}function u(s){return r(l(s))}const{items:a,isFetching:o,hasMore:I,nextCursor:L}=$(l,u),v=g.hasCompleted&&n.hasCompleted,E=Z(n.data,e.type),j=[{header:"",accessorKey:"title",cell:s=>t.jsx("div",{className:"font-label",children:s.getValue()}),size:200},{header:"",accessorKey:"value",cell:s=>t.jsx("div",{children:s.getValue()}),size:600}],T={application:d.CRM_STUDIO,action:m.CrmStudio.ADD_LIBRARY_SUBSCRIBER,args:[e.libId]};async function V(s,f){try{await i(y.updateSubscriberPermissions(e.libId,s,f)),c.success(`Successfully ${f?"enabled":"disabled"} library requests for subscriber.`)}catch{c.error("Failed to update subscriber permissions, please try again")}}function w(){return o&&!(a!=null&&a.length)?t.jsx(U,{}):a!=null&&a.length?t.jsxs(t.Fragment,{children:[t.jsx(X,{data:a,isFetching:o,libraryId:e.libId,onToggleLibraryRequestEnabled:V}),I&&!o&&t.jsx(B,{isFetching:o,fetchNext:u,nextCursor:L,fetchOnScroll:!0})]}):t.jsx("p",{className:"px-3 pt-3",children:"Library has no subscribers at the moment."})}return t.jsx(Y,{view:G.Customers,children:t.jsxs(P,{title:"Content",currentTabId:"content",id:e.id,loading:!v,extraBreadcrumbsItems:[{name:"Content",appLink:{application:d.CRM_STUDIO,action:m.CrmStudio.CUSTOMER_CONTENT,args:[e.id]}},{name:e.type==="shared"?"Shared Library":"Customer Library",active:!0}],children:[n.data&&t.jsx(x,{data:E,columns:j,theme:ee}),t.jsx("div",{className:"mt-3",children:t.jsx(z,{heading:"Library subscribers",disableCollapse:!0,buttonText:"Add subscriber",buttonAppLink:T,children:w()})})]})})}export{Oe as CustomerLibraryView};
//# sourceMappingURL=BDNyIeS3.chunk.js.map
