define(["globalize","connectionManager","require","loading","datetime","scrollStyles","emby-button","emby-checkbox","emby-input","emby-select","paper-icon-button-light","css!./recordingcreator","material-icons","flexStyles"],function(globalize,connectionManager,require,loading,datetime){"use strict";var currentItemId,currentServerId;function renderTimer(context,item){context.querySelector("#txtPrePaddingMinutes").value=item.PrePaddingSeconds/60,context.querySelector("#txtPostPaddingMinutes").value=item.PostPaddingSeconds/60,context.querySelector(".selectChannels").value=item.RecordAnyChannel?"all":"one",context.querySelector(".selectAirTime").value=item.RecordAnyTime?"any":"original",context.querySelector(".selectShowType").value=item.RecordNewOnly?"new":"all",context.querySelector(".chkSkipEpisodesInLibrary").checked=item.SkipEpisodesInLibrary,context.querySelector(".selectKeepUpTo").value=item.KeepUpTo||0,item.ChannelName||item.ChannelNumber?context.querySelector(".optionChannelOnly").innerHTML=globalize.translate("ChannelNameOnly",item.ChannelName||item.ChannelNumber):context.querySelector(".optionChannelOnly").innerHTML=globalize.translate("OneChannel"),context.querySelector(".optionAroundTime").innerHTML=globalize.translate("AroundTime",datetime.getDisplayTime(datetime.parseISO8601Date(item.StartDate))),loading.hide()}function onSubmit(e){var form=this,apiClient=connectionManager.getApiClient(currentServerId);return apiClient.getLiveTvSeriesTimer(currentItemId).then(function(item){item.PrePaddingSeconds=60*form.querySelector("#txtPrePaddingMinutes").value,item.PostPaddingSeconds=60*form.querySelector("#txtPostPaddingMinutes").value,item.RecordAnyChannel="all"===form.querySelector(".selectChannels").value,item.RecordAnyTime="any"===form.querySelector(".selectAirTime").value,item.RecordNewOnly="new"===form.querySelector(".selectShowType").value,item.SkipEpisodesInLibrary=form.querySelector(".chkSkipEpisodesInLibrary").checked,item.KeepUpTo=form.querySelector(".selectKeepUpTo").value,apiClient.updateLiveTvSeriesTimer(item)}),e.preventDefault(),!1}function init(context){!function(context){for(var text,html="",i=0;i<=50;i++)text=0===i?globalize.translate("AsManyAsPossible"):1===i?globalize.translate("ValueOneEpisode"):globalize.translate("ValueEpisodeCount",i),html+='<option value="'+i+'">'+text+"</option>";context.querySelector(".selectKeepUpTo").innerHTML=html}(context),context.querySelector("form").addEventListener("submit",onSubmit)}function onFieldChange(e){this.querySelector(".btnSubmit").click()}return{embed:function(itemId,serverId,options){currentServerId=serverId,loading.show(),options=options||{},require(["text!./seriesrecordingeditor.template.html"],function(template){var context,id,apiClient,dlg=options.context;dlg.innerHTML=globalize.translateDocument(template,"sharedcomponents"),dlg.removeEventListener("change",onFieldChange),dlg.addEventListener("change",onFieldChange),dlg.classList.remove("hide"),init(dlg),context=dlg,id=itemId,apiClient=connectionManager.getApiClient(currentServerId),loading.show(),"string"==typeof id?(currentItemId=id,apiClient.getLiveTvSeriesTimer(id).then(function(result){renderTimer(context,result),loading.hide()})):id&&(currentItemId=id.Id,renderTimer(context,id),loading.hide())})}}});