angular.module("c8y.ui").directive("c8yCodeEditor",function(){return{restrict:"A",require:"ngModel",link:function(r,t,n,e){(n=n.c8yCodeEditor)&&"json"===n.toLowerCase()&&(e.$parsers.push(function(r){try{var t=JSON.parse(r);return e.$setValidity("json",!0),t}catch(r){return e.$setValidity("json",!1),null}}),e.$formatters.push(function(r){if(null===r)return e.$setValidity("json",!1),"";try{var t=JSON.stringify(r,null,"  ");return e.$setValidity("json",!0),t}catch(r){return e.$setValidity("json",!1),""}}),t.bind("blur",function(){var r;e.$valid&&(r=JSON.stringify(e.$modelValue,null,"  "),e.$viewValue=r,e.$render())})),t.css({fontFamily:"monospace"})}}});