'use strict';
import { hasPermission } from '../../../../meta/server/permission/permission-checker.js';
import { tryGetFromCoreCache, setCoreCache } from '../../../../../fd-toolbox/server/cachings/core-cache.js';
import { getResourceMetas } from '../../../../meta/server/services/metas.js';
import { fdServerCacheKeys } from '../../../../../fd-toolbox/server/constants/fd-server-cache-keys.js';
import { getResourceListUrl } from '../../../../meta/services/meta-navigations.js';
import { getRelativeUrl } from '../../../../../fd-toolbox/routing/routers.js';
import { routes } from '../../../../../fd-toolbox/routing/routes.js';
import { demoManageUsers } from '../../../layout/sidebar/sidebar-constants.js';
import { demoResourceNames } from '../../../../../fd-toolbox/resources/demo-resource-names.js';
import { getBooleanEnvSetting } from '../../../../../fd-toolbox/infra/env-functions.js';
import { resourceNames } from '../../../../../fd-toolbox/resources/resource-names.js';
import { permissionNames } from '../../../../../fd-toolbox/constants/permission-names-constants.js';
import { crudActions } from '../../../../../fd-toolbox/enums/enums.js';
import { toolboxEnvSettingKeys } from '../../../../../fd-toolbox/infra/toolbox-env-setting-keys.js';

var __defProp=Object['defineProperty'],__name=(_0x17c031,_0x33de7a)=>__defProp(_0x17c031,'name',{'value':_0x33de7a,'configurable':!![]});async function getSidebarItems(_0x1816d4,_0x4d2e83){let _0x526b9d=await tryGetFromCoreCache(fdServerCacheKeys['sidebarItems'],_0x4d2e83);if(!_0x526b9d){const _0x5bd06b=getInitialSidebarItems(_0x1816d4);_0x526b9d=await createSidebarItems(_0x5bd06b,_0x4d2e83),await setCoreCache(fdServerCacheKeys['sidebarItems'],_0x526b9d,void(0x38e+0x8cd+-0x1*0xc5b),_0x4d2e83);}return _0x526b9d;}__name(getSidebarItems,'getSidebarItems');async function createSidebarItems(_0x4c167d,_0x32cf18){const {resourceLinks:_0x3ee267,sidebarLinks:_0x219e09,allowedResourceMetas:_0xe26b7a}=await prepareSidebarNavigation(_0x4c167d,_0x32cf18),_0x55f758=[];for(const _0x6583a2 of _0xe26b7a){_0x55f758['push']({'displayName':_0x6583a2['display']['preferPluralName']?_0x6583a2['display']['pluralName']:_0x6583a2['display']['displayName'],'link':_0x3ee267['get'](_0x6583a2['resourceName']),'icon':_0x6583a2['icon']});}for(const _0x126a33 of _0x219e09){_0x55f758['push']({'displayName':_0x126a33,'link':_0x3ee267['get'](_0x126a33)});}return _0x55f758;}__name(createSidebarItems,'createSidebarItems');async function prepareSidebarNavigation(_0x146c5a,_0x5e0a31){const _0xc28259=[],_0x4e9626=[],_0x14b5fc=await getResourceMetas(_0x146c5a);for(const _0x20a1ed of _0x146c5a){const _0x5dad53=_0x14b5fc[_0x20a1ed],_0x37c864=await hasPermission({'userId':_0x5e0a31,'throwIfNoPermission':![],'resourceName':_0x5dad53['resourceName'],'resourceMetaId':_0x5dad53['id'],'crudAction':crudActions['view']});if(_0x20a1ed===resourceNames['paymentPlan']&&_0x37c864){const _0xbc4b1b=await hasPermission({'userId':_0x5e0a31,'throwIfNoPermission':![],'resourceName':_0x5dad53['resourceName'],'resourceMetaId':_0x5dad53['id'],'crudAction':crudActions['update']});_0xbc4b1b&&(_0xc28259['push'](_0x20a1ed),_0x4e9626['push'](_0x5dad53));}else _0x37c864&&(_0xc28259['push'](_0x20a1ed),_0x4e9626['push'](_0x5dad53));}const _0x2edb79=new Map([..._0xc28259['map'](_0x5f37fb=>[_0x5f37fb,getRelativeUrl(getResourceListUrl(_0x5f37fb))]),[resourceNames['dashboard'],getRelativeUrl(routes['dashboard'])]]);await addEditUserResourceIfHasPermission(_0x5e0a31,_0x2edb79);const _0x5597c2=[..._0x2edb79['keys']()],_0x5c014c=_0x5597c2['filter'](_0x2ea459=>!_0xc28259['includes'](_0x2ea459));return {'resourceLinks':_0x2edb79,'sidebarLinks':_0x5c014c,'allowedResourceMetas':_0x4e9626};}__name(prepareSidebarNavigation,'prepareSidebarNavigation');async function addEditUserResourceIfHasPermission(_0x192230,_0x45a52f){const _0x523ab1=await hasPermission({'userId':_0x192230,'throwIfNoPermission':![],'permissionName':permissionNames['editOtherUser']});_0x523ab1&&_0x45a52f['set'](demoManageUsers,getRelativeUrl(routes['userList']));}__name(addEditUserResourceIfHasPermission,'addEditUserResourceIfHasPermission');function getInitialSidebarItems(_0xa72839){const _0x321a73=getBooleanEnvSetting(toolboxEnvSettingKeys['seedDemoResources']),_0x17e966=[..._0xa72839];return _0x321a73&&_0x17e966['push'](...demoResourceNames),_0x17e966;}__name(getInitialSidebarItems,'getInitialSidebarItems');

export { getSidebarItems };
