function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function ownKeys(t,e){var n,r=Object.keys(t);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(t),e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)),r}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(n),!0).forEach(function(e){_defineProperty(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function _defineProperty(e,t,n){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _toPropertyKey(e){e=_toPrimitive(e,"string");return"symbol"==_typeof(e)?e:e+""}function _toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0===n)return("string"===t?String:Number)(e);n=n.call(e,t||"default");if("object"!=_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}(()=>{function e(n,o,i,u,c,a){var t="c8y_DynamicGroup",r="c8y_IsDynamicGroup",f="c8y_UIDeviceColumnsMeta",y="c8y_UIDeviceFilterConfig",l="c8y_DeviceQueryString";return{spawnEmpty:function(){return _defineProperty({type:t},r,{})},createWithUI:function(e){var t=e.columns,n=e.columnsConfig,r=e.configurableColumns;return i({templateUrl:":::PLUGIN_PATH:::/ui/views/addDynamicGroupModal.html",controller:"addDynamicGroupModalController",resolve:{columns:function(){return _.cloneDeep(t)},columnsConfig:function(){return _.cloneDeep(n)},configurableColumns:function(){return _.cloneDeep(r)}}})},create:function(e){var t=e.dynamicGroup,n=e.columns,r=e.columnsConfig,e=e.configurableColumns,t=_objectSpread(_objectSpread({},t),{},_defineProperty(_defineProperty(_defineProperty({},y,r),l,c.buildQuery(a.getQuery(n,r))),f,_.map(e,"meta")));return u.create(t).then(o.getResData)},getGroupList:function(){return u.list({fragmentType:r})},getGroupItems:s,getConfigurableColumnsMeta:function(e){return m(e).then(function(e){return _.get(e,f)})},saveConfigurableColumnsMeta:function(e,t){return u.save(_defineProperty({id:_.get(e,"id",e)},f,_.map(t,"meta")))},getColumnsConfig:function(e){return m(e).then(function(e){return _.get(e,y)})},saveColumnsConfig:function(e,t,n){var r=_defineProperty(_defineProperty({id:_.get(e,"id",e)},y,n),l,c.buildQuery(a.getQuery(t,n)));return m(r).then(function(e){e=_objectSpread(_objectSpread({},e),r);return u.save(e)}).then(o.getResData)},isDynamicGroup:d,isDynamicGroupForId:function(e){return _.isUndefined(e)?n.resolve(!1):u.detailCached(e).then(o.getResData).then(d)},addChildCountProperty:function(t,e){return n.all(_.map(t,function(t){return d(t)?p(t,e).then(function(e){return t.childCount=e,t}):n.resolve(t)})).then(function(e){return e.statistics=t.statistics,e.paging=t.paging,e})},getChildCount:p,getType:function(){return t},remove:function(e){return m(e).then(function(e){return u.remove(e)}).then(o.getResData)}};function p(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(d(e))return delete(t=_objectSpread({},t)).onlyRoots,s(e,_objectSpread(_objectSpread({},t),{},{pageSize:1,withTotalPages:!0,withChildren:!1,withParents:!1})).then(function(e){e=e.statistics.totalPages;return void 0===e?0:e});throw new Error("c8yDynamicGroups.fetchChildCount() can only be called with dynamic groups")}function s(e,t){return m(e).then(function(e){return u.list(_objectSpread({q:_.get(e,l)},t))})}function m(e){return d(e)?n.resolve(e):u.detail(e).then(o.getResData)}function d(e){return _.has(e,r)||_.get(e,"type")===t}}e.$inject=["$q","c8yBase","c8yModal","c8yInventory","c8yQueriesUtil","c8yFilteringSortingInventoryQueries"],angular.module("c8y.core").factory("c8yDynamicGroups",e)})();