(()=>{function e(t,n,e,a,i,o,l,c,d){var r,s,u="c8y_Position",g="com_nsn_startups_vendme_fragments_GPSCoordinates",f={},m={icon:{type:"div",className:"normal-marker-icon",iconSize:[25,41],iconAnchor:[12.5,41]},focus:!0,draggable:!0};function v(e){d.getMap("locationId").then(function(e){setTimeout(function(){e.invalidateSize(!0)},500)}),r=e,t.location=A(e)||{};var n,e=t.location;b(t.location),s=_.clone(e),(n=e).lat&&n.lng&&$(e)}function b(e){var n=_.get(e,"lat"),t=_.get(e,"lng"),a=_.get(e,"alt");_.set(e,"lat",_.toNumber(n)),_.set(e,"lng",_.toNumber(t)),_.isUndefined(a)||_.set(e,"alt",_.toNumber(a))}function h(e){e&&($(e={lat:Number(e.lat),lng:Number(e.lng),zoom:17}),C(e),D(e))}function p(){var e;i.detailCached(((e=_.get(t,"child.config.device"))&&(m.draggable=!1),_.get(e,"id",n.deviceId))).then(function(e){return _.cloneDeep(e.data)}).then(v)}function $(e){_.assign(m,{lat:parseFloat(e.lat),lng:parseFloat(e.lng)}),D(f.main=m)}function C(e){_.assign(t.location,{lat:parseFloat(e.lat),lng:(e=parseFloat(e.lng),(e%=360)<-180?360+e:180<e?e-360:e)})}function y(e){return i.isVendme(e)?g:u}function A(e){return e[y(e)]}function D(e){e=e||m;_.assign(t.center,e)}_.assign(t,{settings:{},markers:f,mapDefaults:{scrollWheelZoom:!1},centerMap:D,center:{lat:0,lng:0,zoom:11},pattern:{latitude:/^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?)$/,longitude:/^[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$/,altitude:/^[-+]?(0|([1-9]\d*))(\.\d+)?$/},events:{markers:{enable:["dragend"]}},gotoAddress:function(e){a.geoCode(e).then(function(e){e=_.get(e,"data[0]");return e?(e.lng=e.lon,e):(l.warning(c("Address could not be found.")),null)}).then(h)},cancel:function(){t.noeditable=!t.noeditable,_.isEqual(t.location,s)||(t.location=_.clone(s))},save:function(){t.noeditable=!t.noeditable;var e={id:r.id},n=_.clone(A(r));delete n.address,e[y(r)]=n,b(e[y(r)]),i.save(e).then(function(){l.success(c("Location saved."))}).then(p)},realtimeChannel:"/managedobjects/".concat(void 0!==n.deviceId?n.deviceId:"*"),invalid:angular.bind(e,e.invalid,t),id:t.$id}),t.$on("leafletDirectiveMarker.locationId.dragend",function(e,n){C(n.model)}),t.$watch("child.config.device",p),o.addListener(t.$id,t.realtimeChannel,"".concat(t.$id,"-subscribed"),function(){p()}),o.addListener(t.$id,t.realtimeChannel,"CREATE",function(e,n){v(n)}),o.addListener(t.$id,t.realtimeChannel,"UPDATE",function(e,n){v(n)}),p()}e.$inject=["$scope","$routeParams","c8yBase","c8yGeo","c8yDevices","c8yRealtime","c8yAlert","gettext","leafletData"],angular.module("c8y.parts.location").controller("locationCtrl",e)})();