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 fetchItems(query){var item=this.currentOptions.displayItem,chapters=item.Chapters||[],videoStream=(((item.MediaSources||[])[0]||{}).MediaStreams||[]).filter(function(i){return"Video"===i.Type})[0]||{},aspect=null;videoStream.Width&&videoStream.Height&&(aspect=videoStream.Width/videoStream.Height);for(var i=0,length=chapters.length;i<length;i++){var chapter=chapters[i];chapter.Id=item.Id,chapter.Type=item.Type,chapter.ServerId=item.ServerId,chapter.MediaType=item.MediaType,chapter.PrimaryImageAspectRatio=aspect,null==chapter.ChapterIndex&&(chapter.ChapterIndex=i)}videoStream=(chapters=function(chapters){for(var list=[],i=0,length=chapters.length;i<length;i++){var chapter=chapters[i];chapter.MarkerType&&"Chapter"!==chapter.MarkerType||list.push(chapter)}return list}(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:videoStream})}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=fetchItems.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,{offset:"-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 hasFocus=instance.itemsContainer.contains(document.activeElement);return instance.itemsContainer.resume(options).then(function(){instance.scrollToCurrentItem(hasFocus)})})},ChaptersTab.prototype.onItemUpdated=function(options){var instance,hasFocus;if(_basetab.default.prototype.onItemUpdated.apply(this,arguments),!this.paused)return hasFocus=(instance=this).itemsContainer.contains(document.activeElement),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.displayItem.Chapters||[],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});