import{j as s,O as q,T as H,C as N,aX as x,ag as b,e9 as V,e8 as S,aJ as j,k as _,l as $,o as B,R as c,bu as L,E as Q,as as W,a9 as u,w as X}from"./app-BgLa5dit.js";import{S as Y}from"./nO4MXtNL.chunk.js";import{D as z}from"./DPl9_NPk.chunk.js";import{W as G,a as J}from"./C6Gt0vzN.chunk.js";import{S as y}from"./BSa28HTr.chunk.js";import"./HrByhRZi.chunk.js";import"./0GREfvNX.chunk.js";import"./EZim8aq-.chunk.js";const K="_addObjectSeriesSearchItem_1n5ct_1",U={addObjectSeriesSearchItem:K};function Z(e){function t(n){e.onToggleSelect(e.result),n.preventDefault()}const a=!e.isSelected&&e.disableSelectingMore;return s.jsxs(q,{className:"py-2 pe-3 ps-2 hover-bg-light-blue d-flex rounded-2",disabled:a,onClick:a?()=>{}:t,children:[s.jsx("div",{className:"d-inline-flex align-items-center flex-nowrap",style:{flex:1},children:s.jsx("div",{onClick:n=>n.stopPropagation(),children:s.jsx(H,{title:e.isSelected?void 0:e.disabledMessage,spanHack:!0,spanHackClassName:"",children:s.jsx(N,{className:"me-1 ms-2",checked:e.isSelected,onChange:a?()=>{}:()=>e.onToggleSelect(e.result),id:e.result.id,disabled:a})})})}),x.isType(e.result,b.Video)?s.jsx(G,{video:e.result}):x.isType(e.result,b.Series)?s.jsx(J,{series:e.result,className:U.addObjectSeriesSearchItem}):null]})}function ee(e){return e.isFetching?s.jsx(V,{}):e.results.length?s.jsx(s.Fragment,{children:e.results.map(t=>s.jsx(Z,{result:t,onToggleSelect:e.onToggleSelect,isSelected:e.selectedIds.includes(t.id),disableSelectingMore:e.disableSelectingMore??!1,disabledMessage:e.disabledMessage},t.id))}):s.jsx(z,{})}const C=100,v=1;function M(e){return t=>t.length<e}const te={videos:{texts:{title:"Add Videos",success:"Videos added successfully",error:"Failed to add videos, please try again later.",placeholder:"Search a video",disabledMessage:`You can only select ${C} videos at a time`},predicates:{canSelectMore:M(C)},requests:{search:({query:e,success:t,error:a})=>y.searchContent({query:e,indices:["video"],filters:{status:`${j.Published},${j.Draft}`},success:t,error:a}),add:S.addVideosToPartnerProfile}},series:{texts:{title:"Add Series",success:"Series added successfully",error:"Failed to add series, please try again later.",placeholder:"Search a series",disabledMessage:`You can only select ${v} series at a time`},predicates:{canSelectMore:M(v)},requests:{search:({query:e,success:t,error:a})=>y.searchContent({query:e,indices:["series"],filters:{},success:t,error:a}),add:(e,t)=>S.addSeriesToPartnerProfile(e,t[0])}}};function oe(e){const t=te[e.type],a=_(),n=$(),P=B(S.getContentPartner(e.contentPartnerId)),[I,T]=c.useState([]),[h,E]=c.useState(""),l=L(h,300),[A,i]=c.useState(!1),[r,g]=c.useState([]),[f,d]=c.useState(!1);function R(o){g(X.addOrRemoveImmutable(r,o.id))}async function O(){if(r.length){d(!0);try{await a(t.requests.add(e.contentPartnerId,r)),d(!1),n.success(t.texts.success),e.closePopup()}catch{d(!1),n.error(t.texts.error)}}}async function k(o){await a(t.requests.search({query:o,error:()=>i(!1),success:w=>{T(w.results),i(!1)}}))}function p(){g([])}c.useEffect(()=>{if(l){i(!0),k(l);return}i(!1)},[l]);const D=!P.data,m=!t.predicates.canSelectMore(r),F=m?t.texts.disabledMessage:void 0;return s.jsxs(Q,{title:t.texts.title,closePopup:e.closePopup,showLoadingSpinner:D,children:[s.jsx(Y,{name:`content-partner-add-${e.type}-search`,placeholder:t.texts.placeholder,setQuery:E,query:h,autoFocus:!0}),s.jsx("div",{className:"my-2",children:s.jsx(W.Scrollbars,{autoHeight:!0,autoHeightMin:300,autoHeightMax:300,children:s.jsx(ee,{isFetching:A,results:I,onToggleSelect:R,selectedIds:r,disableSelectingMore:m,disabledMessage:F})})}),s.jsxs(u,{className:"justify-content-between",children:[s.jsx("div",{children:!!r.length&&s.jsx(u.Cancel,{onClick:p,text:`Clear ${r.length} ${r.length===1?"selection":"selections"}`})}),s.jsx(u.Submit,{variant:"dark",text:"Save",onClick:O,disabled:f,showSpinner:f})]})]})}export{oe as ContentPartnerAddObjectsView};
//# sourceMappingURL=BbMl6OgA.chunk.js.map
