(()=>{function e(t,i,a,o,n,r){var c=t.$id,s=this,p=[];function u(){_.uniq(p).forEach(function(e){return o.destroySubscription(c,e)}),p=[]}function d(e){var n,t=_.find(s.operations,_.pick(e,"id"));t?_.assign(t,e):(s.operations.push(e),t=e,(n=_.pick(t.c8y_JsonSchemaContext,["key","schemaId","path"]))&&(e=_.find(s.properties,function(e){var t=e.key;return _.isEqual({key:t,schemaId:e.schemaId,path:e.path},n)}))&&e.operationList.push(t))}function l(e){var e=0<arguments.length&&void 0!==e?e:null,t=s.path,n=s.schema,r=s.context,a=s.includeUndefined,n=i.getProperties(n,r,t,a),r=_.map(s.properties,"key"),t=_.map(n,"key"),a=_.difference(t,r).length||_.difference(r,t).length,r=!!(e&&e.path&&e.path.currentValue&&e.path.previousValue)&&e.path.previousValue!==e.path.currentValue;(a||r)&&(s.properties=i.sortProperties(n),s.showSave=i.showSave(s.properties)),s.propertyContainsBasicOperations=_.find(s.properties,function(e){return"operations"===_.get(e,"key")}),s.mutatedProperties=_.filter(s.properties,function(e){return"operations"!==_.get(e,"key")})}function h(e,n,t){var r=s.context,a=s.schema;return i.createOperation(e,n,t,r,a).then(function(e){var t=e.created,e=e.completed;return i.alertOperationCreateSuccess(t,n),i.alertOperationComplete(e),t})}function f(){t.MainForm.$setPristine();var e=r("Object updated.");n.success(e)}_.assign(s,{$onChanges:function(e){{var t;l(e),e.context&&(t=_.get(e.context,"currentValue.id"),(e=>{var t=_.get(e,"previousValue.id"),e=_.get(e,"currentValue.id");t!==e&&(s.operations=[],i.listPendingOperations(e).then(function(e){return _.forEach(e,d)}))})(e.context),(e=>{var t,n,r;u(),e&&(n=o.realtimeActions(),t=n.UPDATE,n=n.CREATE,r="/operations/".concat(e),e="/managedobjects/".concat(e),o.addListener(c,r,t,function(e,t){return d(t)}),o.addListener(c,r,n,function(e,t){return d(t)}),o.addListener(c,e,t,function(e,t){s.context=a.updateManagedObject(s.context,t),l()}),o.start(c,r),o.start(c,e),p=p.concat([r,e]))})(t))}},$onDestroy:function(){u()},operations:[],propertyContainsBasicOperations:{},createOperation:h,save:function(){var e=_.pick(s.context,["id",s.path]);s.saving=!0,a.update(e).then(f).finally(function(){s.saving=!1})},execute:function(e,t){var e=s.propertyContainsBasicOperations.operations[e],n=_.pick(s.propertyContainsBasicOperations,["path","schemaId","key"]);h(JSON.parse(i.replaceOperationTemplatePlaceholders(e.template,s.context,n,t)),e.name,n)},getIcon:function(e){var t="edit";switch(e){case 0:case 1:t="show-property";break;case 2:t="plus-circle";break;case 3:t="delete";break;default:t="edit"}return t}})}e.$inject=["$scope","c8yGenericUi","c8yInventory","c8yRealtime","c8yAlert","gettext"],angular.module("c8y.genericUi").component("c8yGenericUiInventory",{templateUrl:":::PLUGIN_PATH:::/generic-ui-inventory.html",controllerAs:"vm",controller:e,bindings:{path:"<",schema:"<",context:"<",includeUndefined:"<",title:"<",onlyBasicOperations:"<"}})})();