define(["connectionManager","dom","recordingHelper","paper-icon-button-light","emby-button"],function(connectionManager,dom,recordingHelper){"use strict";function RecordingButton(options){(this.options=options).item?this.refreshItem(options.item):options.itemId&&options.serverId&&this.refresh(options.itemId,options.serverId);var button=options.button;button.querySelector("i").innerHTML="&#xE061;";var clickFn=function(e){var serverId,programId,timerId,timerStatus,seriesTimerId,instance,item=this.item;item&&(serverId=item.ServerId,programId=item.Id,timerId=item.TimerId,timerStatus=item.Status,seriesTimerId=item.SeriesTimerId,instance=this,recordingHelper.toggleRecording(serverId,programId,timerId,timerStatus,seriesTimerId).then(function(){instance.refresh(serverId,programId)}))}.bind(this);this.clickFn=clickFn,dom.addEventListener(button,"click",clickFn,{passive:!0})}return RecordingButton.prototype.refresh=function(serverId,itemId){var apiClient=connectionManager.getApiClient(serverId),self=this;apiClient.getItem(apiClient.getCurrentUserId(),itemId).then(function(item){self.refreshItem(item)})},RecordingButton.prototype.refreshItem=function(item){var button=this.options.button;this.item=item,button.querySelector("i").innerHTML=function(item){var status;if("SeriesTimer"===item.Type)return"&#xE062;";if(item.TimerId||item.SeriesTimerId)status=item.Status||"Cancelled";else{if("Timer"!==item.Type)return"&#xE061;";status=item.Status}return item.SeriesTimerId&&"Cancelled"!==status?"&#xE062;":"&#xE061;"}(item),item.TimerId&&"Cancelled"!==(item.Status||"Cancelled")?button.classList.add("recordingIcon-active"):button.classList.remove("recordingIcon-active")},RecordingButton.prototype.destroy=function(){var button,clickFn,options=this.options;options&&(button=options.button,(clickFn=this.clickFn)&&dom.removeEventListener(button,"click",clickFn,{passive:!0})),this.options=null,this.item=null},RecordingButton});