'use strict';
import { getFlagString } from '../../../fd-toolbox/collections/internal-enums.js';
import { englishLanguageCode, emptyUuid } from '../../../fd-toolbox/constants/constants.js';
import { isGuid, isDateTime, isDateOnly, isPhoneNumber, isCurrency, isEnum, isFlagsEnum, isFormattedNumber } from '../core/property-types.js';
import { getResourceDescriptionValue } from '../core/resource-description/resource-description.js';
import { getPropertyValueFromArray, getOptionalPropertyValue } from '../../../fd-toolbox/objects/property-value.js';
import { isDate, isString, isNumber, isArray, isObject } from '../../../fd-toolbox/types/ensure-type.js';
import { fetchResourceMeta } from '../meta-providers.js';
import { fetchResource } from '../resource-providers.js';
import { formatDateTime, formatDateOnly } from '../../../fd-toolbox/dates/date-time.js';
import { getDefaultMaximumFractionDigits } from '../../../fd-toolbox/numbers/numbers.js';
import { propertyTypeFormats } from '../constants/property-type-formats.js';
import { currencyCodes } from '../../../fd-toolbox/constants/currency-constants.js';

var __defProp=Object['defineProperty'],__name=(_0x38df9f,_0x1a86b7)=>__defProp(_0x38df9f,'name',{'value':_0x1a86b7,'configurable':!![]});async function getUserFriendlyPropertyValue(_0x171c59,_0x109b0a,_0x25d33d){let _0x3e9928=Array['isArray'](_0x25d33d)?getPropertyValueFromArray(_0x25d33d,_0x109b0a):getOptionalPropertyValue(_0x25d33d,_0x109b0a);if(_0x109b0a in _0x171c59['properties']){const _0xd99fa1=_0x171c59['properties'][_0x109b0a];if(isDate(_0x3e9928))return formatDateValues(_0xd99fa1['type'],_0xd99fa1['typeFormat'],_0x3e9928);else {if(isString(_0x3e9928))return formatStringValues(_0xd99fa1['type'],_0xd99fa1['typeFormat'],_0x3e9928,_0xd99fa1['relation'],_0x25d33d);else {if(isNumber(_0x3e9928))return formatNumberValues(_0xd99fa1['type'],_0xd99fa1['typeFormat'],_0x3e9928,_0xd99fa1['enumerationDisplayName'],_0xd99fa1['enumerationValues']);else {if(isArray(_0x3e9928))return _0x3e9928['join'](',\x20');}}}}return _0x3e9928??'';}__name(getUserFriendlyPropertyValue,'getUserFriendlyPropertyValue');async function formatStringValues(_0x47d7ee,_0x5385a5,_0x128f18,_0x2bd998,_0x337ad6){let _0x5edcf3=_0x128f18;if(isGuid(_0x5385a5,_0x2bd998))_0x5edcf3=await getRelatedResourceDescriptionValue(_0x2bd998,_0x128f18,_0x337ad6);else {if(isDateTime(_0x47d7ee,_0x5385a5))_0x5edcf3=formatDateTime(_0x128f18);else {if(isDateOnly(_0x47d7ee,_0x5385a5))_0x5edcf3=formatDateOnly(_0x128f18);else {if(isPhoneNumber(_0x47d7ee,_0x5385a5))_0x5edcf3=formatPhoneNumber(_0x128f18);else isCurrency(_0x5385a5)&&(_0x5edcf3=formatCurrency(Number(_0x128f18)));}}}return _0x5edcf3;}__name(formatStringValues,'formatStringValues');function formatDateValues(_0xa68ab5,_0x4e8bd2,_0x5f268a){let _0x58f73a='';if(isDateTime(_0xa68ab5,_0x4e8bd2))_0x58f73a=formatDateTime(_0x5f268a);else isDateOnly(_0xa68ab5,_0x4e8bd2)&&(_0x58f73a=formatDateOnly(_0x5f268a));return _0x58f73a;}__name(formatDateValues,'formatDateValues');function formatNumberValues(_0x2b6eff,_0x40187c,_0x379fa2,_0x51e1c6,_0x5c7d46){let _0x537643=String(_0x379fa2);if(isEnum(_0x2b6eff,_0x40187c))_0x537643=getEnumPropertyValue(_0x51e1c6,_0x5c7d46,_0x379fa2);else {if(isFlagsEnum(_0x2b6eff,_0x40187c))_0x537643=getFlagsEnumPropertyValue(_0x51e1c6,_0x5c7d46,_0x379fa2);else {if(isFormattedNumber(_0x40187c))_0x537643=formatNumber(_0x379fa2);else isCurrency(_0x40187c)&&(_0x537643=formatCurrency(_0x379fa2));}}return _0x537643;}__name(formatNumberValues,'formatNumberValues');function getEnumPossibleValues(_0x529e86,_0x418e99){return new Map(_0x529e86?.['map']((_0x14e264,_0x210cbd)=>[_0x418e99[_0x210cbd],_0x14e264]));}__name(getEnumPossibleValues,'getEnumPossibleValues');function formatNumber(_0x4d4b07,_0x5539a2=englishLanguageCode){if(!_0x4d4b07&&_0x4d4b07!==0x26aa+0x66+0x2*-0x1388)return '';return _0x4d4b07['toLocaleString'](_0x5539a2);}__name(formatNumber,'formatNumber');function formatCurrency(_0x4fa53c){let _0x2575d1='';return (_0x4fa53c||_0x4fa53c===0x1c56+0xa77+0x58b*-0x7)&&(_0x2575d1=formatPrice(_0x4fa53c,0xcd3+-0x797+-0x53c)),_0x2575d1;}__name(formatCurrency,'formatCurrency');function formatPrice(_0xbfa482,_0x1fa910,_0xacf989,_0x1506eb=englishLanguageCode){return _0xbfa482['toLocaleString'](_0x1506eb,{'style':propertyTypeFormats['currency'],'currency':_0xacf989??currencyCodes['usd'],'maximumFractionDigits':_0x1fa910??getDefaultMaximumFractionDigits(_0xbfa482)});}__name(formatPrice,'formatPrice');async function getRelatedResourceDescriptionValue(_0x3f8472,_0x275fa3,_0x57f442){let _0x57599b='';if(_0x275fa3&&_0x275fa3!==emptyUuid){const _0x260f28=await fetchResourceMeta(_0x3f8472['relatedResourceName']);if(_0x260f28){const _0x3258ff=getExpandedResource(_0x3f8472,_0x57f442);isObject(_0x3258ff)?_0x57599b=await getResourceDescriptionValue(_0x260f28,_0x3258ff):_0x57599b=await getFetchedResourceDescriptionValue(_0x260f28,_0x275fa3);}}return _0x57599b;}__name(getRelatedResourceDescriptionValue,'getRelatedResourceDescriptionValue');function getExpandedResource(_0x5aeb56,_0x4057cf){return _0x4057cf&&_0x5aeb56['expandPropertyName']?getOptionalPropertyValue(_0x4057cf,_0x5aeb56['expandPropertyName']):void(-0x25df+-0x3*-0x625+0x1370);}__name(getExpandedResource,'getExpandedResource');async function getFetchedResourceDescriptionValue(_0x39454c,_0x13b8c0){let _0x1b9324='';const _0x3922a8=await fetchResource(_0x39454c,_0x13b8c0);return _0x3922a8&&(_0x1b9324=await getResourceDescriptionValue(_0x39454c,_0x3922a8)),_0x1b9324;}__name(getFetchedResourceDescriptionValue,'getFetchedResourceDescriptionValue');function getEnumPropertyValue(_0x3129af,_0x4a779c,_0x57e09c){const _0x205d8e=getEnumPossibleValues(_0x3129af,_0x4a779c);return _0x205d8e['get'](_0x57e09c);}__name(getEnumPropertyValue,'getEnumPropertyValue');function getFlagsEnumPropertyValue(_0x14812d,_0x40545b,_0x50dac1){const _0x39176e=getEnumPossibleValues(_0x14812d,_0x40545b);return getFlagString(_0x39176e,_0x50dac1??0x4*-0x60b+0x2651+-0xe25);}__name(getFlagsEnumPropertyValue,'getFlagsEnumPropertyValue');const phoneRegex=/^(\+\d{1,3} )?\(?(\d{1,3})\)?-? ?(\d{1,3})?-? ?(\d+)$/,stringToPhoneReplacement='$1($2)\x20$3-$4';function formatPhoneNumber(_0x443c75){let _0x55b0f5='';return _0x443c75&&(_0x55b0f5=_0x443c75['replace'](phoneRegex,stringToPhoneReplacement)),_0x55b0f5;}__name(formatPhoneNumber,'formatPhoneNumber');

export { formatCurrency, formatDateValues, formatNumber, formatNumberValues, formatPrice, formatStringValues, getEnumPossibleValues, getUserFriendlyPropertyValue };
