'use strict';
import { propertyTypes } from '../../properties/property-type.js';
import { getInternalResourceMeta } from '../resources/internal-resource-meta.js';
import { isListRelationProperty, setRelation } from '../relations/relations.js';
import { isIdProperty, isResourceListProperty, isIdOnlyProperty } from '../props/property-names.js';
import { isPropertyRequired } from '../props/required-properties.js';
import { createError } from '../../../../fd-toolbox/errors/errors.js';
import { splitAndCapitalize } from '../../../../fd-toolbox/server/strings/strings.js';
import { propertyTypeFormats } from '../../constants/property-type-formats.js';
import { metaValidationMessages } from '../constants/meta-validation-messages.js';
import { isManyToOneRelation } from '../../relations/meta-relations.js';
import { isEmptyNullOrUndefined } from '../../../../fd-toolbox/functions/value-checking-functions.js';
import { isBaseResource } from '../entities/edit-base-resources.js';
import { baseResourceProps } from '../../../../fd-toolbox/base-resource/props/base-resource-props.js';
import { emptyUuid } from '../../../../fd-toolbox/constants/constants.js';
import { workspaceResourceProps } from '../../multitenancy/props/workspace-resource-props.js';
import { isEnum } from '../../core/property-types.js';
import { getInternalPropertyMeta } from '../props/property-meta-config-provider.js';
import { wellKnownUserProps } from '../../../../fd-toolbox/constants/common-user-fields.js';

var __defProp=Object['defineProperty'],__name=(_0x159be4,_0x421c19)=>__defProp(_0x159be4,'name',{'value':_0x421c19,'configurable':!![]});async function setBasePropertyTypeInfo(_0x1e97be,_0x2e8506){const _0x2d77fb=await getInternalResourceMeta(_0x2e8506['resourceName']),_0x1b1427=_0x2d77fb['properties'][_0x1e97be['name']];if(!_0x1b1427)throw createError(metaValidationMessages['propertyNotFound']['replace']('{0}',_0x1e97be['name']));await setPropertyType(_0x1b1427,_0x1e97be,_0x2e8506['resourceName']),_0x1e97be['required']=isPropertyRequired(_0x1b1427);const _0x2b8011=isListRelationProperty(_0x1e97be['name']);await setPropertyMeta(_0x1e97be,_0x2e8506,_0x2b8011,_0x1b1427);}__name(setBasePropertyTypeInfo,'setBasePropertyTypeInfo');async function setPropertyType(_0x557cb5,_0x5862c2,_0x24ae27){const _0x3c275f=_0x557cb5['type'];if(!_0x3c275f){_0x5862c2['typeFormat']='';return;}isBaseType(_0x3c275f)?handleBaseType(_0x557cb5,_0x5862c2):handleSpecialType(_0x557cb5,_0x5862c2),await checkMetaConfig(_0x5862c2,_0x24ae27);}__name(setPropertyType,'setPropertyType');const baseTypes=[propertyTypes['string'],propertyTypes['number'],propertyTypes['integer'],propertyTypes['boolean'],propertyTypes['array'],propertyTypes['object']];function isFilterDisplayable(_0x10fbe5,_0x4e4532){if(_0x4e4532['notFilterDisplayable']||_0x4e4532['notDisplayable'])return ![];return _0x10fbe5['isDisplayable'];}__name(isFilterDisplayable,'isFilterDisplayable');function isEditDisplayable(_0x321bc0,_0x18d6d9,_0x97d660){if(_0x97d660['notEditDisplayable']||_0x97d660['notDisplayable'])return ![];return isDisplayableDuringCreateOrEdit(_0x97d660,_0x18d6d9,_0x321bc0);}__name(isEditDisplayable,'isEditDisplayable');async function isListDisplayAdvisable(_0x59a417,_0x29c424){const _0x4b7cc0=await getInternalPropertyMeta(_0x29c424,_0x59a417['name']);let _0x3cf814;if(!_0x4b7cc0)throw createError(metaValidationMessages['propertyNotFound']['replace']('{0}',_0x59a417['name']));if(_0x4b7cc0['notListDisplayable']||_0x4b7cc0['notDisplayable']||_0x4b7cc0['outsideExcluded'])_0x3cf814=![];else isPropertyAlwaysVisibleInList(_0x59a417,_0x4b7cc0)?_0x3cf814=!![]:_0x3cf814=!((isIdProperty(_0x4b7cc0['name'])??![])||isResourceListProperty(_0x4b7cc0['name'])||_0x59a417['type']===propertyTypes['object']||isIdOnlyProperty(_0x4b7cc0['name']));return _0x3cf814;}__name(isListDisplayAdvisable,'isListDisplayAdvisable');function isDisplayableDuringCreateOrEdit(_0x193f91,_0x5c22be,_0x51d516){if(isEmptyNullOrUndefined(_0x193f91))return ![];const _0x3ea5fa=isBaseResource(_0x51d516)&&_0x5c22be['name']===baseResourceProps['modifiedDate'],_0x4d62a8=(_0x193f91['isNavigationProperty']&&isManyToOneRelation(_0x5c22be))??![],_0x42432e=_0x193f91['notDisplayable']??![],_0x2009fc=_0x193f91['notEditableFromOutside']??![];return !(_0x3ea5fa||_0x42432e||_0x4d62a8||_0x2009fc);}__name(isDisplayableDuringCreateOrEdit,'isDisplayableDuringCreateOrEdit');function setPropertyValue(_0x9c965a,_0x386a6e,_0x417314){if(!(_0x417314['name']in _0x9c965a))throw createError(metaValidationMessages['propertyNotFound']['replace']('{0}',_0x417314['name']));return _0x9c965a[_0x417314['name']]=_0x386a6e,_0x386a6e;}__name(setPropertyValue,'setPropertyValue');function setPropertyValueFromAnotherResource(_0x46f198,_0x5d19c1,_0x113996){const _0xd4a436=getPropertyValue(_0x5d19c1,_0x113996);if(_0x113996['name']===workspaceResourceProps['workspaceId']&&_0xd4a436===emptyUuid)return;setPropertyValue(_0x46f198,_0xd4a436,_0x113996);}__name(setPropertyValueFromAnotherResource,'setPropertyValueFromAnotherResource');function isPropertyExpandable(_0x447d80){return !!_0x447d80['relation']&&_0x447d80['relation']['isExpandProperty'];}__name(isPropertyExpandable,'isPropertyExpandable');function isBaseType(_0x196523){return baseTypes['includes'](_0x196523);}__name(isBaseType,'isBaseType');function handleBaseType(_0x4df367,_0x5173da){switch(_0x4df367['type']){case propertyTypes['string']:setStringType(_0x4df367,_0x5173da);break;case propertyTypes['number']:setNumberType(_0x4df367,_0x5173da);break;case propertyTypes['integer']:setIntegerType(_0x4df367,_0x5173da);break;case propertyTypes['boolean']:_0x5173da['type']=propertyTypes['boolean'];break;case propertyTypes['array']:_0x5173da['type']=propertyTypes['array'];break;case propertyTypes['object']:_0x5173da['type']=propertyTypes['object'];break;default:_0x5173da['typeFormat']='';break;}}__name(handleBaseType,'handleBaseType');function handleSpecialType(_0x489a99,_0x3db7a1){switch(_0x489a99['type']){case propertyTypes['date']:_0x3db7a1['type']=propertyTypes['string'],_0x3db7a1['typeFormat']=propertyTypeFormats['dateOnly'];break;case propertyTypes['time']:case propertyTypes['dateTime']:_0x3db7a1['type']=propertyTypes['string'],_0x3db7a1['typeFormat']=propertyTypeFormats['dateTime'];break;case propertyTypes['uuid']:setUuidType(_0x3db7a1);break;case propertyTypes['enum']:_0x3db7a1['type']=propertyTypes['string'];break;default:_0x3db7a1['typeFormat']='';break;}}__name(handleSpecialType,'handleSpecialType');function setStringType(_0xbef28d,_0x473b1d){_0x473b1d['type']=propertyTypes['string'];if(_0xbef28d['isBlobImage'])_0x473b1d['typeFormat']=propertyTypeFormats['blob'];else {if(_0xbef28d['fileUpload'])_0x473b1d['typeFormat']=propertyTypeFormats['binary'];else {if(_0xbef28d['markdown'])_0x473b1d['typeFormat']=propertyTypeFormats['markdown'];else {if(_0xbef28d['bigText'])_0x473b1d['typeFormat']=propertyTypeFormats['bigText'];else {if(_0xbef28d['phoneNumber'])_0x473b1d['typeFormat']=propertyTypeFormats['phoneNumber'];else {if(_0xbef28d['isUrl'])_0x473b1d['typeFormat']=propertyTypeFormats['url'];else {if(_0xbef28d['isEmail'])_0x473b1d['typeFormat']=propertyTypeFormats['email'];else {if(_0xbef28d['isRichText'])_0x473b1d['typeFormat']=propertyTypeFormats['richText'];else {if(isDefaultFormattedProperty(_0xbef28d['name'],wellKnownUserProps['phoneNumber'],_0xbef28d['preventDefault']))_0x473b1d['typeFormat']=propertyTypeFormats['phoneNumber'];else isDefaultFormattedProperty(_0xbef28d['name'],wellKnownUserProps['email'],_0xbef28d['preventDefault'])?_0x473b1d['typeFormat']=propertyTypeFormats['email']:_0x473b1d['typeFormat']='';}}}}}}}}}__name(setStringType,'setStringType');function isDefaultFormattedProperty(_0x37502b,_0x3ebe0d,_0x14a8dd){return !_0x14a8dd&&_0x37502b===_0x3ebe0d;}__name(isDefaultFormattedProperty,'isDefaultFormattedProperty');function setNumberType(_0x31b3fc,_0x173ad2){_0x173ad2['type']=propertyTypes['number'],_0x173ad2['typeFormat']=_0x31b3fc['isCurrency']?propertyTypeFormats['currency']:propertyTypeFormats['double'];}__name(setNumberType,'setNumberType');function setIntegerType(_0x435974,_0x55548c){_0x55548c['type']=propertyTypes['integer'],_0x55548c['typeFormat']=_0x435974['isCurrency']?propertyTypeFormats['currency']:propertyTypeFormats['int32'];}__name(setIntegerType,'setIntegerType');function setUuidType(_0x2525c4){_0x2525c4['type']=propertyTypes['string'],_0x2525c4['typeFormat']=propertyTypeFormats['uuid'];}__name(setUuidType,'setUuidType');function isPropertyAlwaysVisibleInList(_0x18b4a0,_0x2d66b5){const _0x156dd2=_0x18b4a0['relation']?.['expandForDescription']??![],_0x16880b=_0x18b4a0['relation']?.['isExpandProperty']??![],_0x251350=_0x2d66b5['notRelation']??![];return _0x156dd2&&(!_0x16880b||isResourceListProperty(_0x2d66b5['name']))||_0x251350;}__name(isPropertyAlwaysVisibleInList,'isPropertyAlwaysVisibleInList');async function checkMetaConfig(_0x26b894,_0x72bc37){const _0x12ba8c=await getInternalResourceMeta(_0x72bc37),_0xdb0eb3=_0x12ba8c['properties'][_0x26b894['name']];if(_0xdb0eb3['markdown'])_0x26b894['type']=propertyTypes['string'],_0x26b894['typeFormat']=propertyTypeFormats['markdown'];else {if(_0xdb0eb3['bigText'])_0x26b894['type']=propertyTypes['string'],_0x26b894['typeFormat']=propertyTypeFormats['bigText'];else _0xdb0eb3['enumerationValues']&&(_0x26b894['type']=propertyTypes['integer'],_0xdb0eb3['flagsEnum']?_0x26b894['typeFormat']=propertyTypeFormats['flagsEnum']:_0x26b894['typeFormat']=propertyTypeFormats['enum']);}}__name(checkMetaConfig,'checkMetaConfig');async function setPropertyMeta(_0x53aa28,_0xeb5876,_0x2e2102,_0x2f4619){setDisplayAndEditProperties(_0x53aa28,_0x2e2102,_0x2f4619),await setRelationAndEnumData(_0x53aa28,_0xeb5876,_0x2f4619),setRequiredProperties(_0x53aa28,_0x2f4619),setVisibilityProperties(_0x53aa28,_0x2f4619);}__name(setPropertyMeta,'setPropertyMeta');function setDisplayAndEditProperties(_0x179763,_0x29af4e,_0x5aae62){(_0x5aae62['notDisplayable']||_0x179763['type']===propertyTypes['object']&&!_0x29af4e)&&(_0x179763['isDisplayable']=![]),_0x179763['isOutsideEditable']=!_0x5aae62['notEditableFromOutside'],_0x5aae62['outsideExcluded']&&(_0x179763['isOutsideExcluded']=!![],_0x179763['isDisplayable']=![],_0x179763['isOutsideEditable']=![]);}__name(setDisplayAndEditProperties,'setDisplayAndEditProperties');async function setRelationAndEnumData(_0x725b68,_0x21d2a9,_0xe37446){if(!_0xe37446['notAResource'])await setRelation(_0x725b68,_0x21d2a9);isEnum(_0x725b68['type'],_0x725b68['typeFormat'])&&fillEnumerationData(_0x725b68,_0xe37446),_0x725b68['isListDisplayAdvisable']=await isListDisplayAdvisable(_0x725b68,_0x21d2a9['resourceName']);}__name(setRelationAndEnumData,'setRelationAndEnumData');function setRequiredProperties(_0xf85e34,_0x1d1d87){_0x1d1d87['requiredIfOtherArePresent']&&(_0xf85e34['requiredIfOtherArePresent']=_0x1d1d87['requiredIfOtherArePresent']);if(_0x1d1d87['requiredIfPropHasValue'])_0xf85e34['requiredIfPropHasValue']=_0x1d1d87['requiredIfPropHasValue'];}__name(setRequiredProperties,'setRequiredProperties');function setVisibilityProperties(_0x452c42,_0x32863f){_0x452c42['isViewVisible']=_0x32863f['isViewVisible'];}__name(setVisibilityProperties,'setVisibilityProperties');function fillEnumerationData(_0x440e1f,_0x3e0e22){_0x440e1f['enumerationValues']=_0x3e0e22['enumerationValues'],_0x440e1f['enumerationDisplayName']=_0x3e0e22['enumerationDisplayName']?.['map'](splitAndCapitalize);}__name(fillEnumerationData,'fillEnumerationData');function getPropertyValue(_0x62daf2,_0x566fe8){if(!(_0x566fe8['name']in _0x62daf2)&&_0x566fe8['required'])throw createError(metaValidationMessages['propertyNotFound']['replace']('{0}',_0x566fe8['name']));return _0x62daf2[_0x566fe8['name']];}__name(getPropertyValue,'getPropertyValue');

export { isDisplayableDuringCreateOrEdit, isEditDisplayable, isFilterDisplayable, isListDisplayAdvisable, isPropertyExpandable, setBasePropertyTypeInfo, setPropertyType, setPropertyValue, setPropertyValueFromAnotherResource };
