(()=>{function e(c,t,e,o,n,l,s){var u,r=this,y=[];function d(e){var t,n,r=_.cloneDeep(u.c8y_RelayArray),a=p(r[e])?"OPEN":"CLOSED",i=(i=e,n=a,y=_(y).push({relayIndex:i,targetRelayState:n}).uniqBy("relayIndex").value(),((e,t,n)=>(e={deviceId:u.id,c8y_RelayArray:e},t=p(e.c8y_RelayArray[n]=t)?l("Close relay {{relayNo}}"):l("Open relay {{relayNo}}"),e.description=s.getString(t,{relayNo:n+1}),e))(r,a,e));n=e,_.isEqual(_.head(y).relayIndex,n)&&(t=i,o.createWithNotifications(t).then(function(e){e.created.then(function(){g(s.getString('"{{description | translate}}" will be executed.',t))}),e.completed.then(function(e){var t;y=_.drop(y),e.status===o.status.SUCCESSFUL?(t=e,g(s.getString('"{{description | translate}}" completed.',t)),c.onSuccess&&c.onSuccess({operationResult:t})):e.status===o.status.FAILED&&(e.failureReason?f(s.getString('"{{description | translate}}" failed due to: "{{failureReason | translate}}".',e)):f(s.getString('"{{description | translate}}" failed.',e)),c.onFailure)&&c.onFailure({operationResult:e}),y.length&&d(_.head(y).relayIndex)})}))}function p(e){return"CLOSED"===e}function g(e){a(n.success,e)}function f(e){a(n.danger,e)}function a(e,t){c.suppressAlerts&&c.suppressAlerts()||e(t)}function i(e){return _.find(y,{relayIndex:e})}_.assign(r,{toggle:d,isSupported:function(){return e.supportsOperation(u,"c8y_RelayArray")},isClosed:p,iconClass:function(e,t){e=i(e)?"dlt-c8y-icon-circle-o-notch icon-spin":p(t)?"dlt-c8y-icon-check text-success":"dlt-c8y-icon-ban text-danger";return e},isOperationInQueue:i}),c.$watch("device()",function(e){(e=e&&(e.id||e))&&t.detailRealtime(e,c).then(function(e){u=e,r.deviceRealtime=e})})}e.$inject=["$scope","c8yInventory","c8yDevices","c8yDeviceControl","c8yAlert","gettext","gettextCatalog"],angular.module("c8y.deviceControl.relayArray").controller("c8yRelayArrayControlCtrl",e)})();