(()=>{function e(e,n,t,l,a,o,r){var c,g=new l.Bounds,i=[],s={type:"polygon",stroke:!0,weight:1,color:"#2e3974",fillColor:"#2e3974",latlngs:[]},d={center:{},events:{},defaults:{tileLayerOptions:{referrerPolicy:"strict-origin-when-cross-origin"},doubleClickZoom:!1},bounds:g.get(),markers:i,paths:{geofencePath:s}};function f(e){e&&(d.center=_.assign(d.center,{lat:Number(e.lat),lng:Number(e.lng),zoom:17}))}function u(){0<s.latlngs.length&&(g.reset(),_.forEach(s.latlngs,function(e){g.add(e)}),d.bounds=g.get())}function h(){s.latlngs.length=0,i.length=0}function m(e,n){switch(e.name){case"leafletDirectiveMarker.dragstart":c={lat:n.model.lat,lng:n.model.lng,draggable:!0};break;case"leafletDirectiveMarker.dragend":s.latlngs[_.findIndex(s.latlngs,c)]={lat:n.model.lat,lng:n.model.lng,draggable:!0}}}e.gotoAddress=function(e){l.geoCode(e).then(function(e){e=_.get(e,"data[0]");return e?(e.lng=e.lon,e):(o.warning(r("Address could not be found.")),null)}).then(f)},e.centerMap=u,e.clearGeofence=h,e.chooseGeofence=function(){var e;n.close((e=s.latlngs,_.map(e,function(e){return{lat:e.lat,lng:e.lng}})))},e.cancel=n.dismiss,e.map=d,e.$on("leafletDirectiveMap.click",function(e,n){n={lat:n.leafletEvent.latlng.lat,lng:n.leafletEvent.latlng.lng,draggable:!0,icon:{type:"div",className:"normal-marker-icon",iconSize:[25,41],iconAnchor:[12.5,41]}},d.markers.push(n),s.latlngs.push(n),1===s.latlngs.length&&(d.paths={geofencePath:s})}),e.$on("leafletDirectiveMarker.dragend",m),e.$on("leafletDirectiveMarker.dragstart",m),h(),_.forEach(a,function(e){e.draggable=!0,e.icon={type:"div",className:"normal-marker-icon",iconSize:[25,41],iconAnchor:[12.5,41]},i.push(e),s.latlngs.push(e)}),0<s.latlngs.length?d.paths={geofencePath:s}:d.paths={},t(u,0)}e.$inject=["$scope","$uibModalInstance","$timeout","c8yGeo","geofenceLatLngs","c8yAlert","gettext"],angular.module("c8y.cockpit.map").controller("GeofenceEditCtrl",e)})();