define(["exports","./layoutmanager.js","./dom.js","./emby-elements/emby-button/emby-button.js","./emby-elements/emby-tabs/emby-tabs.js","./focusmanager.js"],function(_exports,_layoutmanager,_dom,_embyButton,_embyTabs,_focusmanager){var tabOwnerView,headerTabsContainer,tabsElem,headerTop,headerMiddle;function ensureElements(){headerTabsContainer=headerTabsContainer||document.querySelector(".headerMiddle")}function onViewTabsReady(){this.selectedIndex(this.readySelectedIndex),this.readySelectedIndex=null}function defaultGetTabContainersFn(){return[]}function focus(){var btn;return headerMiddle?(btn=headerMiddle.querySelector(".emby-tab-button-active"))?(_focusmanager.default.focus(btn),btn):_focusmanager.default.autoFocus(headerMiddle):null}function getTabsElement(){var _headerMiddle;return null==(_headerMiddle=headerMiddle)?void 0:_headerMiddle.querySelector(".tabs-viewmenubar")}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;_exports.default={setTabs:function(view,selectedIndex,getTabsFn,getTabContainersFn,onTabChange,setSelectedIndex){if(!view)return tabOwnerView&&(headerTabsContainer=headerTabsContainer||document.querySelector(".headerMiddle"),ensureElements(),headerTop&&headerTop.classList.remove("headerTop-withSectionTabs","headerTop-tv-withSectionTabs","headerTop-tv-withSectionTabs-hideTitle"),headerMiddle&&headerMiddle.classList.remove("headerMiddle-withSectionTabs"),document.documentElement.classList.remove("withHeaderTabs"),headerTabsContainer.innerHTML="",tabOwnerView=null),{tabsContainer:headerTabsContainer,replaced:!1};ensureElements();var index,tabsClass,tabsSliderClass,indexAttribute,tabsContainerElem=headerTabsContainer;return tabOwnerView!==view?(index=0,indexAttribute=null==selectedIndex?"":' data-index="'+selectedIndex+'"',tabsClass="tabs-viewmenubar tabs-viewmenubar-backgroundcontainer emby-tabs padded-left padded-right",tabsSliderClass="tabs-viewmenubar-slider emby-tabs-slider",_dom.default.allowBackdropFilter()&&(tabsClass+=" tabs-viewmenubar-backgroundcontainer-backdropfilter"),_layoutmanager.default.tv&&(tabsClass+=" tabs-viewmenubar-tv tabs-viewmenubar-backgroundcontainer-tv scrollFrameX",tabsSliderClass+=" tabs-viewmenubar-slider-tv scrollSliderX"),indexAttribute='<div is="emby-tabs"'+indexAttribute+' class="'+tabsClass+'"><div class="'+tabsSliderClass+'">'+getTabsFn().map(function(t){var tabClass="emby-button secondaryText emby-tab-button main-tab-button";return _layoutmanager.default.tv&&(tabClass+=" emby-button-tv main-tab-button-tv"),!1===t.enabled&&(tabClass+=" hide"),t.cssClass&&(tabClass+=" "+t.cssClass),tabClass=t.href?'<a href="'+t.href+'" is="emby-linkbutton" class="'+tabClass+'" data-index="'+index+'">'+t.name+"</a>":'<button type="button" is="emby-button" class="'+tabClass+'" data-index="'+index+'">'+t.name+"</button>",index++,tabClass}).join("")+"</div></div>",tabsContainerElem.innerHTML=indexAttribute,headerTop=headerTop||document.querySelector(".headerTop"),headerMiddle=headerMiddle||document.querySelector(".headerMiddle"),_layoutmanager.default.tv?headerTop.classList.add("headerTop-withSectionTabs","headerTop-tv-withSectionTabs","headerTop-tv-withSectionTabs-hideTitle"):headerTop.classList.add("headerTop-withSectionTabs"),headerMiddle.classList.add("headerMiddle-withSectionTabs"),document.documentElement.classList.add("withHeaderTabs"),tabOwnerView=view,tabsElem=tabsContainerElem.querySelector('[is="emby-tabs"]'),getTabContainersFn=getTabContainersFn||defaultGetTabContainersFn,tabsElem.addEventListener("beforetabchange",function(e){var tabContainers=getTabContainersFn(),previousPanel=(null!=e.detail.previousIndex&&(previousPanel=tabContainers[e.detail.previousIndex])&&previousPanel.classList.remove("is-active"),tabContainers[e.detail.selectedTabIndex]);previousPanel&&previousPanel.classList.add("is-active")}),onTabChange&&tabsElem.addEventListener("tabchange",onTabChange),!1!==setSelectedIndex&&(tabsElem.selectedIndex?tabsElem.selectedIndex(selectedIndex):(tabsElem.readySelectedIndex=selectedIndex,tabsElem.addEventListener("ready",onViewTabsReady))),{tabsContainer:tabsContainerElem,replaced:!0}):(tabsElem=tabsElem||tabsContainerElem.querySelector('[is="emby-tabs"]'),tabOwnerView=view,{tabsContainer:tabsContainerElem,replaced:!1})},getTabsElement:getTabsElement,selectedTabIndex:function(index){tabsElem=tabsElem||headerTabsContainer.querySelector('[is="emby-tabs"]'),null!=index?tabsElem.selectedIndex(index):tabsElem.triggerTabChange()},focus:focus,setTabVisible:function(index,visible){var tabsElem=getTabsElement();tabsElem&&(tabsElem=tabsElem.querySelector('.main-tab-button[data-index="'+index+'"]'))&&(visible?tabsElem.classList.remove("hide"):(index=document.activeElement===tabsElem,tabsElem.classList.add("hide"),index&&focus()))}}});