'use strict';
import { crudActions } from '../../../../fd-toolbox/enums/enums.js';
import { tableElementSuffixes } from '../../../fd-component-toolbox/constants/table-element-suffixes.js';
import { getCellItem, isDefaultCell, isImageCell } from '../services/table-private-cell.js';
import { maxColumnNumberForFixedColumnWidth } from '../table-constants.js';
import { internalTableColumnTypes } from '../table-models.js';
import { getResourceDescriptionValue, getResourceDescriptionImageUrl } from '../../core/resource-description/resource-description.js';
import { getUserFriendlyPropertyValue, formatStringValues, formatNumberValues } from '../../services/property-values.js';
import { hasCrudPermission } from '../../auth/permissions/permission-checker.js';
import { imageNotFoundUrl } from '../../../../fd-toolbox/constants/public-files.js';
import { deleteResource } from '../../edit-resource/services/edit-resources.js';
import { wellKnownMetaProps } from '../../../../fd-toolbox-core/constants/meta-constants.js';
import { getOptionalPropertyValue } from '../../../../fd-toolbox/objects/property-value.js';
import { elementSuffixes } from '../../../../fd-toolbox/constants/element-suffixes.js';
import { isString, isNumber, isArray } from '../../../../fd-toolbox/types/ensure-type.js';
import { getResourceUrl } from '../../services/meta-navigations.js';
import { routes } from '../../../../fd-toolbox/routing/routes.js';
import { silentChangeUrl } from '../../../../fd-toolbox/routing/routers.js';
import { getElementId } from '../../../../fd-toolbox/html/element-ids.js';
import { jsBasicTypes } from '../../../../base-repo/constants/basic-types.js';
import { metaQueryParams } from '../../../../fd-toolbox/constants/meta-query-params.js';

var __defProp=Object['defineProperty'],__name=(_0x56ffc6,_0x558ffc)=>__defProp(_0x56ffc6,'name',{'value':_0x558ffc,'configurable':!![]});async function initBodyCell(_0x2ddaef,_0x1f7902,_0xcf4d46,_0x4575bf,_0x174257,_0x37aefd,_0x43ab18,_0x58d773,_0x59e24e,_0x265aa1,_0xff30e2,_0x5f34fa,_0x2d5c4a){_0x2ddaef(''),_0x1f7902(void(0x1fe7+-0x4*-0xbe+0x71*-0x4f));if(!_0x2d5c4a)return;if(!_0x2d5c4a['internalTableColumn']['cellTemplate']){let _0x321e7d=getCellItem(_0x2d5c4a['row']['item'],_0x2d5c4a['internalTableColumn']['expandInfo']);_0x2ddaef(await getBodyCellValueFromItem(_0x2d5c4a,_0x321e7d)),_0x1f7902(await getBodyCellImageFromItem(_0x2d5c4a,_0x321e7d));}_0xcf4d46(getCheckboxId(_0x2d5c4a)),_0x4575bf(getBodyCellViewButtonId(_0x2d5c4a['row']['item']['id'])),_0x174257(getBodyCellId(_0x2d5c4a)),_0x37aefd(getBodyCellIconId(_0x2d5c4a)),_0x43ab18(isDefaultCell(_0x2d5c4a)),_0x58d773(_0x2d5c4a['internalTableColumn']['type']===internalTableColumnTypes['checkMark']),_0x2d5c4a['tableInstance']['internalTableColumns']['length']>maxColumnNumberForFixedColumnWidth&&_0x59e24e(0x1e8b+-0x2*0xbf0+-0x225*0x3),_0x2d5c4a['tableInstance']['uiResourceMeta']?.['resourceMeta']&&(_0x265aa1(isAllowedCrudAction(_0x2d5c4a,crudActions['update'])),_0xff30e2(isAllowedCrudAction(_0x2d5c4a,crudActions['view'])),_0x5f34fa(isAllowedCrudAction(_0x2d5c4a,crudActions['delete'])));}__name(initBodyCell,'initBodyCell');function getBodyCellViewButtonId(_0x637646){return getElementId(tableElementSuffixes['viewButton'],void(0x26*-0xa3+0x482*0x1+0x13b0),_0x637646);}__name(getBodyCellViewButtonId,'getBodyCellViewButtonId');function getCheckboxId(_0x1bbea4){return getElementId(_0x1bbea4['tableInstance']['id']??'',tableElementSuffixes['checkbox'],_0x1bbea4['row']['index']);}__name(getCheckboxId,'getCheckboxId');function getBodyCellId(_0x49f94b){const _0x33ae07=getBodyCellIdParts(_0x49f94b);return getElementId(_0x33ae07['join'](''),elementSuffixes['cell'],_0x49f94b['row']['index']);}__name(getBodyCellId,'getBodyCellId');function getBodyCellIconId(_0x232e33){const _0x34129e=getBodyCellIdParts(_0x232e33);return getElementId(''+_0x34129e['join']('')+elementSuffixes['value']+tableElementSuffixes['icon'],elementSuffixes['cell'],_0x232e33['row']['index']);}__name(getBodyCellIconId,'getBodyCellIconId');function getBodyCellIdParts(_0x397ce1){let _0x48d9c2=_0x397ce1['internalTableColumn']['expandInfo']?_0x397ce1['internalTableColumn']['expandInfo']['expandPropertyName']:'',_0x19cc7c=_0x397ce1['internalTableColumn']['itemPropertyName'];return (_0x397ce1['internalTableColumn']['type']===internalTableColumnTypes['checkBox']||!_0x19cc7c)&&(_0x19cc7c=''),[_0x397ce1['tableInstance']['id']??'',_0x48d9c2,_0x19cc7c];}__name(getBodyCellIdParts,'getBodyCellIdParts');function isAllowedCrudAction(_0x44a5ab,_0x49d4fc){if(_0x44a5ab['tableInstance']['uiResourceMeta']?.['resourceMeta'])return (_0x44a5ab['internalTableColumn']['type']===internalTableColumnTypes['action']||_0x44a5ab['internalTableColumn']['type']===internalTableColumnTypes['customHeaderAction'])&&hasCrudPermission(_0x49d4fc,_0x44a5ab['tableInstance']['uiResourceMeta']['resourceMeta']);return ![];}__name(isAllowedCrudAction,'isAllowedCrudAction');async function getBodyCellValueFromItem(_0xc35108,_0x408e31){const _0x32e45c=_0xc35108['internalTableColumn'],_0x228e3f=_0xc35108['tableInstance'],_0xefe87b=_0x228e3f['uiResourceMeta']?.['resourceMeta'];let _0x4424b9='';if(_0x408e31){if(_0x32e45c['itemPropertyName'])!hasTableSpecificFormat(_0x32e45c)&&_0xefe87b?_0x4424b9=await getUserFriendlyPropertyValue(_0xefe87b,_0x32e45c['itemPropertyName'],_0x408e31):_0x4424b9=await getUserFriendlyPropertyValueForTable(_0x32e45c,_0x32e45c['itemPropertyName'],_0x408e31);else _0x32e45c['expandInfo']?.['resourceMeta']&&(_0x4424b9=await getResourceDescriptionValue(_0x32e45c['expandInfo']['resourceMeta'],_0x408e31));}return _0x4424b9;}__name(getBodyCellValueFromItem,'getBodyCellValueFromItem');async function getBodyCellImageFromItem(_0x39781a,_0x2a817d){const _0x36eb8a=_0x39781a['internalTableColumn'];if(_0x2a817d&&_0x36eb8a['expandInfo']?.['resourceMeta']){const _0x3b85ae=await getResourceDescriptionImageUrl(_0x36eb8a['expandInfo']['resourceMeta'],_0x2a817d);return _0x3b85ae;}return void(0x1ac0+-0x1925*-0x1+-0x33e5);}__name(getBodyCellImageFromItem,'getBodyCellImageFromItem');function getCellId(_0x2d3313,_0x4c65ab,_0x5612e9){return _0x4c65ab['tableInstance']['id']+_0x5612e9+_0x2d3313;}__name(getCellId,'getCellId');function getBodyCellResourceEditUrl(_0x39ca6e){return getEditUrl(_0x39ca6e['row']['item'],_0x39ca6e['tableInstance']['uiResourceMeta']['resourceMeta']);}__name(getBodyCellResourceEditUrl,'getBodyCellResourceEditUrl');async function getBodyImageCell(_0x3f1902){if(_0x3f1902&&!isImageCell(_0x3f1902))return imageNotFoundUrl;const _0x352e10=_0x3f1902['row']['item'][wellKnownMetaProps['imageUrl']];return typeof _0x352e10===jsBasicTypes['string']?new Promise(_0x4a87fe=>{const _0x4b3f05=new Image(),_0x4b194a=_0x352e10;_0x4b3f05['onload']=()=>_0x4a87fe(_0x4b194a),_0x4b3f05['onerror']=()=>_0x4a87fe(imageNotFoundUrl),_0x4b3f05['src']=_0x4b194a;}):imageNotFoundUrl;}__name(getBodyImageCell,'getBodyImageCell');function handleDialogResponse(_0x5d6eb3,_0xe87c00,_0x395b84){if(!_0x395b84?.['tableInstance']['uiResourceMeta']?.['resourceMeta'])return;_0x5d6eb3&&_0xe87c00&&deleteResource(_0x5d6eb3,_0x395b84['tableInstance']['uiResourceMeta']['resourceMeta']['resourceName'],{'id':_0x395b84['row']['item']['id']},_0xe87c00);}__name(handleDialogResponse,'handleDialogResponse');function updateSelectedRow(_0x2b91f6,_0xaf1ffa,_0x55e87c){const _0x4350b2=_0xaf1ffa['tableInstance']['tableRows']['map']((_0x3011f5,_0x3ff655)=>_0x3ff655===_0xaf1ffa['row']['index']?{..._0x3011f5,'selected':_0x2b91f6}:_0x3011f5);_0x55e87c?.(_0x4350b2);}__name(updateSelectedRow,'updateSelectedRow');function onViewClick(_0x2788ab){if(_0x2788ab){const _0x4b4eff=getResourceUrl(routes['view'],_0x2788ab['tableInstance']['uiResourceMeta']['resourceMeta']['resourceName'],_0x2788ab['row']['item']['id']);silentChangeUrl(_0x4b4eff);}}__name(onViewClick,'onViewClick');function hasTableSpecificFormat(_0x13b6c3){return _0x13b6c3['isDateAsTimeAgo'];}__name(hasTableSpecificFormat,'hasTableSpecificFormat');async function getUserFriendlyPropertyValueForTable(_0xde7f8d,_0x19a655,_0x57a664){const _0x1a3c38=getOptionalPropertyValue(_0x57a664,_0x19a655);if(_0xde7f8d['propertyType']&&_0xde7f8d['propertyTypeFormat']){if(isString(_0x1a3c38)&&_0xde7f8d)return formatStringValues(_0xde7f8d['propertyType'],_0xde7f8d['propertyTypeFormat'],_0x1a3c38);else {if(isNumber(_0x1a3c38))return formatNumberValues(_0xde7f8d['propertyType'],_0xde7f8d['propertyTypeFormat'],_0x1a3c38,_0xde7f8d['enumInfo']?.['enumerationDisplayName'],_0xde7f8d['enumInfo']?.['enumerationValues']);else {if(isArray(_0x1a3c38))return _0x1a3c38['join'](',\x20');}}}return String(_0x1a3c38);}__name(getUserFriendlyPropertyValueForTable,'getUserFriendlyPropertyValueForTable');function getEditUrl(_0x19e852,_0x4e8180){const _0x3422f1=new URLSearchParams();return _0x3422f1['set'](metaQueryParams['resource'],_0x4e8180['resourceName']),_0x3422f1['set'](metaQueryParams['id'],_0x19e852['id']),routes['edit']+'?'+_0x3422f1['toString']();}__name(getEditUrl,'getEditUrl');

export { getBodyCellId, getBodyCellImageFromItem, getBodyCellResourceEditUrl, getBodyCellValueFromItem, getBodyCellViewButtonId, getBodyImageCell, getCellId, getCheckboxId, handleDialogResponse, initBodyCell, isAllowedCrudAction, onViewClick, updateSelectedRow };
