define(["exports","./../common/textencoding.js","./../common/globalize.js","./../loading/loading.js","./../layoutmanager.js","./../approuter.js","./../cardbuilder/cardbuilder.js","./../listview/listview.js","./../common/usersettings/usersettings.js","./../registrationservices/registrationservices.js"],function(_exports,_textencoding,_globalize,_loading,_layoutmanager,_approuter,_cardbuilder,_listview,_usersettings,_registrationservices){function SectionsController(view){this.view=view,this.sectionsContainer=this.getSectionsContainer()}function autoFocus(){!this.instance.autoFocus()&&this.retries<20?(this.retries++,setTimeout(autoFocus.bind(this),100)):this.retries=null}function getHorizontalScrollerStartTag(scrollButtons){return'
'}function loadSection(instance,elem,section){var bannerClass,viewScrollX="x"===instance.scrollDirection(),title=_textencoding.default.htmlEncode(section.Name),viewType=section.ViewType||"cards",sectionScrollX=(viewScrollX&&"buttons"===viewType&&(section.ViewType=viewType="cards",section.ListOptions.fields=[],section.ListOptions.lines=null,section.ListOptions.centerText=!0,section.ListOptions.sideFooter=!1,section.ListOptions.smallSideFooter=!1,section.CardSizeOffset=-2),!viewScrollX&&"Vertical"!==section.ScrollDirection),listOptions=("onnow"===section.SectionType&&!function(instance,elem){var html="",instance=instance.getApiClient(),html=(html=(html=(html=(html=(html=(html=html+'
")}(instance,elem),section.ListOptions||{}),sideFooter="cards"===viewType&&listOptions.sideFooter&&!listOptions.smallSideFooter||"list"===viewType&§ionScrollX,smallSideFooter="cards"===viewType&&listOptions.sideFooter&&listOptions.smallSideFooter||"buttons"===viewType,headerButtons=(!(sideFooter||smallSideFooter||listOptions.cardLayout)||viewScrollX||elem.classList.add("verticalSection-extrabottompadding"),!_layoutmanager.default.tv&§ion.HeaderButtons||[]),sectionTitleContainerClass="sectionTitleContainer",isPlainContent="text"===viewType||"content"===viewType,focusableTypeAttribute=(sectionTitleContainerClass+="list"===viewType&§ionScrollX?" sectionTitleContainer-wrappedlistview":" sectionTitleContainer-cards",viewScrollX||(isPlainContent?elem.classList.add("padded-left","padded-left-page","padded-right"):sectionTitleContainerClass+=" padded-left padded-left-page padded-right"),""),sectionHref=section.Href,html=(sectionHref&&!viewScrollX&&instance.enableFocusPreview&&instance.enableFocusPreview()&&(sectionHref=null),!(title&§ionHref||headerButtons.length)||viewScrollX||(sectionTitleContainerClass+=" focusable",focusableTypeAttribute=' data-focusabletype="nearest"'),""),sectionTitleClass="sectionTitle sectionTitle-cards";if(viewScrollX&&(sectionTitleClass+=" sectionTitle-cards-horizontal"),"text"===viewType){switch(null==(_section$TextInfo=section.TextInfo)?void 0:_section$TextInfo.Level){case"Error":bannerClass="errorBanner";break;case"Warning":bannerClass="warningBanner";break;default:bannerClass="infoBanner"}html+='
'}var _section$TextInfo=title||headerButtons.length;_section$TextInfo&&(html+='
"),title&&(sectionHref&&(html=(html+='
')+''+title+"
",titleRendered=!0),titleRendered||(html+='
'+title+"
"));for(var i=0,length=headerButtons.length;i
'+button.Icon+""+_textencoding.default.htmlEncode(button.Name||"")+"":html+='":button.Href?html+=''+button.Icon+"":html+='"}_section$TextInfo&&(html+=""),section.Subtitle&&(html+='
'+_textencoding.default.htmlEncode(section.Subtitle)+"
");var titleRendered,sectionTitleContainerClass=!isPlainContent,contentButtons=("content"!==viewType&&("text"===viewType?(html+='
',html=title?(html+='
')+_textencoding.default.htmlEncode((null==(focusableTypeAttribute=section.TextInfo)?void 0:focusableTypeAttribute.Text)||"")+"
":(html+='
')+_textencoding.default.htmlEncode((null==(sectionHref=section.TextInfo)?void 0:sectionHref.Text)||"")+"
",html+="
"):(titleRendered=section.Monitor||[],sectionTitleClass=section.MonitorIds||[],_section$TextInfo=titleRendered.length?' data-monitor="'+titleRendered.join(",")+'"':"",isPlainContent=sectionTitleClass.length?' data-monitorids="'+sectionTitleClass.join(",")+'"':"",title=section.RefreshInterval?' data-refreshinterval="'+section.RefreshInterval+'"':"",focusableTypeAttribute=null!=section.ImmediateUpdate?' data-immediateupdate="'+section.ImmediateUpdate+'"':"",titleRendered=null!=(sectionHref=section.QueryOptions)&§ionHref.ParentId?' data-parentid="'+section.QueryOptions.ParentId+'"':"",sectionTitleClass="itemsContainer",viewScrollX||(sectionTitleClass+=" focuscontainer-x"),viewScrollX&&"spotlight"===section.SectionType&&null!=(sectionHref=section.SpotlightButtons)&§ionHref.length&&(sectionTitleClass+=" spotlightItemsContainer"),sectionHref=!listOptions.autoWidth&&!viewScrollX,listOptions.autoWidth||(smallSideFooter?sectionTitleClass+=" itemsContainer-sideFooters itemsContainer-smallSideFooters":sideFooter&&(sectionTitleClass+=" itemsContainer-sideFooters")),sectionScrollX?(!_layoutmanager.default.tv&§ion.FinePointerWrap&&(sectionTitleClass+=" itemsContainer-finepointerwrap",sectionHref=!1),html+=getHorizontalScrollerStartTag()+'
"):html=html+('
')),"text"===viewType&&(html+="
"),viewScrollX&&null!=(sectionScrollX=section.SpotlightButtons)&§ionScrollX.length&&(html+='';for(var _i=0,_length=contentButtons.length;_i<_length;_i++){var _button=contentButtons[_i];_button.Href?html+='
"}return elem.innerHTML=html,hasContentButtons&&elem.querySelector(".contentButtons").addEventListener("click",instance.onContentButtonClicked.bind({instance:instance,section:section})),viewScrollX&&null!=(sectionHref=section.SpotlightButtons)&§ionHref.length&&((_section$TextInfo=elem.querySelector(".spotlightButtonsItemsContainer")).fetchData=fetchSpotlightButtonItems.bind({instance:instance,section:section}),_section$TextInfo.getListOptions=fetchSpotlightButtonListOptions.bind({instance:instance,section:section}),(_section$TextInfo.parentContainer=_section$TextInfo).addEventListener("action-null",instance.onSpotlightButtonsItemsContainerAction.bind({instance:instance,section:section}))),sectionTitleContainerClass?((isPlainContent=elem.querySelector(".itemsContainer")).fetchData=section.fetchData,isPlainContent.getListOptions=section.getListOptions,isPlainContent.onRefreshing=instance.onSectionRefreshing.bind({instance:instance,section:section,elem:elem}),isPlainContent.afterRefresh=instance.afterSectionRefreshed.bind({instance:instance,section:section,elem:elem}),isPlainContent.parentContainer=elem,sideFooter||smallSideFooter?isPlainContent.removeAttribute("data-cardsizeoffset"):section.CardSizeOffset&&isPlainContent.setAttribute("data-cardsizeoffset",section.CardSizeOffset.toString()),instance.addFocusBehavior&&instance.addFocusBehavior(isPlainContent),"custom"===listOptions.action&&isPlainContent.addEventListener("action-null",instance.onItemsContainerAction.bind({instance:instance,section:section})),isPlainContent.waitForCustomElementUpgrade()):(elem.classList.remove("hide"),Promise.resolve())}function fetchSpotlightButtonItems(){var section=this.section;return Promise.resolve(section.SpotlightButtons)}function fetchSpotlightButtonListOptions(){var section=this.section;return{renderer:_cardbuilder.default,options:Object.assign({shape:"fourThree",overlayText:!0,multiSelect:!1,fields:["Name"],action:"custom",scalable:!0,cardClass:"spotlightButtonCard-horizontal",cardContentClass:"spotlightButtonCardContent-horizontal",context:section.CollectionType,horizontal:!0,cardBoxClass:"cardBox-horizontalgrid"},{}),virtualScrollLayout:null}}function fetchSections(instance,options){return instance.fetchSections(options).catch(function(errorResponse){return console.log("Error fetching sections: "+errorResponse),Emby.importModule("./modules/common/responsehelper.js").then(function(responseHelper){return responseHelper.getErrorInfo(errorResponse,{enableDefaultTitle:!1}).then(function(errorInfo){return[{Id:"error",Name:errorInfo.title,ScrollDirection:"Vertical",ViewType:"text",TextInfo:{Text:errorInfo.html,Level:"Error"},ContentButtons:[{Name:_globalize.default.translate("Retry"),Icon:"",OnClick:instance.refreshSections.bind(instance)}]}]})})})}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,SectionsController.prototype.getSectionsContainer=function(){return this.view.querySelector(".sections")||this.view},SectionsController.prototype.fetchSections=function(options){return Promise.resolve([])},SectionsController.prototype.onItemsContainerAction=function(e){var e=e.target,itemsContainer=e.closest(".itemsContainer");itemsContainer&&(e=e.closest(itemsContainer.getItemSelector()))&&this.instance.onItemCustomAction({section:this.section,item:itemsContainer.getItemFromElement(e),itemElement:e})},SectionsController.prototype.onItemCustomAction=function(options){},SectionsController.prototype.onSpotlightButtonsItemsContainerAction=function(e){var e=e.target,itemsContainer=e.closest(".itemsContainer");itemsContainer&&(e=e.closest(itemsContainer.getItemSelector()))&&this.instance.onSpotlightButtonCustomAction({section:this.section,item:itemsContainer.getItemFromElement(e),itemElement:e})},SectionsController.prototype.onSpotlightButtonCustomAction=function(options){},SectionsController.prototype.onContentButtonClicked=function(e){var button=e.target.closest(".contentButton"),section=this.section;button&&(button=button.getAttribute("data-buttonindex"))&&(button=parseInt(button),section=section.ContentButtons[button].OnClick)&§ion(e)},SectionsController.prototype.onSectionRefreshing=function(result){var instance=this.instance,section=this.section,elem=this.elem;section.PremiumFeature&&(result.Items||result).length&&_registrationservices.default.validateFeature(section.PremiumFeature,{viewOnly:!0,showDialog:!1}).then(function(){var _elem$querySelector;null!=(_elem$querySelector=elem.querySelector(".sectionPremiereContainer"))&&_elem$querySelector.remove(),elem.querySelector(".itemsContainer").classList.remove("hide")},function(){var html,itemsContainer=elem.querySelector(".itemsContainer");itemsContainer.classList.add("hide"),elem.querySelector(".sectionPremiereContainer")||(html=(html=(html="")+'