define(["dialogHelper","globalize","layoutManager","mediaInfo","apphost","connectionManager","require","loading","imageLoader","scrollStyles","emby-button","emby-input","paper-icon-button-light","css!./../formdialog","css!./recordingcreator","material-icons","flexStyles","emby-scroller"],function(dialogHelper,globalize,layoutManager,mediaInfo,appHost,connectionManager,require,loading,imageLoader){"use strict";var currentDialog,currentItemId,currentServerId,currentResolve,recordingDeleted=!1;function closeDialog(isDeleted){recordingDeleted=isDeleted,dialogHelper.close(currentDialog)}function onSubmit(e){var form=this,apiClient=connectionManager.getApiClient(currentServerId);return apiClient.getLiveTvTimer(currentItemId).then(function(item){item.PrePaddingSeconds=60*form.querySelector("#txtPrePaddingMinutes").value,item.PostPaddingSeconds=60*form.querySelector("#txtPostPaddingMinutes").value,apiClient.updateLiveTvTimer(item).then(currentResolve)}),e.preventDefault(),!1}function init(context){context.querySelector(".btnCancel").addEventListener("click",function(){closeDialog(!1)}),context.querySelector(".btnCancelRecording").addEventListener("click",function(){(function(apiClient,timerId){return new Promise(function(resolve,reject){require(["recordingHelper"],function(recordingHelper){recordingHelper.cancelTimerWithConfirmation(timerId,apiClient.serverId()).then(resolve,reject)})})})(connectionManager.getApiClient(currentServerId),currentItemId).then(function(){closeDialog(!0)})}),context.querySelector("form").addEventListener("submit",onSubmit)}function reload(context,id){loading.show(),currentItemId=id,connectionManager.getApiClient(currentServerId).getLiveTvTimer(id).then(function(result){!function(context,item){item.ProgramInfo,context.querySelector("#txtPrePaddingMinutes").value=item.PrePaddingSeconds/60,context.querySelector("#txtPostPaddingMinutes").value=item.PostPaddingSeconds/60,loading.hide()}(context,result),loading.hide()})}return{show:function(itemId,serverId,options){return new Promise(function(resolve,reject){recordingDeleted=!1,currentServerId=serverId,loading.show(),options=options||{},currentResolve=resolve,require(["text!./recordingeditor.template.html"],function(template){var dialogOptions={removeOnClose:!0,scrollY:!1};layoutManager.tv&&(dialogOptions.size="fullscreen");var dlg=dialogHelper.createDialog(dialogOptions);dlg.classList.add("formDialog"),dlg.classList.add("recordingDialog"),layoutManager.tv||(dlg.style["min-width"]="20%",dlg.classList.add("dialog-fullscreen-lowres"));var html="";html+=globalize.translateDocument(template,"sharedcomponents"),dlg.innerHTML=html,!1===options.enableCancel&&dlg.querySelector(".formDialogFooter").classList.add("hide"),(currentDialog=dlg).addEventListener("closing",function(){recordingDeleted||dlg.querySelector(".btnSubmit").click()}),dlg.addEventListener("close",function(){recordingDeleted&&resolve({updated:!0,deleted:!0})}),init(dlg),reload(dlg,itemId),dialogHelper.open(dlg)})})}}});