'use strict';
import { getResourceMeta } from './metas.js';
import { getPermissionCheckConfig } from './permission-check-config-provider.js';
import { hasPermission } from '../permission/permission-checker.js';
import { crudActions } from '../../../../fd-toolbox/enums/enums.js';
import { checkSupportedCrudActions } from './crud-actions.js';
import { setDefaultPropertyValueIfNoPermission } from './resource-provider-defaults.js';

var __defProp=Object['defineProperty'],__name=(_0x2a8246,_0x3f23fb)=>__defProp(_0x2a8246,'name',{'value':_0x3f23fb,'configurable':!![]});async function checkExpandsPropertiesForAccess(_0x7845a2,_0x8792e,_0x10e2e3,_0x4d2f27){for(const _0x3f20ed of _0x7845a2['expands']??[]){if(_0x8792e['properties'][_0x3f20ed]){const _0x217327=_0x8792e['properties'][_0x3f20ed]['relation']?.['relatedResourceName'];if(_0x217327){const _0x5bd2cb=await getResourceMeta(_0x217327);checkSupportedCrudActions(_0x5bd2cb,crudActions['view']);const _0x2a1253=getPermissionCheckConfig(_0x10e2e3,_0x5bd2cb),_0x51d758=_0x4d2f27[_0x3f20ed];if(_0x51d758){let _0x195a3e=[];_0x7845a2['selects']&&(_0x195a3e=_0x7845a2['selects']['filter'](_0x43cdaa=>_0x43cdaa['startsWith'](_0x3f20ed+'/'))['map'](_0x56e3f9=>_0x56e3f9['replace'](_0x3f20ed+'/',''))),await processExpandedDataWithPermissions(_0x2a1253,_0x5bd2cb,_0x51d758,_0x195a3e);}}}}}__name(checkExpandsPropertiesForAccess,'checkExpandsPropertiesForAccess');async function preventExpandsIfHasNoAccess(_0x4cda3f,_0x138b44,_0x1a2255,_0x2ca079){let _0x4fa3eb=_0x2ca079;for(const _0x5441cd of _0x4cda3f['expands']){const _0x4cad80=_0x1a2255['properties'][_0x5441cd]['relation']?.['relatedResourceName'];if(_0x4cad80){const _0x23541f=await getResourceMeta(_0x4cad80),_0x2a21a6=getPermissionCheckConfig(_0x138b44,_0x23541f,_0x2ca079),_0x52fc2e=await hasPermission(_0x2a21a6);!_0x52fc2e&&(_0x4fa3eb=void(-0xb8f*0x1+0x1a4d+-0x33*0x4a));}}return _0x4fa3eb;}__name(preventExpandsIfHasNoAccess,'preventExpandsIfHasNoAccess');async function processExpandedDataWithPermissions(_0x20a9ea,_0x13f0d6,_0x586ba3,_0x32f6ed){const _0x5af18f=Array['isArray'](_0x586ba3)?_0x586ba3:[_0x586ba3];for(const _0x2a60e2 of _0x5af18f){await setDefaultPropertyValueIfNoPermission(_0x20a9ea,_0x13f0d6,_0x2a60e2,_0x32f6ed);}}__name(processExpandedDataWithPermissions,'processExpandedDataWithPermissions');

export { checkExpandsPropertiesForAccess, preventExpandsIfHasNoAccess };
