'use strict';
import { getResourceDescriptionValue } from './resource-description.js';
import { resourceDescriptionCaseTypes } from './resource-description-case.js';
import { logErrorRaw } from '../../../../fd-toolbox/logging/loggers.js';
import { getUserFriendlyPropertyValue } from '../../services/property-values.js';
import { isString, isWithIndexer } from '../../../../fd-toolbox/types/ensure-type.js';
import { fetchResourceMeta } from '../../meta-providers.js';
import { getRelatedPropertyValue } from '../../components/related-resources/related-property.js';
import { wellKnownMetaProps } from '../../../../fd-toolbox-core/constants/meta-constants.js';

var __defProp=Object['defineProperty'],__name=(_0x5a2247,_0x32482d)=>__defProp(_0x5a2247,'name',{'value':_0x32482d,'configurable':!![]});async function getDefaultResourceDescription(_0x59719e,_0x4a2668){let _0x146e0a={'value':''};if(_0x59719e['manyToManyInfo']&&Array['isArray'](_0x4a2668)){const _0x38b764=await getManyToManyDescriptionPropertyValue(_0x59719e,_0x4a2668);_0x38b764&&(_0x146e0a['value']=_0x38b764);}else {if(_0x59719e['description']['resourceDescriptionProperty']){const _0x2ab9e2=await getUserFriendlyPropertyValue(_0x59719e,_0x59719e['description']['resourceDescriptionProperty'],_0x4a2668);_0x146e0a['value']=isString(_0x2ab9e2)?_0x2ab9e2:'';}}return _0x59719e['description']['useImage']&&isString(_0x4a2668[wellKnownMetaProps['imageUrl']])&&(_0x146e0a['imageUrl']=_0x4a2668[wellKnownMetaProps['imageUrl']]),_0x146e0a;}__name(getDefaultResourceDescription,'getDefaultResourceDescription');async function getBasedOnPropertyValueResourceDescription(_0x4f6e82,_0x1eb25a){let _0x485216=await getDefaultResourceDescription(_0x4f6e82,_0x1eb25a);if(!_0x485216['value']){const _0x1ce4f0=getDescriptionCase(_0x4f6e82['description'],_0x1eb25a);_0x1ce4f0?.['type']===resourceDescriptionCaseTypes['concat']&&(_0x485216=await getConcatResourceDescription(_0x1ce4f0,_0x1eb25a,_0x4f6e82));}return _0x485216;}__name(getBasedOnPropertyValueResourceDescription,'getBasedOnPropertyValueResourceDescription');async function getPropertyDisplayValue(_0x12124b,_0x1521b1,_0x2ebda8,_0x67fb5d){if(_0x12124b['relation']?.['expandPropertyName'])return getRelatedPropertyValue(_0x1521b1,_0x2ebda8,_0x67fb5d,_0x12124b);return getUserFriendlyPropertyValue(_0x1521b1,_0x67fb5d,_0x2ebda8);}__name(getPropertyDisplayValue,'getPropertyDisplayValue');async function getRelatedItemDisplayValue(_0x4cbdf7,_0x59f122){if(_0x59f122&&_0x4cbdf7['relation']){const _0x3a6aec=await fetchResourceMeta(_0x4cbdf7['relation']['relatedResourceName']);if(_0x3a6aec){const _0x336151=await getResourceDescriptionValue(_0x3a6aec,_0x59f122);return _0x336151;}}return _0x59f122['id'];}__name(getRelatedItemDisplayValue,'getRelatedItemDisplayValue');async function getManyToManyDescriptionPropertyValue(_0x29b48d,_0x2bfc6a){let _0x5184fc='';if(_0x29b48d['manyToManyInfo']){const _0x5841e9=Array['from'](new Set(Object['values'](_0x29b48d['properties'])['map'](_0x2af38f=>_0x2af38f['relation']?.['descriptionPropertyName'])['filter'](_0x244157=>_0x244157!==void(-0x998+-0x7c*-0xf+0x254))));for(const _0x28e5e7 of _0x5841e9){for(const _0x23cf29 of _0x2bfc6a){const _0x3374d3=_0x23cf29[_0x29b48d['manyToManyInfo']?.['secondExpandPropertyName']];if(isWithIndexer(_0x3374d3)){const _0x39c7f8=_0x3374d3[_0x28e5e7];_0x39c7f8&&(_0x5184fc+=_0x39c7f8+',\x20');}}}}return _0x5184fc['trim']()['slice'](-0x29b*-0x9+-0x16*0x1a8+0x1*0xcfd,-(-0x346+-0x641+0x4c4*0x2));}__name(getManyToManyDescriptionPropertyValue,'getManyToManyDescriptionPropertyValue');function getDescriptionCase(_0x40b185,_0x2e49be){const _0x1dbc6f=_0x2e49be[_0x40b185['propertyToCheck']],_0x48b440=_0x40b185['cases']?.['find'](_0x57d465=>_0x1dbc6f===_0x57d465['valueToMatch']);if(!_0x48b440)logErrorRaw(new Error('DescriptionCase\x20doesn\x27t\x20exist'));return _0x48b440;}__name(getDescriptionCase,'getDescriptionCase');async function getConcatResourceDescription(_0x359762,_0x361300,_0x2c0bdd){const _0x34bcf1=await getUserFriendlyPropertyValue(_0x2c0bdd,_0x359762['resourceDescriptionProperty'],_0x361300),_0x2290a4=await getUserFriendlyPropertyValue(_0x2c0bdd,_0x359762['additionalResourceDescriptionProperty'],_0x361300),_0x5c3292=_0x359762['connector']??'\x20',_0x1c5d3e=_0x34bcf1+'\x20'+_0x5c3292+'\x20'+_0x2290a4;return {'value':_0x1c5d3e};}__name(getConcatResourceDescription,'getConcatResourceDescription');

export { getBasedOnPropertyValueResourceDescription, getDefaultResourceDescription, getPropertyDisplayValue, getRelatedItemDisplayValue };
