import{t}from'./chunk-CrWoVCei.js';import{j}from'./chunk-CMCtTkWA.js';import{g,dW as W,dl as Ie,dG as ze,aN as $,by as X,fP as EHe,aY as S,bL as J,bM as wo}from'./main-DEZ5cZzu.js';var v=J(wo());var n=(0,v.default)("peertube:search:FindInBulkService"),C=(()=>{class a{searchService=g(j);advancedSearchForBulk;getVideoInBulk;getChannelInBulk;getPlaylistInBulk;constructor(){this.getVideoInBulk=this.buildBulkObservableObject(this.getVideosInBulk.bind(this)),this.getChannelInBulk=this.buildBulkObservableObject(this.getChannelsInBulk.bind(this)),this.getPlaylistInBulk=this.buildBulkObservableObject(this.getPlaylistsInBulk.bind(this)),this.advancedSearchForBulk=new t({searchTarget:"local"});}getVideo(e){return n("Schedule video fetch for uuid %s.",e),this.getData({observableObject:this.getVideoInBulk,finder:t=>t.uuid===e||t.shortUUID===e,param:e});}getChannel(e){return n("Schedule channel fetch for handle %s.",e),this.getData({observableObject:this.getChannelInBulk,finder:t=>t.nameWithHost===e||t.nameWithHostForced===e,param:e});}getPlaylist(e){return n("Schedule playlist fetch for uuid %s.",e),this.getData({observableObject:this.getPlaylistInBulk,finder:t=>t.uuid===e||t.shortUUID===e,param:e});}getData(e){let{observableObject:t,param:s,finder:k}=e;return new W(i=>{t.result.pipe(Ie(r=>r.params.includes(s)),ze(),$(r=>r.response.data),$(r=>r.find(k))).subscribe({next:r=>{if(!r){i.error(new Error("No s'ha trobat l'element "+s+""));return;}i.next(r),i.complete();},error:r=>i.error(r)}),t.notifier.next(s);});}getVideosInBulk(e){return n("Fetching videos %s.",e.join(", ")),this.searchService.searchVideos({uuids:e,componentPagination:{itemsPerPage:e.length,currentPage:1},skipCount:true,advancedSearch:this.advancedSearchForBulk});}getChannelsInBulk(e){return n("Fetching channels %s.",e.join(", ")),this.searchService.searchVideoChannels({handles:e,componentPagination:{itemsPerPage:e.length,currentPage:1},advancedSearch:this.advancedSearchForBulk});}getPlaylistsInBulk(e){return n("Fetching playlists %s.",e.join(", ")),this.searchService.searchVideoPlaylists({uuids:e,componentPagination:{itemsPerPage:e.length,currentPage:1},advancedSearch:this.advancedSearchForBulk});}buildBulkObservableObject(e){let t=new X();return{notifier:t,result:EHe({time:100,bulkGet:e,notifierObservable:t.asObservable()})};}static ɵfac=function(t){return new(t||a)();};static ɵprov=S({token:a,factory:a.ɵfac});}return a;})();/**i18n:c8855ca17fb20171aa9dd43d012e42547cb1f0cfd9c21d4dc05679bbbdf5ccb8*/export{C};//# sourceMappingURL=chunk-CDhLx_Ru.js.map