define(["dialogHelper","layoutManager","globalize","require","material-icons","emby-button","paper-icon-button-light","emby-input","formDialogStyle","flexStyles","emby-scroller"],function(dialogHelper,layoutManager,globalize,require){"use strict";function showDialog(options,template){var dialogOptions={removeOnClose:!0,scrollY:!1},enableTvLayout=layoutManager.tv;enableTvLayout&&(dialogOptions.size="fullscreen");var dlg=dialogHelper.createDialog(dialogOptions);dlg.classList.add("formDialog","align-items-center","justify-content-center"),dlg.innerHTML=globalize.translateHtml(template,"sharedcomponents");var originalString,strWith,reg,formDialogContent=dlg.querySelector(".formDialogContent");formDialogContent.classList.add("no-grow"),enableTvLayout?(formDialogContent.style["max-width"]="50%",formDialogContent.style["max-height"]="60%"):dlg.classList.add("dialog-fullscreen-lowres"),options.title?dlg.querySelector(".formDialogHeaderTitle").innerHTML=options.title||"":dlg.querySelector(".formDialogHeaderTitle").classList.add("hide"),options.html?dlg.querySelector(".dialogContentInner").innerHTML=options.html:options.preFormattedText?dlg.querySelector(".dialogContentInner").innerHTML='<pre style="text-align:left;font-size:inherit;margin:0;">'+options.preFormattedText+"</pre>":options.text?dlg.querySelector(".dialogContentInner").innerText=(originalString=options.text||"",strWith="\n",reg=new RegExp("<br/>","ig"),originalString.replace(reg,strWith)):dlg.querySelector(".dialogContentInner").classList.add("hide");for(var dialogResult,html="",hasDescriptions=!1,i=0,length=options.buttons.length;i<length;i++){var item=options.buttons[i],buttonClass="btnOption raised formDialogFooterItem formDialogFooterItem-autosize";item.type&&(buttonClass+=" button-"+item.type),item.description&&(hasDescriptions=!0),hasDescriptions&&(buttonClass+=" formDialogFooterItem-vertical formDialogFooterItem-nomarginbottom"),item.href?html+='<a is="emby-linkbutton" target="_blank" href="'+item.href+'" class="'+buttonClass+'" data-id="'+item.id+'">'+item.name+"</a>":html+='<button is="emby-button" type="button" class="'+buttonClass+'" data-id="'+item.id+'">'+item.name+"</button>",item.description&&(html+='<div class="formDialogFooterItem formDialogFooterItem-autosize fieldDescription" style="margin-top:.25em!important;margin-bottom:1.25em!important;">'+item.description+"</div>")}function onButtonClick(){dialogResult=this.getAttribute("data-id"),dialogHelper.close(dlg)}dlg.querySelector(".formDialogFooter").innerHTML=html,hasDescriptions&&dlg.querySelector(".formDialogFooter").classList.add("formDialogFooter-vertical");var timeout,buttons=dlg.querySelectorAll(".btnOption");for(i=0,length=buttons.length;i<length;i++)buttons[i].addEventListener("click",onButtonClick);return options.timeout&&(timeout=setTimeout(function(){dialogResult="_timeout",dialogHelper.close(dlg)},options.timeout)),dialogHelper.open(dlg).then(function(){return timeout&&clearTimeout(timeout),dialogResult||Promise.reject()})}return function(text,title){var options="string"==typeof text?{title:title,text:text}:text;return require(["text!./dialog.template.html"]).then(function(responses){return showDialog(options,responses[0])})}});