define(["exports","./basetab.js","./../modules/cardbuilder/cardbuilder.js","./../modules/common/playback/playbackmanager.js","./../modules/focusmanager.js","./../modules/layoutmanager.js"],function(_exports,_basetab,_cardbuilder,_playbackmanager,_focusmanager,_layoutmanager){function ChaptersTab(view){_basetab.default.apply(this,arguments)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,Object.assign(ChaptersTab.prototype,_basetab.default.prototype);ChaptersTab.prototype.loadTemplate=function(){var view=this.view;return view.innerHTML='\n                    <div is="emby-scroller" data-mousewheel="false" data-focusscroll="start" data-focusscrolloffset="-padding-inline-start" class="padded-top-focusscale padded-bottom-focusscale">\n                        <div is="emby-itemscontainer" data-focusabletype="nearest" class="focusable focuscontainer-x scrollSlider itemsContainer videoosd-padded-left videoosd-padded-right" data-virtualscrolllayout="horizontal-grid"></div>\n                    </div>\n',this.itemsContainer=view.querySelector(".itemsContainer"),this.itemsContainer.fetchData=function(query){var chapters=this.currentOptions.currentDisplayChapters||[],totalItems=chapters.length;return query&&(chapters=chapters.slice(query.StartIndex||0),query.Limit)&&chapters.length>query.Limit&&(chapters.length=query.Limit),Promise.resolve({Items:chapters,TotalRecordCount:totalItems})}.bind(this),this.itemsContainer.getListOptions=function(items){return{renderer:_cardbuilder.default,options:{shape:"autooverflow",fields:["Name","ChapterTime"],multiSelect:!1,contextMenu:!1,playedButton:!1,ratingButton:!1,action:"custom",playAction:"custom",enableUserData:!1,draggable:!1,cardClass:"videoOsd-itemstab-card videoOsd-itemstab-card-twoline",defaultShape:"backdrop",allowBottomPadding:!1,background:"black",textLinks:!1,enableFocusScaling:!1},virtualScrollLayout:"horizontal-grid"}}.bind(this),this.itemsContainer.addEventListener("action-null",function(e){e=e.detail.item,_playbackmanager.default.seek(e.StartPositionTicks||0),this.closeTab()}.bind(this)),Promise.resolve()},ChaptersTab.prototype.scrollToCurrentItem=function(focus){this.paused||this.view.contains(document.activeElement)||(focus?_focusmanager.default.focus(this.itemsContainer):function(instance,focus){var currentIndex=instance.getCurrentIndex();console.log("scrolling to chapter index: "+currentIndex),instance.itemsContainer.scrollToIndex(currentIndex,{offsetLeft:"-padding-inline-start"},focus)}(this,focus))},ChaptersTab.prototype.onResume=function(options){var instance=this;return _basetab.default.prototype.onResume.apply(this,arguments).then(function(){var optionsWithoutRefresh=Object.assign(Object.assign({},options),{refresh:!1}),hasFocus=instance.itemsContainer.contains(document.activeElement);return instance.itemsContainer.resume(optionsWithoutRefresh).then(function(){options.refresh?instance.refreshItem():instance.scrollToCurrentItem(hasFocus)})})},ChaptersTab.prototype.refreshItem=function(){_basetab.default.prototype.refreshItem.apply(this,arguments);var instance=this,hasFocus=instance.itemsContainer.contains(document.activeElement);return instance.itemsContainer.refreshItems().then(function(){instance.scrollToCurrentItem(hasFocus)})},ChaptersTab.prototype.onTimeUpdate=function(positionTicks,runtimeTicks){_basetab.default.prototype.onTimeUpdate.apply(this,arguments),this.paused||_layoutmanager.default.tv&&this.scrollToCurrentItem()},ChaptersTab.prototype.getCurrentIndex=function(){for(var chapters=this.currentOptions.currentDisplayChapters||[],positionTicks=this.positionTicks||0,i=0,length=chapters.length;i<length;i++)if(positionTicks<chapters[i].StartPositionTicks)return Math.max(0,i-1);return positionTicks?Math.max(chapters.length-1,0):0},ChaptersTab.prototype.onPause=function(){_basetab.default.prototype.onPause.apply(this,arguments),this.itemsContainer.pause()},ChaptersTab.prototype.destroy=function(){_basetab.default.prototype.destroy.apply(this,arguments),this.itemsContainer=null};_exports.default=ChaptersTab});