define(["dialogHelper","layoutManager","globalize","browser","dom","emby-button","css!./actionsheet","material-icons","scrollStyles","listViewStyle"],function(dialogHelper,layoutManager,globalize,browser,dom){"use strict";function getOffsets(elems){var doc=document,results=[];if(!doc)return results;for(var box,elem,i=0,length=elems.length;i0&&(pos.left-=overflowX+20),overflowY>0&&(pos.top-=overflowY+20),pos.top+=options.offsetTop||0,pos.left+=options.offsetLeft||0,pos.top=Math.max(pos.top,10),pos.left=Math.max(pos.left,10),pos}function centerFocus(elem,horiz,on){require(["scrollHelper"],function(scrollHelper){var fn=on?"on":"off";scrollHelper.centerFocus[fn](elem,horiz)})}function show(options){var isFullscreen,dialogOptions={removeOnClose:!0,enableHistory:options.enableHistory,scrollY:!1};layoutManager.tv?(dialogOptions.size="fullscreen",isFullscreen=!0,!0,dialogOptions.autoFocus=!0):(dialogOptions.modal=!1,dialogOptions.entryAnimation=options.entryAnimation,dialogOptions.exitAnimation=options.exitAnimation,dialogOptions.entryAnimationDuration=options.entryAnimationDuration||140,dialogOptions.exitAnimationDuration=options.exitAnimationDuration||100,dialogOptions.autoFocus=!1);var dlg=dialogHelper.createDialog(dialogOptions);isFullscreen?dlg.classList.add("actionsheet-fullscreen"):dlg.classList.add("actionsheet-not-fullscreen"),dlg.classList.add("actionSheet"),options.dialogClass&&dlg.classList.add(options.dialogClass);var html="",scrollClassName=layoutManager.tv?"scrollY smoothScrollY hiddenScrollY":"scrollY",style="";if(options.items.length>20){style+="min-width:"+(dom.getWindowSize().innerWidth>=300?240:200)+"px;"}var i,length,option,itemIcon,renderIcon=!1,icons=[];for(i=0,length=options.items.length;i');var center=options.title&&!renderIcon;center||layoutManager.tv?html+='
':html+='
',options.title&&(html+='

',html+=options.title,html+="

"),options.text&&(html+='

',html+=options.text,html+="

");var scrollerClassName="actionSheetScroller";layoutManager.tv&&(scrollerClassName+=" actionSheetScroller-tv focuscontainer-x focuscontainer-y"),html+='
';var menuItemClass="listItem listItem-button actionSheetMenuItem";for((options.border||options.shaded)&&(menuItemClass+=" listItem-border"),options.menuItemClass&&(menuItemClass+=" "+options.menuItemClass),layoutManager.tv&&(menuItemClass+=" listItem-focusscale"),layoutManager.mobile&&(menuItemClass+=" actionsheet-xlargeFont"),i=0,length=options.items.length;i
';else{var autoFocus=option.selected&&layoutManager.tv?" autoFocus":"",optionId=null==option.id||""===option.id?option.value:option.id;html+="',itemIcon=icons[i],itemIcon?html+=''+itemIcon+"":renderIcon&&!center&&(html+=''),html+='
',html+='
',html+=option.name||option.textContent||option.innerText,html+="
",option.secondaryText&&(html+='
',html+=option.secondaryText,html+="
"),html+="
",option.asideText&&(html+='
',html+=option.asideText,html+="
"),html+=""}options.showCancel&&(html+='
',html+='",html+="
"),html+="
",dlg.innerHTML=html,layoutManager.tv&¢erFocus(dlg.querySelector(".actionSheetScroller"),!1,!0),dlg.querySelector(".btnCloseActionSheet")&&dlg.querySelector(".btnCloseActionSheet").addEventListener("click",function(){dialogHelper.close(dlg)});var selectedId,timeout;return options.timeout&&(timeout=setTimeout(function(){dialogHelper.close(dlg)},options.timeout)),new Promise(function(resolve,reject){var isResolved;dlg.addEventListener("click",function(e){var actionSheetMenuItem=dom.parentWithClass(e.target,"actionSheetMenuItem");actionSheetMenuItem&&(selectedId=actionSheetMenuItem.getAttribute("data-id"),options.resolveOnClick&&(options.resolveOnClick.indexOf?-1!==options.resolveOnClick.indexOf(selectedId)&&(resolve(selectedId),isResolved=!0):(resolve(selectedId),isResolved=!0)),dialogHelper.close(dlg))}),dlg.addEventListener("close",function(){layoutManager.tv&¢erFocus(dlg.querySelector(".actionSheetScroller"),!1,!1),timeout&&(clearTimeout(timeout),timeout=null),isResolved||(null!=selectedId?(options.callback&&options.callback(selectedId),resolve(selectedId)):reject())}),dialogHelper.open(dlg);var pos=options.positionTo&&"fullscreen"!==dialogOptions.size?getPosition(options,dlg):null;pos&&(dlg.style.position="fixed",dlg.style.margin=0,dlg.style.left=pos.left+"px",dlg.style.top=pos.top+"px")})}return{show:show}});