(()=>{function e(a){e.$inject=["$rootScope","$timeout","$location","$routeParams","c8yUiUtil","gettextCatalog"];var o={};return{addTab:function(e,t){var n,r=/:[^/]+/g;{var i;o[e]||(i="".concat(e.replace(r,"(.+)"),"/([^/]+)$").replace(/\/+/g,"/"),o[e]=[],(n=o[e]).regexp=new RegExp(i),n.routeParams=_.map(e.match(r),function(e){return e.replace(/^:/,"")}))}null==t.path&&(t.path=a.appendSegment(e,t.name));_.isUndefined(t.priority)&&(t.priority=0);(n=o[e]).push(t)},sortTabsViews:g,removeForAll:m,$get:e};function s(n,r,e){return g(_.find(o,function(e){var t=e.regexp.test(n),e=!r||_.every(e.routeParams,function(e){return _.get(r,e)});return t&&e}),e)||null}function g(e,t){return _.orderBy(e,["priority",function(e){return t.getString(e.label||e.name)}],["desc","asc"])}function m(e){var t=_.flattenDeep(_.map(o)),n=_.find(t,{path:e});return n&&_.forEach(o,function(e){return!_.remove(e,function(e){return e===n}).length}),n}function e(e,a,r,o,c,t){var u,p="c8yTabs.update",h=[],f=e.$new(!0),n=_.memoize(function(e){return(e||"").split("/").map(function(t){var n;try{n=decodeURIComponent(t)}catch(e){n=t}return n}).join("/")}),d=_.partialRight(g,t);return e.$on("$routeChangeSuccess",function(){h.forEach(function(e){e.active=l(e.path)}),_.some(h,{active:!0,redirectedTo:!0})||(h.length=0,s(r.path(),o,t).forEach(i),a.cancel(u),u=a(function(){return f.$emit(p)}))}),_.assign(f,{EVENT_UPDATE:p,routeTabs:h,sort:d,removeForAll:m,getTabsByURL:function(e){return s(e,o,t)},get:function(e){return s(e,o,t)},addTab:function(e){i(e),(()=>{var e=r.path(),t=h.filter(function(e){return!1!==e.show}),n=_.maxBy(t,"priority"),e=_.find(t,{path:e});(t=_.find(t,"redirectedTo"))&&e!==n&&(e=n.path,r.replace(),r.path(e),t.redirectedTo=!1,n.redirectedTo=!0)})()}});function i(e){var t,n,r,i;_.some(h,{path:e.path})?(i=e,n=_.find(h,{path:i.path}),i=_.pick(i,["name","icon","priority","redirectedTo","active"]),_.assign(n,i)):((t=_.cloneDeep(e)).originalPath=t.path,t.path=(n=t.path,_.reduce(o,function(e,t,n){var r,n=new RegExp(":".concat(n),"g");try{r=encodeURIComponent(t)}catch(e){r=t}return e.replace(n,r)},n)),t.active=l(t.path),t.path===f.redirectedViewPath&&(t.redirectedTo=!0,f.redirectedViewPath=null),t.checkingVisibility=c.configureVisibility(t,"show",!1).then((r=e,function(e){e=e.show;r.show=e})).then(function(){return t}),h.push(t),i=d(h),h.length=0,i.forEach(function(e){return h.push(e)}),a.cancel(u),u=a(function(){return f.$emit(p)}))}function l(e){return new RegExp("^".concat(n(e))).test(r.path())}}}e.$inject=["c8yPathUtils"],angular.module("c8y.ui").provider("c8yTabs",e)})();