define(["dialogHelper","layoutManager","globalize","browser","dom","emby-button","css!./actionsheet","material-icons","scrollStyles"],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},backButton=!1;layoutManager.tv?(dialogOptions.size="fullscreen",isFullscreen=!0,backButton=!0,dialogOptions.autoFocus=!0):(dialogOptions.modal=!1,dialogOptions.entryAnimation=options.entryAnimation,dialogOptions.exitAnimation=options.exitAnimation,dialogOptions.entryAnimationDuration=options.entryAnimationDuration||140,dialogOptions.exitAnimationDuration=options.exitAnimationDuration||160,dialogOptions.autoFocus=!1);var dlg=dialogHelper.createDialog(dialogOptions);isFullscreen?dlg.classList.add("actionsheet-fullscreen"):dlg.classList.add("actionsheet-not-fullscreen");var extraSpacing=!layoutManager.tv;extraSpacing&&dlg.classList.add("actionsheet-extraSpacing"),dlg.classList.add("actionSheet"),options.dialogClass&&dlg.classList.add(options.dialogClass);var html="",scrollType=layoutManager.desktop?"smoothScrollY":"hiddenScrollY",style="";if(options.items.length>20){var minWidth=dom.getWindowSize().innerWidth>=300?240:200;style+="min-width:"+minWidth+"px;"}var i,length,option,renderIcon=!1;for(i=0,length=options.items.length;i');var center=options.title&&!renderIcon;html+=center?'
':'
',options.title&&(layoutManager.tv?(html+='

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

"):(html+='

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

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

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

"),html+='
';var menuItemClass=browser.firefox?"actionSheetMenuItem actionSheetMenuItem-noflex":"actionSheetMenuItem";options.menuItemClass&&(menuItemClass+=" "+options.menuItemClass),extraSpacing&&(menuItemClass+=" actionSheetMenuItem-extraspacing");var actionSheetItemTextClass="actionSheetItemText";for(i=0,length=options.items.length;i',option.icon?html+=''+option.icon+"":renderIcon&&!center&&(html+=''),html+='
'+(option.name||option.textContent||option.innerText)+"
",option.secondaryText&&(html+='
'+option.secondaryText+"
"),html+=""}options.showCancel&&(html+='
',html+='",html+="
"),html+="
",dlg.innerHTML=html,layoutManager.tv&¢erFocus(dlg.querySelector(".actionSheetScroller"),!1,!0);var btnCloseActionSheet=dlg.querySelector(".btnCloseActionSheet");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&&(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 setPositions=function(){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")};browser.safari?setTimeout(setPositions,0):setPositions()})}return{show:show}});