"use strict";(self.webpackChunkapp=self.webpackChunkapp||[]).push([[64254],{64254:(e,r,t)=>{t.r(r),t.d(r,{CoreSearchHistory:()=>u,CoreSearchHistoryProvider:()=>d});var s=t(10467),a=t(52749),i=t(37762),o=t(79555),c=t(49833),n=t(89312),h=t(71689),l=t(54438);let d=(()=>{var e;class CoreSearchHistoryProvider{constructor(){this.searchHistoryTables=(0,c.$)((e=>(0,n.A)((()=>a.CoreSites.getSiteTable(i.lG,{siteId:e,primaryKeyColumns:[...i.Ph],rowIdColumn:null,config:{cachingStrategy:h.T.None},onDestroy:()=>delete this.searchHistoryTables[e]})))))}getSearchHistory(e,r){var t=this;return(0,s.A)((function*(){null!=r?r:r=a.CoreSites.getCurrentSiteId();return(yield t.searchHistoryTables[r].getMany({searcharea:e})).sort(((e,r)=>(r.lastused||0)-(e.lastused||0)))}))()}controlSearchLimit(e,r){var t=this;return(0,s.A)((function*(){const s=yield t.getSearchHistory(e);if(s.length>CoreSearchHistoryProvider.HISTORY_LIMIT){const e=s.pop();if(!e)return;yield t.searchHistoryTables[r].delete({searcharea:e.searcharea,searchedtext:e.searchedtext})}}))()}updateExistingItem(e,r,t){var a=this;return(0,s.A)((function*(){const s={searcharea:e,searchedtext:r};try{const e=yield a.searchHistoryTables[t].getOne(s);return e.lastused=Date.now(),e.times++,yield a.searchHistoryTables[t].update(e,s),!0}catch{return!1}}))()}insertOrUpdateSearchText(e,r,t){var i=this;return(0,s.A)((function*(){null!=t?t:t=a.CoreSites.getCurrentSiteId();(yield i.updateExistingItem(e,r,t))||(yield i.searchHistoryTables[t].insert({searcharea:e,searchedtext:r,lastused:Date.now(),times:1}),yield i.controlSearchLimit(e,t))}))()}}return(e=CoreSearchHistoryProvider).HISTORY_LIMIT=10,e.ɵfac=function CoreSearchHistoryProvider_Factory(r){return new(r||e)},e.ɵprov=l.jDH({token:e,factory:e.ɵfac,providedIn:"root"}),CoreSearchHistoryProvider})();const u=(0,o.Qd)(d)}}]);