define(["loading","./focushandler","focusManager","browser","emby-button","scrollStyles","emby-scroller"],function(loading,focusHandler,focusManager,browser){"use strict";function focusViewSlider(){var selected=this.querySelector(".selected");selected?focusManager.focus(selected):focusManager.autoFocus(this)}return function(page,pageOptions){var self=this;pageOptions=pageOptions||{},page.querySelector(".contentScrollSlider").classList.add("focuscontainer-x");var focusTimeout,selectedItemInfoElement=page.querySelector(".selectedItemInfo"),selectedIndexElement=page.querySelector(".selectedIndex");self.renderTabs=function(tabs){var view,instance,userViewNames;page.querySelector(".userViewNames").innerHTML=tabs.map(function(i){return'<button is="emby-button" class="flat btnUserViewHeader button-link" data-id="'+i.Id+'" data-type="'+(i.CollectionType||"")+'"><span class="userViewButtonText">'+i.Name+"</span></button>"}).join(""),instance=self,(userViewNames=(view=page).querySelector(".userViewNames")).focus=focusViewSlider,loading.hide(),setTimeout(function(){var initialTab=userViewNames.querySelector(".btnUserViewHeader");initialTab&&instance.setFocusDelay(view,initialTab)},0),function(view){{var scrollSlider;pageOptions.handleFocus&&(scrollSlider=view.querySelector(".contentScrollSlider"),self.focusHandler=new focusHandler({parent:scrollSlider,selectedItemInfoElement:selectedItemInfoElement,selectedIndexElement:selectedIndexElement,animateFocus:pageOptions.animateFocus,enableBackdrops:!0}))}}(page),function(view,instance){var userViewNames=view.querySelector(".userViewNames");userViewNames.addEventListener("click",function(e){var elem=e.target.closest(".btnUserViewHeader");elem&&instance.setFocusDelay(view,elem)}),userViewNames.addEventListener("focus",function(e){var elem=e.target.closest(".btnUserViewHeader");elem&&instance.setFocusDelay(view,elem)},!0)}(page,self)};var focusDelay=0;self.setFocusDelay=function(view,elem,immediate){var onTimeout,viewId=elem.getAttribute("data-id"),btn=view.querySelector(".btnUserViewHeader.selected");btn&&viewId===btn.getAttribute("data-id")||(elem!==btn&&(btn&&btn.classList.remove("selected"),elem.classList.add("selected")),focusTimeout&&clearTimeout(focusTimeout),onTimeout=function(){!function(page,id,self){var btn=page.querySelector(".btnUserViewHeader[data-id='"+id+"']");page.querySelector(".itemScrollFrame").scrollToPosition({left:0,behavior:"instant"});var contentScrollSlider=page.querySelector(".contentScrollSlider");contentScrollSlider.innerHTML="";var promise=self.loadViewContent.call(self,page,id,btn.getAttribute("data-type"));promise&&browser.animate&&promise.then(function(){contentScrollSlider.animate([{opacity:"0",transform:"translate3d(1%, 0, 0)",offset:0},{opacity:"1",transform:"none",offset:1}],{duration:300,iterations:1})})}(view,viewId,self)},immediate?onTimeout():focusTimeout=setTimeout(onTimeout,focusDelay),focusDelay=700)},self.destroy=function(){self.focusHandler&&(self.focusHandler.destroy(),self.focusHandler=null)}}});