(()=>{function e(n,r,i,e,a,c,o,u){var s,l="".concat("c8y_JsonSchema",".fragmentType"),f={};return{hasMatchingSchemas:function(t){return(s||p()).then(function(e){return _.some(e,function(e){return g(t,e).length})})},getMatchingSchemas:function(t){return(s||p()).then(function(e){return _.some(e,function(e){return g(t,e)})})},matchObjectWithSchemas:function(n,e){return _.reduce(e,function(e,t){return e.concat(g(n,t))},[])},listSchemas:p,replaceObjectPlaceholders:function(e,t,n){t=_.assign({managedObject:t,object:_.get(t,n)});return d(e,t)},replaceOperationTemplatePlaceholders:function(e,t,n,r){return d(e,_.assign({managedObject:t,object:_.get(t,n.path),property:n.key},r))},getProperties:function(e,t,n,r){var t=_.get(t,n),i=_.get(e,"id"),c=_.keys(t),t=a.getProperties(e);r||(t=_.filter(t,function(e){e=e.key;return _.includes(c,e)}));return _.map(t,function(e){return _.assign({operationList:[],schemaId:i,path:n},e)})},listPendingOperations:function(t){var e=c.status,e=[e.PENDING,e.EXECUTING];f[t]||(e=e.map(function(e){return{deviceId:t,status:e,pageSize:1e3}}).map(c.list),f[t]=n.all(e).then(_.flatten),f[t].finally(function(){return _.unset(f,t)}));return f[t]},createOperation:function(e,t,n,r){e=((e,t,n,r)=>((n=_.pick(n,["schemaId","path","key"])).operation=t,_.assign({c8y_JsonSchemaContext:n,deviceId:r.id,deviceName:r.name,description:t},e)))(e,t,n,r);return c.createWithNotifications(e)},sortProperties:function(e){return _.sortBy(e,[function(e){return-(e.priority||0)},function(e){return _.lowerCase(u.getString(e.title)||e.key)}])},alertOperationCreateSuccess:function(e,t){var n=o('"{{description | translate}}" will be executed.');e.then(function(){return i.success(u.getString(n,{description:t}))})},alertOperationComplete:function(e){var t=o('"{{description | translate}}" completed.'),n=o('"{{description | translate}}" failed.'),r=o('"{{description | translate}}" failed due to: "{{failureReason | translate}}".');e.then(function(e){e.status===c.status.SUCCESSFUL?i.success(u.getString(t,e)):e.failureReason?i.danger(u.getString(r,e),e):i.danger(u.getString(n,e))})},showSave:function(e){return _.some(e,function(e){return!_.keys(e).map(function(e){return e.toLowerCase()}).includes("readonly")&&"operations"!==e.type})}};function p(){return s=a.list().then(function(e){return _.filter(e,"appliesTo.GENERIC_UI")})}function g(e,t){var n,e=_.keys(e),r=_.get(t,l),i=[];return void 0!==r&&(n=new RegExp(r),i=e.filter(function(e){return n.test(e)}).map(function(e){return{key:e,schema:t}})),i}function d(e,t){e=e.replace(/\${([^}]+)}/g,"{{$1}}");return r(e)(t)}}e.$inject=["$q","$interpolate","c8yAlert","c8yInventory","c8yJsonSchemas","c8yDeviceControl","gettext","gettextCatalog"],angular.module("c8y.genericUi").factory("c8yGenericUi",e)})();