'use strict';
'use client';
import { apiDelete, apiGetWithOData } from '../../../fd-toolbox/api/api-client.js';
import { fetchUiResourceMeta } from '../ui-meta-providers.js';
import { createEditResourceForm, fillColumnData } from './services/edit-resource-components.js';
import { editResourceTwoColumnThreshold } from './edit-resources-constants.js';
import { editResourceLayoutTypes } from './edit-resource-constants.js';
import { shouldEditResourceShowCreateButton, shouldEditResourceShowSaveCancelButtons, getODataConfig, checkPermission, fetchAndSetResource, getStringifiedResourceRelations } from './services/edit-resources.js';
import { emptyUuid } from '../../../fd-toolbox/constants/constants.js';
import { getObjectValues } from '../../../fd-toolbox/lib/utils.js';
import { getLoginState } from '../../../fd-toolbox/auth/internal-login-states.js';
import { applyValueChanges } from './apply-value-changes.js';
import { wellKnownMetaProps } from '../../../fd-toolbox-core/constants/meta-constants.js';
import { metaQueryParams } from '../../../fd-toolbox/constants/meta-query-params.js';
import { apiPathNames } from '../../../fd-toolbox/api/api-path-names.js';
import { isUuidSet } from '../../../fd-toolbox/functions/value-checking-functions.js';
import { fetchResourceComments } from '../comment/comment-service.js';
import { fetchResourceMetas } from '../meta-providers.js';
import { getRelatedResourceMultiListItems } from '../components/related-resources/related-resources-component.js';
import { getMultiListItemType } from '../components/multi-list/multi-list-item-type.js';
import { getElementId } from '../../../fd-toolbox/html/element-ids.js';
import { EditResource } from './EditResource.js';
import { markdownSuffixes } from '../../../fd-toolbox/constants/element-suffixes.js';
import { isNonEmptyUuid, getEmptyUuid } from '../../../fd-toolbox/uuids.js';
import { browserTypeToSuffix } from '../browsers/browser-type.js';
import { hideProperties } from './config/internal-edit-resource-configs.js';
import { fetchResource, fetchResources } from '../resource-providers.js';
import { first } from '../../../fd-toolbox/server/collections/single-funcs.js';
import { getEditResourceHeaderExpandRelationButtonId, getEditResourceHeaderBackButtonId, getEditResourceHeaderSaveButtonId, getEditResourceHeaderCancelButtonId } from './EditResourceHeader.funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x406c3e,_0x20d137)=>__defProp(_0x406c3e,'name',{'value':_0x20d137,'configurable':!![]});async function onConfigChange(_0x40e746,_0x1fed6a,_0x303b50,_0xde72e3,_0x6eab3c,_0x3aedb8,_0x5cf9f0,_0x521384,_0x5af88e,_0xe4045c,_0x166ee1,_0x78a313,_0x7f786d,_0x3fd261,_0x473032,_0x4381da,_0x46dc87){const _0x9a119f=isUuidSet(_0x303b50['id']);return _0x40e746(_0x473032??!_0x9a119f),await loadResourceMetaAndResource(_0x1fed6a,!_0x9a119f,_0x303b50,_0xde72e3,_0x6eab3c,_0x3aedb8,_0x5cf9f0,_0x521384,_0x5af88e,_0xe4045c,_0x78a313,_0x7f786d,_0x3fd261,_0x4381da,_0x46dc87),_0x166ee1['value']++,()=>{_0x166ee1['value']--;};}__name(onConfigChange,'onConfigChange');async function initializeMultiListResources(_0x36ff80,_0x47202c,_0x43fe80,_0x5baae3,_0x4df418,_0xa44f6e,_0x3e49c0,_0x39bfda,_0x50dc24,_0x71a988,_0x5e452f,_0x398d3a){const _0xa5df13=await fetchUiResourceMeta(_0x36ff80);if(_0x39bfda){_0xa44f6e(_0xa5df13),_0x4df418({'id':emptyUuid}),_0x5baae3(_0x47202c),_0x3e49c0(!![]);return;}await initializeExistingResourceData(_0xa5df13,_0x398d3a,_0x36ff80,_0x47202c,_0x5baae3,_0x4df418,_0xa44f6e,_0x43fe80,_0x50dc24,_0x71a988,_0x5e452f),_0x3e49c0(!![]);}__name(initializeMultiListResources,'initializeMultiListResources');async function onCancelImageEdit(_0x3169a8,_0x13bc5b,_0x289e51){const _0x492685=_0x13bc5b[wellKnownMetaProps['imageUrl']],_0x43ed75=_0x3169a8['getValues'](wellKnownMetaProps['imageUrl']);if(_0x43ed75!==_0x492685&&_0x43ed75){const _0x7e2a3a=_0x43ed75;await apiDelete(apiPathNames['blob'],_0x7e2a3a['slice'](_0x7e2a3a['lastIndexOf']('/')+(0x15af+-0x956+-0xc58)));}_0x289e51?.();}__name(onCancelImageEdit,'onCancelImageEdit');async function onSaveResourceOnChange(_0x52a57e,_0x522575,_0x468ec3,_0x10ce08,_0x51a208,_0xa08f7d,_0x34caa9,_0x5cba24,_0x14e9e9,_0x5dccac,_0x31982b,_0x167786,_0x1123b0,_0x4a14bc,_0x284151,_0x122535,_0x2d9a5c){_0x31982b(_0x5f3f59=>_0x5f3f59+(0x1f81+0x3*0x161+-0x23a3)),_0x284151?.(),await onChangeSave(_0x52a57e,_0x522575,_0x468ec3,_0x10ce08,_0x51a208,_0xa08f7d,_0x34caa9,_0x5cba24,_0x14e9e9,_0x5dccac,_0x167786,_0x1123b0,_0x4a14bc),_0x31982b(_0x1afce7=>_0x1afce7-(0x20*-0x132+-0x1656+0x1*0x3c97)),_0x122535?.(),_0x2d9a5c?.();}__name(onSaveResourceOnChange,'onSaveResourceOnChange');function shouldShowSaveCancelButtons(_0x4edb73,_0x13b6d8){return _0x4edb73?shouldEditResourceShowCreateButton(_0x13b6d8['resourceMeta']):shouldEditResourceShowSaveCancelButtons(_0x13b6d8['resourceMeta']);}__name(shouldShowSaveCancelButtons,'shouldShowSaveCancelButtons');function determineColumnsCount(_0x2302fe,_0xf2d029){const _0x5358e0=getObjectValues(_0x2302fe['properties'])['filter'](_0x46bf1c=>_0x46bf1c['isEditDisplayable']);return _0xf2d029??(_0x5358e0['length']<editResourceTwoColumnThreshold?-0x1*0xdd3+-0x1*0x1961+0x2735:0x1499*-0x1+-0xf92+0x242d);}__name(determineColumnsCount,'determineColumnsCount');function getInitialEditResource(_0x570cc3,_0x5a6e07){return _0x570cc3??{'id':_0x5a6e07??emptyUuid};}__name(getInitialEditResource,'getInitialEditResource');function getSyncedEditResourceConfig(_0x2200da,_0x178080){if(!_0x178080)return _0x2200da;const _0x316356={..._0x2200da,..._0x178080,'propertyConfigs':_0x2200da['propertyConfigs']};if(_0x316356['multiListSections']===_0x2200da['multiListSections']&&_0x316356['tabsConfig']===_0x2200da['tabsConfig']&&_0x316356['additionalResources']===_0x2200da['additionalResources']&&_0x316356['hiddenRelatedResources']===_0x2200da['hiddenRelatedResources']&&_0x316356['customActionFields']===_0x2200da['customActionFields'])return _0x2200da;return _0x316356;}__name(getSyncedEditResourceConfig,'getSyncedEditResourceConfig');function getEditNavigationItems(_0x231a9a,_0x10191d){const _0x55a05c=_0x231a9a['map'](_0x1401df=>({'displayName':_0x1401df['displayName'],'targetHtmlElementId':_0x1401df['resourceId']})),_0x680505=(_0x10191d??[])['filter'](_0x5705f6=>_0x5705f6['hasPermission'])['map'](_0x502c58=>({'displayName':_0x502c58['displayName'],'targetHtmlElementId':_0x502c58['id']}));return [..._0x55a05c,..._0x680505];}__name(getEditNavigationItems,'getEditNavigationItems');async function processTabAdditionalResources(_0x1ee547,_0x34a881){const _0x472cab=_0x1ee547['additionalResources'],_0x134336=[];if(!_0x472cab)return _0x134336;const _0x51dd27=await fetchResourceMetas(_0x472cab);for(const _0x35471b of _0x472cab){const _0x3e5bd4=_0x51dd27[_0x35471b],_0x1f750c=getTabAdditionalResourceFilters(_0x1ee547),_0x38b028=await getTabRelatedResourceId(_0x3e5bd4,_0x1f750c);_0x134336['push']({'type':_0x34a881,'relatedResourceElementId':'multiListResource'+_0x3e5bd4['resourceName'],'resourceId':_0x38b028,'displayName':_0x3e5bd4['display']['displayName'],'resourceName':_0x3e5bd4['resourceName'],'propertyName':_0x3e5bd4['resourceName'],'filters':_0x1f750c});}return _0x134336;}__name(processTabAdditionalResources,'processTabAdditionalResources');function getEditResourceId(_0x35e948){return getElementId(EditResource['displayName'],void(0x229+-0x9*-0xac+-0xb*0xbf),_0x35e948);}__name(getEditResourceId,'getEditResourceId');function getEditResourcePropertyId(_0x2ee7f8,_0x138652,_0x5ddd33){return getElementId(_0x2ee7f8,_0x138652,_0x5ddd33);}__name(getEditResourcePropertyId,'getEditResourcePropertyId');function getEditResourceExpandRelationButtonId(_0x5092fd){return getEditResourceHeaderExpandRelationButtonId(_0x5092fd);}__name(getEditResourceExpandRelationButtonId,'getEditResourceExpandRelationButtonId');function getEditResourceBackButtonId(_0x2f48df){return getEditResourceHeaderBackButtonId(_0x2f48df);}__name(getEditResourceBackButtonId,'getEditResourceBackButtonId');function getEditResourceSaveButtonId(_0x126e59){return getEditResourceHeaderSaveButtonId(_0x126e59);}__name(getEditResourceSaveButtonId,'getEditResourceSaveButtonId');function getEditResourceCancelButtonId(_0x4c7876){return getEditResourceHeaderCancelButtonId(_0x4c7876);}__name(getEditResourceCancelButtonId,'getEditResourceCancelButtonId');function getEditResourceMarkdownPreviewButtonId(_0x589dcd,_0x20c560,_0x299c7d){return getEditResourcePropertyId(_0x589dcd,_0x20c560,_0x299c7d)+markdownSuffixes['previewIcon'];}__name(getEditResourceMarkdownPreviewButtonId,'getEditResourceMarkdownPreviewButtonId');function getEditResourceBrowserInputId(_0x18817e,_0x121716,_0x3c85fa,_0x5e8f56){return getElementId(_0x18817e+browserTypeToSuffix[_0x121716],_0x3c85fa,_0x5e8f56);}__name(getEditResourceBrowserInputId,'getEditResourceBrowserInputId');function checkLoadComplete(_0x229128,_0x45ebbb){_0x45ebbb?.(),_0x229128(!![]);}__name(checkLoadComplete,'checkLoadComplete');async function loadResource(_0x553167,_0xfa8b35,_0x93222c,_0x51a75b,_0x1afbbd,_0x269e6f,_0x5aa377,_0x2398fa,_0x4959dc,_0x367cf1,_0x2c15c6){const _0x40d2b1=_0x93222c['resourceMeta'];let _0x5508c7={..._0xfa8b35};if(!_0x553167&&!_0x2c15c6&&isUuidSet(_0xfa8b35['id'])){const _0x48ac35=await apiGetWithOData(_0x40d2b1['resourceName'],getODataConfig(_0x4959dc),_0xfa8b35['id']);_0x48ac35['data']&&(_0x5508c7=_0x48ac35['data'],_0x51a75b(_0x5508c7));}checkPermission(_0x553167,_0x93222c,_0xfa8b35),_0x269e6f(createEditResourceForm(_0x5aa377,_0x93222c,_0x5508c7,_0x2398fa,_0x553167)),_0x51a75b(_0x5508c7),_0x367cf1?.(),checkLoadComplete(_0x1afbbd,_0x367cf1);}__name(loadResource,'loadResource');async function onChangeSave(_0x1db601,_0x558189,_0x5979cb,_0x5e7ba2,_0x599671,_0x1a9397,_0x47de7f,_0xb7c604,_0x3014b2,_0x5b5614,_0x4b84db,_0x3465d6,_0x523aeb){if(_0x1a9397)return;const _0x56f2c2=await fetchAndSetResource(_0xb7c604,_0x47de7f,_0x599671['id'],_0x1a9397,_0x5b5614,_0x4b84db),_0x11f324=_0x56f2c2?.[wellKnownMetaProps['imageUrl']];_0x11f324?_0x5e7ba2['setValue'](wellKnownMetaProps['imageUrl'],_0x11f324):_0x5e7ba2['setValue'](wellKnownMetaProps['imageUrl'],''),await applyValueChanges(_0x1db601,_0x558189,_0x5979cb,_0x5e7ba2,_0x599671,_0x1a9397,_0x47de7f,_0x3014b2,_0x3465d6,_0x523aeb);}__name(onChangeSave,'onChangeSave');async function loadResourceMetaAndResource(_0x43cc34,_0x3b9ef0,_0x5caaa3,_0x6a29e9,_0x18bea5,_0x41b563,_0x3b85a2,_0x35dee0,_0x2cbf6c,_0x465c8f,_0x4084d2,_0xab6e8b,_0x3bbeba,_0x16b5c8,_0x15f636){fillColumnData(_0x41b563,_0x3b85a2,_0x3bbeba,_0x4084d2,_0x43cc34['customActionFields']),await loadResource(_0x3b9ef0,_0x5caaa3,_0x4084d2,_0x6a29e9,_0x18bea5,_0x35dee0,_0x2cbf6c,_0x465c8f,_0x43cc34,_0x16b5c8,_0x15f636),isUuidSet(_0x5caaa3['id'])?_0xab6e8b(await getStringifiedResourceRelations(_0x5caaa3['id'],_0x4084d2['resourceMeta'])):_0xab6e8b({});}__name(loadResourceMetaAndResource,'loadResourceMetaAndResource');async function initializeExistingResourceData(_0x2b7623,_0x1017c3,_0x4d3c30,_0x311cb4,_0x34b9ec,_0x4e226f,_0x11d57c,_0x48b928,_0x571c52,_0xc1b74,_0x41bd93){if(!_0x1017c3||_0x1017c3===emptyUuid)return;let _0x4d8dd7=[];const _0x2cad40=getMultiListItemType(_0x2b7623['resourceMeta']),_0x2158f0={..._0x311cb4},_0x2ac9d7=await fetchResource(_0x2b7623['resourceMeta'],_0x1017c3),_0x4a376d=await getRelatedResourceMultiListItems(_0x2b7623,_0x1017c3,_0x2cad40,_0x2ac9d7),_0x422619=await fetchResourceComments(_0x4d3c30,_0x1017c3);if(_0x4a376d)for(const _0x32ad3a of _0x4a376d){!_0x311cb4['hiddenRelatedResources']?.['includes'](_0x32ad3a['resourceName'])&&_0x4d8dd7['push'](_0x32ad3a);}const _0x337a11=await processTabAdditionalResources(_0x311cb4,_0x2cad40);_0x4d8dd7=[..._0x4d8dd7,..._0x337a11],isNonEmptyUuid(_0x1017c3)&&(hideProperties(_0x4d8dd7['map'](_0x382156=>_0x382156['propertyName']),_0x2158f0),_0x34b9ec(_0x2158f0)),_0x571c52(_0x422619),_0x48b928(_0x4d8dd7),_0x2ac9d7&&_0x4e226f(_0x2ac9d7),_0x11d57c(_0x2b7623),_0x41bd93({..._0xc1b74,'editResourceConfigs':{..._0xc1b74['editResourceConfigs'],[_0x4d3c30]:_0x2158f0}});}__name(initializeExistingResourceData,'initializeExistingResourceData');async function getTabRelatedResourceId(_0x2558db,_0x3c3365){let _0xd9337b=getEmptyUuid();const _0x38256b=await fetchResources(_0x2558db['resourceName'],{'filters':getObjectValues(_0x3c3365)});return _0x38256b&&_0x38256b['length']>-0x964+-0x17d*0x15+0x28a5&&(_0xd9337b=first(_0x38256b)['id']),_0xd9337b;}__name(getTabRelatedResourceId,'getTabRelatedResourceId');function getTabAdditionalResourceFilters(_0x2c90cf){let _0x25a8f7={};if(isNavigationLayoutType(_0x2c90cf)){const _0x5a5406=getLoginState(),_0x336c46=[{'leftSide':metaQueryParams['userId'],'rightSide':_0x5a5406['userId']}];_0x25a8f7=Object['fromEntries'](_0x336c46['map']((_0x4f7de0,_0x3b26d8)=>[_0x3b26d8,_0x4f7de0]));}return _0x25a8f7;}__name(getTabAdditionalResourceFilters,'getTabAdditionalResourceFilters');function isNavigationLayoutType(_0x7259e7){return _0x7259e7['tabsConfig']?.['layoutType']===editResourceLayoutTypes['navigation'];}__name(isNavigationLayoutType,'isNavigationLayoutType');

export { determineColumnsCount, getEditNavigationItems, getEditResourceBackButtonId, getEditResourceBrowserInputId, getEditResourceCancelButtonId, getEditResourceExpandRelationButtonId, getEditResourceId, getEditResourceMarkdownPreviewButtonId, getEditResourcePropertyId, getEditResourceSaveButtonId, getInitialEditResource, getSyncedEditResourceConfig, initializeMultiListResources, onCancelImageEdit, onConfigChange, onSaveResourceOnChange, processTabAdditionalResources, shouldShowSaveCancelButtons };
