define(["exports","./../emby-apiclient/connectionmanager.js","./../loading/loading.js","./globalize.js","./itemmanager/itemmanager.js"],function(_exports,_connectionmanager,_loading,_globalize,_itemmanager){function showToast(options){Emby.importModule("./modules/toast/toast.js").then(function(toast){return toast(options)})}function changeRecordingToSeries(apiClient,timerId,programId,confirmTimerCancellation){return _loading.default.show(),apiClient.getItem(apiClient.getCurrentUserId(),programId).then(function(item){return item.IsSeries?apiClient.getNewLiveTvTimerDefaults({programId:programId}).then(function(timerDefaults){return apiClient.createLiveTvSeriesTimer(timerDefaults).then(function(){_loading.default.hide(),showToast(_globalize.default.translate("SeriesRecordingScheduled"))})}):cancelTimer(apiClient,timerId,confirmTimerCancellation).then(function(result){return _loading.default.hide(),Promise.resolve(result)})})}function cancelTimer(apiClient,timerId,confirm){return _itemmanager.default.deleteItems({items:[{Id:timerId,ServerId:apiClient.serverId(),Type:"Timer"}],confirm:!0===confirm,navigate:!1})}function createRecording(apiClient,programId,isSeries){return _loading.default.show(),apiClient.getNewLiveTvTimerDefaults({programId:programId}).then(function(item){return(isSeries?apiClient.createLiveTvSeriesTimer(item):apiClient.createLiveTvTimer(item)).then(function(){_loading.default.hide(),showToast(_globalize.default.translate("RecordingScheduled"))})})}function showMultiCancellationPrompt(serverId,programId,timerId,timerStatus,seriesTimerId){var options,items=[];return items.push({name:_globalize.default.translate("HeaderKeepRecording"),id:"cancel",type:"submit"}),items.push("InProgress"===timerStatus?{name:_globalize.default.translate("HeaderStopRecording"),id:"canceltimer",type:"cancel"}:{name:_globalize.default.translate("HeaderCancelRecording"),id:"canceltimer",type:"cancel"}),items.push({name:_globalize.default.translate("HeaderCancelSeries"),id:"cancelseriestimer",type:"cancel"}),options={text:_globalize.default.translate("MessageConfirmRecordingCancellation"),buttons:items},Emby.importModule("./modules/dialog/dialog.js").then(function(dialog){return dialog(options)}).then(function(result){var apiClient=_connectionmanager.default.getApiClient(serverId);return"canceltimer"===result?(_loading.default.show(),cancelTimer(apiClient,timerId,!0)):"cancelseriestimer"===result?(_loading.default.show(),apiClient.cancelLiveTvSeriesTimer(seriesTimerId).then(function(){showToast(_globalize.default.translate("SeriesCancelled")),_loading.default.hide()})):Promise.resolve()})}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;_exports.default={cancelTimer:cancelTimer,createRecording:createRecording,changeRecordingToSeries:changeRecordingToSeries,toggleRecording:function(serverId,programId,timerId,timerStatus,seriesTimerId){var apiClient=_connectionmanager.default.getApiClient(serverId),hasTimer=timerId&&"Cancelled"!==timerStatus;return seriesTimerId&&hasTimer?showMultiCancellationPrompt(serverId,0,timerId,timerStatus,seriesTimerId):hasTimer&&programId?changeRecordingToSeries(apiClient,timerId,programId,!0):programId?createRecording(apiClient,programId):Promise.reject()}}});