'use strict';
import { getOperator, getODataFilterType } from '../api/meta-odata.js';
import { getLoginState } from '../../../fd-toolbox/auth/internal-login-states.js';
import { withUserIdProps } from '../../../fd-toolbox/types/with-user-id.js';
import { crudActions, oDataOperators } from '../../../fd-toolbox/enums/enums.js';
import { isNullOrUndefined, isEmptyNullOrUndefined } from '../../../fd-toolbox/functions/value-checking-functions.js';
import { hasCrudPermission, isBelowLevelCouldBeAllowedByUserId } from '../auth/permissions/permission-checker.js';
import { oDataComparisonTypes, oDataFilterTypes } from '../../../fd-toolbox/odata/odata-enums.js';

var __defProp=Object['defineProperty'],__name=(_0x898e74,_0x106299)=>__defProp(_0x898e74,'name',{'value':_0x106299,'configurable':!![]});function resourceFilterInitFilterInputs(_0xad7867,_0x34a817,_0x4ca33f,_0x30b6d5,_0x51dd04){let _0x501233={},_0x43f36c=Object['keys'](_0xad7867);if(_0x30b6d5)for(let _0x38dec1 of _0x30b6d5){_0x43f36c['push'](_0x38dec1['propertyName']);}for(let _0x132b33 of _0x43f36c){let _0x2d5302=_0x34a817['find'](_0x3a78ff=>_0x3a78ff['leftSide']===_0x132b33);setInitialFilters(_0x4ca33f,_0x501233,_0x132b33,_0x51dd04);if(_0x132b33===withUserIdProps['userId']&&resourceFilterShouldSetAndDisableUserIdFilter(_0x4ca33f))_0x501233[_0x132b33]=getUserIdFilter();else _0x2d5302&&(_0x51dd04?.['find'](_0x399359=>_0x399359['name']===_0x132b33)?_0x501233[_0x132b33]={'filter':{'leftSide':_0x501233[_0x132b33]['filter']['leftSide'],'rightSide':_0x2d5302['rightSide'],'type':_0x2d5302['type'],'comparisonType':_0x2d5302['comparisonType']}}:_0x501233[_0x132b33]={'filter':_0x2d5302});}return _0x501233;}__name(resourceFilterInitFilterInputs,'resourceFilterInitFilterInputs');function resourceFilterGetFilters(_0xb0058f,_0x5a5931,_0x19d640,_0x3b1d71){let _0x36c004={};if(_0xb0058f)for(let _0x54069f of Object['keys'](_0xb0058f)){let _0x31736b=_0x5a5931[_0x54069f],_0x4bb442=_0x19d640?.['find'](_0x326e32=>_0x326e32['propertyName']===_0x54069f);!_0x31736b&&_0x3b1d71&&_0x4bb442&&(_0x31736b=resourceFilterGetPropertyMetaByFilterName(_0x3b1d71,_0x4bb442));let _0x3d23af=resourceFilterTryGetFilter(_0xb0058f[_0x54069f]['filter'],_0x31736b,_0x4bb442);_0x3d23af&&(_0x36c004[_0x54069f]=_0x3d23af);}return _0x36c004;}__name(resourceFilterGetFilters,'resourceFilterGetFilters');function resourceFilterGetPropertyMetaByFilterName(_0x1a1ced,_0x46d0ae){let _0x2bb668=_0x1a1ced['find'](_0x359a1f=>_0x359a1f['resourceName']===_0x46d0ae['resourceName']);if(_0x2bb668?.['properties'][_0x46d0ae['propertyName']])return _0x2bb668['properties'][_0x46d0ae['propertyName']];return void(0x1*0x2228+-0x2263+0x3b);}__name(resourceFilterGetPropertyMetaByFilterName,'resourceFilterGetPropertyMetaByFilterName');function resourceFilterShouldSetAndDisableUserIdFilter(_0x5e6793){return !hasCrudPermission(crudActions['update'],_0x5e6793)&&isBelowLevelCouldBeAllowedByUserId(crudActions['view'],_0x5e6793);}__name(resourceFilterShouldSetAndDisableUserIdFilter,'resourceFilterShouldSetAndDisableUserIdFilter');function setInitialFilters(_0x14a442,_0x73a94a,_0x14aa5d,_0x30e68d){const _0x7f8765=_0x30e68d?.['find'](_0x1cfd4b=>_0x1cfd4b['name']===_0x14aa5d);if(_0x7f8765){const _0x40bf12=Object['values'](_0x14a442['properties'])['filter'](({relation:_0xf08b0b})=>_0xf08b0b?.['manyToManyInfo']?.['manyToManySecondPropertyName']===_0x7f8765['name'])['map'](({relation:_0x23e282})=>_0x23e282?.['manyToManyInfo']?.['manyToManyResourceName'])['find'](Boolean)??'';_0x73a94a[_0x14aa5d]={'filter':{'leftSide':_0x40bf12+'/'+_0x7f8765['name'],'rightSide':'','type':oDataFilterTypes['string'],'comparisonType':oDataComparisonTypes['equal']}};}else _0x73a94a[_0x14aa5d]={'filter':{'leftSide':'','rightSide':'','type':oDataFilterTypes['string'],'comparisonType':oDataComparisonTypes['equal']}};}__name(setInitialFilters,'setInitialFilters');function resourceFilterTryGetFilter(_0x1bd6c2,_0x1f6eca,_0x4d1993){if(isNullOrUndefined(_0x1bd6c2)||Array['isArray'](_0x1bd6c2['rightSide'])&&_0x1bd6c2['rightSide']['length']===0x1f43+0x14d8+-0x341b*0x1||isEmptyNullOrUndefined(_0x1bd6c2['rightSide']))return void(-0x18c0+0x3a2*0x1+-0x9f*-0x22);else {if(!isEmptyNullOrUndefined(_0x1bd6c2)&&_0x1bd6c2['rightSide'])return resourceFilterGetFilter(_0x1bd6c2,_0x4d1993,_0x1f6eca);}return void(-0xfe1+-0x1ed0+0x2eb1);}__name(resourceFilterTryGetFilter,'resourceFilterTryGetFilter');function resourceFilterGetFilter(_0x4bf4f6,_0x4d112a,_0x155513){let _0x4e9710={'leftSide':_0x4bf4f6['leftSide'],'rightSide':_0x4bf4f6['rightSide'],'operator':_0x4bf4f6['operator'],'type':_0x4bf4f6['type'],'comparisonType':oDataComparisonTypes['equal']};if(_0x4d112a)_0x4e9710['leftSide']=_0x4d112a['propertyName'],_0x4e9710['lambdaConfig']=_0x4d112a['oDataLambdaConfig'],_0x4e9710['type']=oDataFilterTypes['lambda'];else _0x155513&&(_0x4e9710['leftSide']=_0x4bf4f6['leftSide']===''?_0x155513['name']:_0x4bf4f6['leftSide'],_0x4e9710['operator']=isNullOrUndefined(_0x4bf4f6['operator'])?getOperator(_0x155513):_0x4bf4f6['operator'],_0x4e9710['type']=isNullOrUndefined(_0x4bf4f6['type'])?getODataFilterType(_0x155513):_0x4bf4f6['type']);return _0x4e9710;}__name(resourceFilterGetFilter,'resourceFilterGetFilter');function getUserIdFilter(){return {'filter':{'leftSide':withUserIdProps['userId'],'rightSide':[getLoginState()['userId']],'operator':oDataOperators['in'],'type':oDataFilterTypes['guid'],'comparisonType':oDataComparisonTypes['equal']}};}__name(getUserIdFilter,'getUserIdFilter');

export { resourceFilterGetFilters, resourceFilterGetPropertyMetaByFilterName, resourceFilterInitFilterInputs, resourceFilterShouldSetAndDisableUserIdFilter };
