(()=>{function e(t,e,n,a,s,i,l,o,r,u,c,d,m,g){var h=_.isEmpty(c)?null:c,y="smartRuleForm",C={parent:null,mo:null,withChildren:{assets:!0,devices:!1},useMoAsContext:m},f={inProgres:!1};function p(e){u=e,t.ruleTemplate=u,t.rule.name||(t.rule.name=g.getString(t.ruleTemplate.description))}function v(e){t.enabledSources=_.sortBy(e,"name")}function S(e){t.disabledSources=_.sortBy(e,"name")}function x(){return M(),n.reject()}function b(){f.inProgress=!0}function M(){f.inProgress=!1}t.hasChildAssets=angular.bind(s,s.hasChildAssets),t.getChildAssetsCount=angular.bind(s,s.getChildAssetsCount),t.ruleTemplate=u,t.rule=c,t.save=function(){u.noTarget&&(C.withChildren={assets:!1,devices:!1}),n.when().then(b).then(angular.bind(o,o.save,c,u,C)).then(e.close,x).then(function(){var e,t={text:"",type:"success",allowHtml:!0};return!!(c&&c.c8y_Context&&c.c8y_Context.id&&c.c8y_Context.context)&&C.useMoAsContext?(e="#".concat(i.getContextPath(c.c8y_Context),"/smart_rules"),t.text=g.getString('Smart rule "{{name}}" saved but not visible here. <a href="{{link}}">Navigate to "{{nameOfMo}}"</a>.',{name:c.name,nameOfMo:C.mo.name,link:e}),t.detailedData=g.getString('Smart rule "{{name}}" saved under the selected asset "{{nameOfMo}}" of type "{{typeOfMo}}".',{name:c.name,typeOfMo:C.mo.type,nameOfMo:C.mo.name})):t.text=g.getString('Smart rule "{{name}}" saved.',{name:c.name}),l.add(t)}).then(M)},t.savingStatus=f,t.cancel=e.dismiss,t.invalid=angular.bind(a,a.invalid,t,y);var A,O=t.$watch(y,function(e){h&&e.$setDirty(),e&&O()});c&&c.id||(c=_.assign(o.getEmpty(),c||{})),t.rule=c,y=o.getRuleModalTitle(t.rule),t.title=y,u?p(u):r.getTemplateForRule(c).then(p),t.initialActivationCfg=C,y=_.get(c,"c8y_Context",d?{id:d}:i.getContext()),s.detail(y.id).then(a.getResData).then(function(e){C.mo=e,m||(C.searchOnlyChildAssetsOf=_.cloneDeep(e))}),c&&c.id&&(_.isEmpty(c.enabledSources)||(A=c.enabledSources.join(","),s.list({ids:A}).then(v)),_.isEmpty(c.disabledSources)||(A=c.disabledSources.join(","),s.list({ids:A}).then(S)))}e.$inject=["$scope","$uibModalInstance","$q","c8yBase","c8yInventory","c8yUiUtil","c8yAlert","smartRulesSvc","smartRuleTemplatesSvc","ruleTemplate","rule","contextMoId","isCloned","gettextCatalog"],angular.module("c8y.smartRules").controller("SmartRuleEditCtrl",e)})();