'use strict';
import { crudActions, relationTypes, oDataOrderByDirections, tableSortDirections } from '../../../fd-toolbox/enums/enums.js';
import { fetchResources } from '../resource-providers.js';
import { fetchUiResourceMeta } from '../ui-meta-providers.js';
import { checkAndNotifyCrudPermissionLessRestrictive } from '../crud/permissions/crud-permission-checker.js';
import { saveComponentState } from '../state/base-state-functions.js';
import _0x5ca88f from 'lodash.debounce';
import { resourceListOnFilterChange } from './resource-lists.js';
import { isReadOnlyResource, isCreateOnlyResource } from './resource-list-checkers.js';
import { parseODataFilter } from '../../../fd-toolbox/odata/odata-formatting/odata-parsers.js';
import { getObjectValues } from '../../../fd-toolbox/lib/utils.js';
import { oDataQueryParams } from '../../../fd-toolbox/constants/odata-query-params.js';
import { oDataComparisonTypes, oDataFilterTypes } from '../../../fd-toolbox/odata/odata-enums.js';
import { metaQueryParams } from '../../../fd-toolbox/constants/meta-query-params.js';
import { getDefaultResourceListConfig } from './resource-list-configs.js';

var __defProp=Object['defineProperty'],__name=(_0xb81bba,_0x48035d)=>__defProp(_0xb81bba,'name',{'value':_0x48035d,'configurable':!![]});async function onInitResourceList(_0x308380,_0x153d63,_0x42e73f,_0x2f7824,_0xe83c0,_0x8dbd98,_0xebd12f,_0x5f0cba,_0x5a008c,_0x1cf5c6,_0x4d2c0f,_0x220307){_0x4d2c0f(()=>_0x2f7824['oDataConfig']??{});if(!_0x42e73f){const _0x1b99e0=_0x153d63[metaQueryParams['resource']];_0xe83c0(_0x1b99e0);}const _0x327bd7=_0x153d63[oDataQueryParams['filter']],_0x4afdd3=_0x2f7824['oDataConfig']?.['filters'],_0x5962df=[..._0x327bd7?parseODataFilter(_0x327bd7):[],..._0x4afdd3??[]];_0x8dbd98(_0x5962df);let _0x388ce0=_0x220307;_0x388ce0??=await fetchUiResourceMeta(_0x42e73f),_0xebd12f(_0x388ce0),_0x5f0cba(_0x388ce0['resourceMeta']),_0x1cf5c6(checkAndNotifyCrudPermissionLessRestrictive(crudActions['view'],_0x388ce0['resourceMeta'])),ensureRelations(_0x388ce0['resourceMeta'],_0x308380,_0x153d63,_0x8dbd98),_0x5a008c(isReadOnlyResource(_0x388ce0['resourceMeta']));}__name(onInitResourceList,'onInitResourceList');async function initResourceList(_0x33c2a8,_0x6b9bb3,_0x1cafdb,_0x388d97,_0x4c8cc7,_0x1f2a85,_0x10323c,_0x23eb59,_0x2d901f,_0x2822d5,_0x322ada,_0x59c482,_0x279eb7,_0x4d32bb,_0x3f7bc3,_0x5baf2a,_0x2c6e61,_0x4ac34d,_0x511b2a){if(!_0x4ac34d)_0x1f2a85([]);await onInitResourceList(_0x1cafdb,_0x10323c,_0x23eb59,_0x4c8cc7,_0x2d901f,_0x2822d5,_0x322ada,_0x59c482,_0x279eb7,_0x4d32bb,_0x3f7bc3,_0x511b2a),!_0x4ac34d&&!_0x2c6e61&&_0x388d97&&await setResources(_0x33c2a8,_0x6b9bb3,_0x1cafdb,_0x388d97['resourceMeta'],_0x1f2a85,_0x3f7bc3,_0x5baf2a);}__name(initResourceList,'initResourceList');async function onResourceListSort(_0x49ac97,_0x41d83a,_0x9b4a20,_0xbc63d5,_0x4d0546,_0x2f8ad3,_0x345e45,_0xae83be,_0x1d6316,_0x6c49e4,_0x280063,_0x36a737){const _0x4480dc={..._0x9b4a20,'tableSort':_0x41d83a,'resourceName':_0x345e45['resourceName']};_0xbc63d5(_0x4480dc),!_0x41d83a['isLocalSort']&&await setResources(_0x4480dc,_0x4d0546,_0x2f8ad3,_0x345e45,_0xae83be,_0x1d6316,_0x6c49e4,_0x280063,_0x36a737),saveComponentState(_0x49ac97,_0x4480dc);}__name(onResourceListSort,'onResourceListSort');const setResources=_0x5ca88f(setResourceListResourcesBeforeDebounce,0x6a*-0x2+-0x18d*0x13+0x91*0x3b);async function setResourceListResourcesBeforeDebounce(_0x2d1d91,_0x525593,_0xacf8c7,_0x342e05,_0x4adbe4,_0x727e42,_0x5c6185,_0x48d0b5,_0x4b4c21,_0x394340){if(isCreateOnlyResource(_0x342e05))return;if(_0x48d0b5&&_0x4b4c21)_0x4adbe4(_0x48d0b5),setResourceListOrderByBasedOnTableSort(_0x2d1d91,_0x525593);else {const _0x25bb82={..._0x525593};let _0x57b16b;if(_0x5c6185){const _0x1ae59c=_0x5c6185['getFilters']();_0x57b16b=[...getObjectValues(_0x1ae59c)],_0x25bb82['filters']=_0x57b16b,resourceListOnFilterChange(_0x57b16b,_0x342e05['resourceName']);}else _0x57b16b=[..._0xacf8c7],_0x25bb82['filters']=_0x57b16b;_0x727e42(_0x25bb82),setResourceListOrderByBasedOnTableSort(_0x2d1d91,_0x25bb82);try{const _0x429cab=await fetchResources(_0x342e05['resourceName'],_0x25bb82);_0x4adbe4(_0x429cab??[]);}finally{_0x394340?.(![]);}}}__name(setResourceListResourcesBeforeDebounce,'setResourceListResourcesBeforeDebounce');function configureResourceInfo(_0x2411b8,_0x60a3ce,_0x1ccbe6,_0x28be46,_0x113555,_0x2f9f7c){_0x2411b8(_0x2f9f7c??[]),_0x60a3ce(_0x113555),_0x1ccbe6(_0x28be46??getDefaultResourceListConfig(_0x113555));}__name(configureResourceInfo,'configureResourceInfo');function ensureRelations(_0x2bb332,_0x44d911,_0x32524f,_0x3dd40d){if(_0x44d911&&Object['keys'](_0x44d911)['length']>0x3b*-0x46+-0xf*0xa7+-0x52f*-0x5)return;for(const _0x8b6626 of Object['keys'](_0x32524f)){for(const _0x5ea8cc of getObjectValues(_0x2bb332['properties'])){_0x5ea8cc['relation']&&_0x5ea8cc['relation']['type']===relationTypes['manyToOne']&&_0x5ea8cc['name']===_0x8b6626&&_0x3dd40d([..._0x44d911,{'leftSide':_0x5ea8cc['name'],'rightSide':[_0x32524f[_0x8b6626]],'type':oDataFilterTypes['guid'],'comparisonType':oDataComparisonTypes['equal']}]);}}}__name(ensureRelations,'ensureRelations');function setResourceListOrderByBasedOnTableSort(_0x401a41,_0x4e2446){_0x401a41['tableSort']&&!_0x401a41['tableSort']['isLocalSort']&&_0x401a41['tableSort']['columnName']?_0x4e2446['orderBys']=[{'propertyName':_0x401a41['tableSort']['columnName'],'direction':_0x401a41['tableSort']['direction']===tableSortDirections['desc']?oDataOrderByDirections['desc']:oDataOrderByDirections['asc']}]:_0x4e2446['orderBys']=void(-0x8ed*0x2+0x18e5+0x1*-0x70b);}__name(setResourceListOrderByBasedOnTableSort,'setResourceListOrderByBasedOnTableSort');

export { configureResourceInfo, initResourceList, onInitResourceList, onResourceListSort, setResourceListResourcesBeforeDebounce, setResources };
