(()=>{function e(e,n){return new o(e,n)}var i={},t=["onGeofenceCreateAlarm","onGeofenceSendEmail"],n=_.throttle(function(e){i.x=e.pageX,i.y=e.pageY},50),o=L.FeatureGroup.extend({initialize:function(e,n){var t=this;L.FeatureGroup.prototype.initialize.call(this,[]),this.smartRulesSvc=e,this.mapApi=n,this._rules=[],this._mousePos={},n.event.$on("refresh",function(e,n){t.refresh(n)})},onAdd:function(e){$(e.getContainer()).mousemove(n),L.FeatureGroup.prototype.onAdd.call(this,e)},onRemove:function(e){$(e.getContainer()).off("mousemove",n),L.FeatureGroup.prototype.onRemove.call(this,e)},refresh:function(){var n=this;return this.smartRulesSvc.list().then(function(e){return e.filter(function(e){return _.includes(t,e.ruleTemplateName)}).filter(function(e){return e.config&&e.config.geofence}).filter(function(e){return!e.enabledSources||(e.enabledSources,e.enabledSources.length)})}).then(function(e){e.forEach(function(n){var e=this,o=L.polygon(n.config.geofence,{weight:1}).bindTooltip(n.name),t=this.mapApi.markers.filter(function(e){return this.smartRulesSvc.hasSource(n,e.id)},this);o.on("contextmenu",function(n){o.bringToBack(),o.fireEvent("mouseout",n);var t=document.elementFromPoint(i.x,i.y);e.eachLayer(function(e){e._path&&e._path===t&&e.fireEvent("mouseover",n)})}),o.on("mouseover",function(){o.setStyle({fillColor:"orange"}),t.forEach(function(e){$(e._icon).addClass("blink")})}),o.on("mouseout",function(){o.setStyle({fillColor:void 0}),t.forEach(function(e){$(e._icon).removeClass("blink")})}),this.addLayer(o)},n)})}});e.$inject=["smartRulesSvc","mapApi"],angular.module("c8y.ui").constant("c8yGeofenceLayer",e)})();