'use strict';
import { resourceFilterGetFilters } from '../../services/resource-filters.js';
import { getComponentState, saveComponentState } from '../../state/base-state-functions.js';
import { parseODataFilter } from '../../../../fd-toolbox/odata/odata-formatting/odata-parsers.js';
import { filterListOrientations } from '../filter-list-positions.js';
import { oDataOperators } from '../../../../fd-toolbox/enums/enums.js';
import { getObjectValues } from '../../../../fd-toolbox/lib/utils.js';
import { screenWidths } from '../../../../fd-toolbox/constants/screen-width-constants.js';
import { isPropertyFilterable } from '../../services/filter-components.js';
import { calculateSizing } from '../../../fd-component-toolbox/sizing/sizing.js';
import { jsBasicTypes } from '../../../../base-repo/constants/basic-types.js';

var __defProp=Object['defineProperty'],__name=(_0x46fd9c,_0xb5eb64)=>__defProp(_0x46fd9c,'name',{'value':_0xb5eb64,'configurable':!![]});function isDisplayable(_0x379b7a){return _0x379b7a?.['isDisplayable']&&_0x379b7a['isFilterDisplayable'];}__name(isDisplayable,'isDisplayable');function getFilters(_0x48162d,_0x20e9a5,_0x29a98e,_0x4536aa){return resourceFilterGetFilters(_0x48162d,_0x20e9a5,_0x29a98e?.['customFilters'],_0x4536aa);}__name(getFilters,'getFilters');function parseFilter(_0x190b43){if(!_0x190b43)return {};const _0x5bef05=Object['fromEntries'](parseODataFilter(_0x190b43)['map'](_0x208636=>[_0x208636['leftSide'],{'filter':_0x208636}]));return _0x5bef05;}__name(parseFilter,'parseFilter');function resetResourceFilterListState(_0x5e2270,_0x27d787,_0x59e445,_0x423762){_0x59e445(_0x251612=>_0x251612+(-0x98*0x30+0x191b+-0x6*-0x91));const _0x3ace84=getComponentState(_0x5e2270);_0x3ace84&&partiallyResetComponentState(_0x3ace84,_0x5e2270,_0x27d787,_0x423762);}__name(resetResourceFilterListState,'resetResourceFilterListState');function onResize(_0x15c064,_0x2d4321,_0x40c43c,_0x3fb6f6,_0x5a06ec,_0x2e35a9,_0x58d63e,_0x5f8e6d){if(!_0x5a06ec)return;if(_0x5f8e6d===filterListOrientations['vertical']){_0x15c064(_0x2d4321['length']),isElementShownLessThenFilteredKeys(_0x2d4321,_0x2d4321['length'],_0x40c43c,_0x5f8e6d);return;}const _0x11358e=_0x5a06ec['getBoundingClientRect']()['width'],_0x2f2b2e=typeof window!==jsBasicTypes['undefined']&&window['innerWidth']>=0x3*0x17b+-0x3*-0x215+0x10*-0x7b,_0x11b36b=_0x2f2b2e?_0x58d63e?.['getBoundingClientRect']()['width']??0x611+-0x1c35*-0x1+-0x2246:0x2*-0x1087+0x11d6+-0x8*-0x1e7,_0x162168=Math['max'](0x13*0x62+0x149e+-0x1be4,_0x11358e-_0x11b36b);let _0x65702f=-0x2*-0xdc4+0x204*0x6+-0x27a0;_0x3fb6f6&&(_0x65702f=calculateFilterCountFromWidths(_0x2d4321,_0x162168,_0x3fb6f6)),!_0x65702f&&_0x2e35a9&&(_0x65702f=calculateFilterCountFromDom(_0x2e35a9,_0x162168)),!_0x65702f&&(_0x65702f=getBreakpointDefaultCount()),_0x15c064(_0x65702f),isElementShownLessThenFilteredKeys(_0x2d4321,_0x65702f,_0x40c43c,_0x5f8e6d);}__name(onResize,'onResize');function setObserver(_0x197e3e,_0x361041,_0x4a9217,_0x4bab19,_0x1bcfcf,_0x2438e0,_0x2b24e4,_0x465333){const _0x294ff7=new ResizeObserver(()=>onResize(_0x197e3e,_0x361041,_0x4a9217,_0x4bab19,_0x1bcfcf,_0x2438e0,_0x2b24e4,_0x465333));return _0x1bcfcf&&_0x294ff7['observe'](_0x1bcfcf),()=>{_0x294ff7['disconnect']();};}__name(setObserver,'setObserver');function onStateChange(_0x3d173c,_0x8c0453,_0x31aecb,_0x2ef395,_0x4977f2){const _0x3cecdc={..._0x8c0453,[_0x3d173c]:{..._0x8c0453[_0x3d173c],'filter':_0x31aecb}};saveComponentState(_0x2ef395,_0x3cecdc),_0x4977f2(_0x3cecdc);}__name(onStateChange,'onStateChange');function partiallyResetComponentState(_0x27961c,_0x5906d9,_0x27cd7b,_0x5c4d81){if(!_0x27961c)return;getObjectValues(_0x27961c)['forEach'](_0xf6d44e=>{_0xf6d44e['filter']['rightSide']='',_0xf6d44e['filter']['operator']=oDataOperators['empty'];}),_0x27cd7b(_0x27961c),setTimeout(()=>{_0x5c4d81?.();},0x1414+-0x9*0x369+0xa9d),saveComponentState(_0x5906d9,_0x27961c);}__name(partiallyResetComponentState,'partiallyResetComponentState');function getFilteredKeys(_0x52b9f8,_0x43e1d1,_0x3289e1,_0x1521c3){return _0x52b9f8['filter'](_0x1e3107=>shouldIncludeKey(_0x1e3107,_0x43e1d1,_0x3289e1,_0x1521c3));}__name(getFilteredKeys,'getFilteredKeys');function createOnFilterRefCallback(_0x97a38){return _0x9ae378=>{const _0x25d2a4=__name(_0x2dff2c=>{_0x2dff2c?_0x97a38['current']['set'](_0x9ae378,_0x2dff2c):_0x97a38['current']['delete'](_0x9ae378);},'callback');return _0x25d2a4;};}__name(createOnFilterRefCallback,'createOnFilterRefCallback');function getFilterWidths(_0x4bd2e1){const _0x27f6a1={};return _0x4bd2e1['current']['forEach']((_0xd855bb,_0x3ce1fc)=>{_0x27f6a1[_0x3ce1fc]=_0xd855bb['getWidth']();}),_0x27f6a1;}__name(getFilterWidths,'getFilterWidths');function shouldIncludeKey(_0x330113,_0x2b3762,_0xf9251f,_0x3d7354){const _0x407361=isDisplayable(_0x2b3762[_0x330113]),_0x5c93f3=_0x3d7354?.['some'](_0x1c9a16=>_0x1c9a16['name']===_0x330113&&_0x1c9a16['isDisplayable'])??![],_0x332d34=_0xf9251f[_0x330113]&&isPropertyFilterable(_0xf9251f[_0x330113]);return _0x5c93f3||_0x332d34&&_0x407361;}__name(shouldIncludeKey,'shouldIncludeKey');function calculateFilterCountFromWidths(_0x371a0c,_0x1dbc11,_0x1bce2b){const _0x3af4c5=_0x1bce2b();if(!Object['keys'](_0x3af4c5)['length'])return 0x1*0xb69+-0x16bd+0xb54;const _0x3aab33=-0x1*-0x71f+-0x854+0x13d,_0x6dafaf=_0x371a0c['map'](_0x4a653d=>{const _0x5137b8=_0x3af4c5[_0x4a653d];return typeof _0x5137b8==='number'&&_0x5137b8>-0x1ed6+0x6f7*-0x5+0x1af*0x27?_0x5137b8:0x335+0x2*-0xff3+0x1d29;}),_0x3261f6=calculateSizing(_0x6dafaf,_0x1dbc11,{'gap':_0x3aab33});return _0x3261f6['count'];}__name(calculateFilterCountFromWidths,'calculateFilterCountFromWidths');function calculateFilterCountFromDom(_0x31a198,_0x48ee1f){try{const _0xd63401=Array['from'](_0x31a198['children']),_0x41ea2b=[];for(const _0x3fafbf of _0xd63401){if(_0x3fafbf instanceof HTMLElement){const _0x8c386=_0x3fafbf['getBoundingClientRect'](),_0x2e3125=window['getComputedStyle'](_0x3fafbf),_0xe9d03=parseFloat(_0x2e3125['marginLeft']||'0')||0x3d*-0x3a+-0x532+0x1304,_0xf84ceb=parseFloat(_0x2e3125['marginRight']||'0')||-0xd57*0x2+0xd92+0x4*0x347;_0x41ea2b['push'](_0x8c386['width']+_0xe9d03+_0xf84ceb);}}if(_0x41ea2b['length']>-0xe*-0x97+-0x949*-0x3+-0x241d){const _0x1867c9=calculateSizing(_0x41ea2b,_0x48ee1f);return _0x1867c9['count'];}}catch{}return -0x24e+-0x1*-0x1c1+-0x2f*-0x3;}__name(calculateFilterCountFromDom,'calculateFilterCountFromDom');function getBreakpointDefaultCount(){const _0x1d1f61=window['innerWidth']>screenWidths['md']&&window['innerWidth']<=screenWidths['lg'],_0x427834=window['innerWidth']>screenWidths['lg']&&window['innerWidth']<=screenWidths['xl'],_0x5c0aa9=window['innerWidth']>screenWidths['xl']&&window['innerWidth']<=screenWidths['xxl'],_0x3ae27e=window['innerWidth']>screenWidths['xxl'];let _0x2857cb=0xe*0x191+-0x1c59+0x89*0xc;if(_0x1d1f61)_0x2857cb=-0xf5e+-0x1086+0x1fe8;else {if(_0x427834)_0x2857cb=0x2094+-0x257c+0x61*0xd;else {if(_0x5c0aa9)_0x2857cb=0xdf*0x4+-0x108f*-0x2+-0x2494;else _0x3ae27e&&(_0x2857cb=-0x1764+0x12d2+0x49a);}}return _0x2857cb;}__name(getBreakpointDefaultCount,'getBreakpointDefaultCount');function isElementShownLessThenFilteredKeys(_0x42c9eb,_0x580b71,_0x25b01d,_0x4c2dc6){if(_0x42c9eb['length']<=_0x580b71)_0x25b01d(![]);else _0x4c2dc6===filterListOrientations['vertical']?_0x25b01d(![]):_0x25b01d(!![]);}__name(isElementShownLessThenFilteredKeys,'isElementShownLessThenFilteredKeys');

export { createOnFilterRefCallback, getFilterWidths, getFilteredKeys, getFilters, isDisplayable, onResize, onStateChange, parseFilter, partiallyResetComponentState, resetResourceFilterListState, setObserver };
