'use strict';class FilterPanel{constructor(e){this.WRAPPER_ELEMENTS={tabList:e.tabList,tabPanel:e.tabPanel};this.SELECTORS={tabsWrapper:".tabs-wrapper",activeTab:".tab.active",activePillItem:".tab-panel.active .pill-bar__item.active",cardCarouselContainer:".appsource-grid-container",tabRole:"[role\x3dtab]"};this.MAPS={wrapperElements:{tabList:e.tabList,tabPanel:e.tabPanel},tabInstances:[],filterTabData:window.appsource.filterTabData};this.STRINGS={};this.CONFIG={filterTab_urlKey:"filterTab",filter_urlKey:"", selectedTab:"categories",selectedTabDefault:"categories",selectedFilter:"ai-machine-learning",selectedFilterDefault:"ai-machine-learning",requiredURLParams:["filterTab","categories","industries","product"],isPageLoad:!0,isTabClick:!1,popstate:!1};this.ELEMENTS={};this._updateCards=()=>{};this._updateURL=()=>{const a=new URL(window.location.href),b=this._createQueryParams();this.CONFIG.requiredURLParams.forEach(c=>{a.searchParams.delete(c)});a.searchParams.set(this.CONFIG.filterTab_urlKey,b[this.CONFIG.filterTab_urlKey]); b[this.CONFIG.filter_urlKey]&&a.searchParams.set(this.CONFIG.filter_urlKey,b[this.CONFIG.filter_urlKey]);window.location.href!=a.href&&(this.popstate?(this.popstate=!1,window.history.replaceState({tab:b[this.CONFIG.filterTab_urlKey],filter:b[this.CONFIG.filter_urlKey]},null,a)):window.history.pushState({tab:b[this.CONFIG.filterTab_urlKey],filter:b[this.CONFIG.filter_urlKey]},null,a));this._updateCarouselCards()};this._updateCarouselCards=a=>{const b=this.getActiveTabAndPill().activePillPanel.querySelector(this.SELECTORS.cardCarouselContainer); CardGridCarouselInstances.find(c=>c.compId==b.dataset.compid).instance._beginCardRender(b,a)};this._pushTabInstances=a=>{a.tabList.querySelectorAll(this.SELECTORS.tabRole).forEach(b=>{this.MAPS.tabInstances.push(new mwf.Tab({el:b,addUrlToHistory:!1}))});a.tabPanel.querySelectorAll(this.SELECTORS.tabRole).forEach(b=>{this.MAPS.tabInstances.push(new mwf.Tab({el:b,addUrlToHistory:!1}))})};this._readURLParams=()=>{const a=new URLSearchParams(window.location.search),b={};this.CONFIG.requiredURLParams.forEach(c=> {b[c]=(a.get(c)||"").trim()});return b};this._createQueryParams=()=>{this.CONFIG.filter_urlKey=this.MAPS.filterTabData.find(b=>b.urlKey&&b.tabKey==this.CONFIG.selectedTab).urlKey;let a={};a[this.CONFIG.filterTab_urlKey]=this.CONFIG.selectedTab;a[this.CONFIG.filter_urlKey]=this.CONFIG.selectedFilter;return a};this._setDefaultTabAndFilter=()=>{const a=this._readURLParams();this.CONFIG.selectedTab=a.filterTab&&0!=a.filterTab.length&&""!=a.filterTab?a.filterTab:this.CONFIG.selectedTabDefault;switch(this.CONFIG.selectedTab.toLowerCase()){case "categories":this.CONFIG.selectedFilter= a.categories?a.categories:this.CONFIG.selectedFilterDefault;break;case "industries":this.CONFIG.selectedFilter=a.industries?a.industries:this.CONFIG.selectedFilterDefault;break;case "products":this.CONFIG.selectedFilter=a.product?a.product:this.CONFIG.selectedFilterDefault}};this._checkTabAndFilterEquality=()=>{var a=this._readURLParams();const b=a.filterTab;if(!b)return!1;const c=this.MAPS.filterTabData.find(d=>d.urlKey&&d.tabKey==b).urlKey;a=a[c];return b==this.CONFIG.selectedTab&&a==this.CONFIG.selectedFilter}; this.getActiveTabAndPill=()=>{const a=this.ELEMENTS.tabsWrapper.querySelector(this.SELECTORS.activeTab),b=this.ELEMENTS.tabsWrapper.querySelector(this.SELECTORS.activePillItem),c=b.attributes.href.value,d=this.ELEMENTS.tabsWrapper.querySelector(c);return{activeTab:a,activePill:b,activePillPanelId:c,activePillPanel:d}};this._showTabs=()=>{const a=this._readURLParams(),b=a.filterTab,c=a[b];this.MAPS.tabInstances.find(d=>d.el.dataset.tabkey==b).show();this.MAPS.tabInstances.find(d=>d.el.dataset.filterkey== c).show()};this._initializeTabs=a=>{this._pushTabInstances(a);this.MAPS.tabInstances.forEach(b=>{b.el.addEventListener("onShown",c=>{this.CONFIG.isTabClick=!0;const {activeTab:d,activePill:f}=this.getActiveTabAndPill();this.CONFIG.selectedTab=d.dataset.tabkey;this.CONFIG.selectedFilter=f.dataset.filterkey;this._checkTabAndFilterEquality()?this.CONFIG.isPopstate&&(this.CONFIG.isPopstate=!1,this._updateURL()):this._updateURL()})})};this._setup=a=>{this.ELEMENTS.tabsWrapper=document.querySelector(this.SELECTORS.tabsWrapper); this.CONFIG.isPageLoad=!0;this._setDefaultTabAndFilter();this._initializeTabs(a);a={};a[this.CONFIG.filterTab_urlKey]=this.CONFIG.selectedTab;a[this.CONFIG.selectedTabDefault]=this.CONFIG.selectedFilter;this._updateCarouselCards(a);window.addEventListener("popstate",()=>{this.CONFIG.isPopstate=!0;this._setDefaultTabAndFilter();this._showTabs()})};this._init=a=>{this._setup(a)};this._init(this.MAPS.wrapperElements)}}const filterPanelInstances=[];window.appsource||(window.appsource={}); window.appsource.filterTabData||(window.appsource.filterTabData=[{tabKey:"categories",filterTabLabel:"Categories",urlKey:"categories"},{tabKey:"industries",filterTabLabel:"Industries",urlKey:"industries"},{tabKey:"products",filterTabLabel:"Products",urlKey:"product"}]);