(()=>{function e(r,t,e,i,s,a,l){var o,n=this;function c(){return o&&o.c8y_Relay&&"CLOSED"===o.c8y_Relay.relayState}function u(n){var e={deviceId:o.id,description:n.description,c8y_Relay:{relayState:n.flag}};return i.createWithNotifications(e).then(function(e){e.created.then(function(){d(n.messages.created)}),e.completed.then(function(e){{var t,s;(a={success:n.messages.success,failure:n.messages.failure},(e=e).status===i.status.SUCCESSFUL)?(t=e,d(s=a.success),r.onSuccess&&r.onSuccess({operationResult:t})):e.status===i.status.FAILED&&(t=a,(s=e).failureReason?f(l.getString(t.failureWithReason,s)):f(t.failure),r.onFailure)&&r.onFailure({operationResult:s})}var a})})}function d(e){y(s.success,e)}function f(e){y(s.danger,e)}function y(e,t){r.suppressAlerts&&r.suppressAlerts()||e(t)}r.$watch("device()",function(e){(e=e&&(e.id||e))&&t.detailRealtime(e,r).then(function(e){o=e})}),this.isSupported=function(){return e.supportsOperation(o,"c8y_Relay")},this.isClosed=c,this.toggle=function(){var e;return e=c(),(e=_.isUndefined(e)?!n.buttonChecked():e)?u({flag:"OPEN",description:a("Open relay"),messages:{created:a("The relay will be opened."),success:a("The relay has been opened."),failure:a("Failed to open the relay."),failureWithReason:a('Failed to open the relay due to: "{{failureReason | translate}}".')}}):u({flag:"CLOSED",description:a("Close relay"),messages:{created:a("The relay will be closed."),success:a("The relay has been closed."),failure:a("Failed to close the relay."),failureWithReason:a('Failed to close the relay due to: "{{failureReason | translate}}".')}})}}e.$inject=["$scope","c8yInventory","c8yDevices","c8yDeviceControl","c8yAlert","gettext","gettextCatalog"],angular.module("c8y.deviceControl.relay").controller("c8yRelayControlCtrl",e)})();