(()=>{function t(s,t){return n.$inject=["$scope","$log"],{scope:{channel:"@",data:"&onData",dataUpdate:"&onDataUpdate",subscribed:"&onSubscribed",state:"="},replace:!0,restrict:"EA",template:'<button class="btn btn-link c8y-realtime" ng-click="on()" ng-disabled="!channel"><span class="c8y-pulse {{icon()}}"></span> {{\''.concat(t("Realtime"),"' | translate}}</button>"),controller:n,require:{formCtrl:"?^^form"},link:function(t,n,a,e){t.formCtrl=e.formCtrl}};function n(a,e){var c=a.$id;function r(t,n){s.addListener(t,n,"CREATE",o),s.addListener(t,n,"UPDATE",i),s.start(t,n)}function o(t,n){a.data({$data:n})}function i(t,n){a.dataUpdate({$data:n})}function l(t){try{s.removeSubscriber(c,t)}catch(t){e.warn(t)}}a.icon=function(){return s.icon(a.state||!1)},a.on=function(){a.state=!a.state,a.formCtrl&&!a.formCtrl.$dirty&&a.formCtrl.$setDirty()},a.$watch("channel",function(t,n){n&&n!==t&&l(n);t&&a.state&&r(c,t)}),a.$watch("state",function(t,n){if(t!==n&&((n=a.channel)&&t&&r(c,n),!t)&&n){t=c;try{s.stop(t,n)}catch(t){e.warn(t)}}}),a.$on("$destroy",function(){var t=a.channel;t&&l(t)})}}t.$inject=["c8yRealtime","gettext"],angular.module("c8y.ui").directive("c8yRealtimeButton",t)})();