define(["datetime","imageLoader","connectionManager","layoutManager","browser","cardBuilder"],function(datetime,imageLoader,connectionManager,layoutManager,browser,cardBuilder){"use strict";function setChapterProperties(item,chapter,index,options,apiClient){chapter.ImageUrl=function(item,chapter,index,maxWidth,apiClient){if(chapter.ImageTag)return apiClient.getScaledImageUrl(item.Id,{maxWidth:maxWidth,tag:chapter.ImageTag,type:"Chapter",index:index});return null}(item,chapter,index,options.width||400,apiClient),chapter.Id=item.Id,chapter.Type=item.Type,chapter.ServerId=item.ServerId,chapter.MediaType=item.MediaType}return{buildChapterCards:function(item,chapters,options){if(options.parentContainer){if(!document.body.contains(options.parentContainer))return;if(!chapters.length)return void options.parentContainer.classList.add("hide");options.parentContainer.classList.remove("hide")}var apiClient=connectionManager.getApiClient(item),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++)chapters[i].PrimaryImageAspectRatio=aspect,setChapterProperties(item,chapters[i],i,options,apiClient);options.itemsContainer.innerHTML=cardBuilder.getCardsHtml(chapters,{shape:"autooverflow",centerText:!0,overlayText:!1,showTitle:!0,showChapterTime:!0,multiSelect:!1,overlayMoreButton:!1,playedButton:!1,ratingButton:!1,moreButton:!1,centerPlayButton:!0,action:"play",enableUserData:!1}),imageLoader.lazyChildren(options.itemsContainer)}}});