'use strict';
import { isObject } from '../../../fd-toolbox/types/ensure-type.js';
import { metaErrorMessages } from '../../meta/constants/meta-error-messages-constants.js';
import { createError } from '../../../fd-toolbox/errors/errors.js';
import { withIdProps } from '../../../fd-toolbox-core/types/resource-with-id.js';
import { getResourceMeta } from '../../meta/server/services/metas.js';
import { isNullOrUndefined } from '../../../fd-toolbox/functions/value-checking-functions.js';
import { isPromiseFulfilled } from '../../../fd-toolbox/lib/utils.js';
import { first } from '../../../fd-toolbox/server/collections/single-funcs.js';

var __defProp=Object['defineProperty'],__name=(_0x1fa186,_0x1f2553)=>__defProp(_0x1fa186,'name',{'value':_0x1f2553,'configurable':!![]});async function convertToCsv(_0x4dbd4b,_0x4b3bd0){if(!_0x4dbd4b['length'])throw createError(metaErrorMessages['exportItemsTypeError']);const _0x4ba1e2=await getResourceMeta(_0x4b3bd0),_0x14e77a=await formatData(_0x4dbd4b,_0x4ba1e2);if(_0x14e77a['length']===-0xd27+-0x279*-0x2+-0x1*-0x835)return '';const _0x4a2fc6=Object['keys'](first(_0x14e77a));let _0x7eee92=_0x4a2fc6['join'](',')+'\x0a';for(const _0x5b417d of _0x14e77a){const _0x16ffc5=_0x4a2fc6['map'](_0x16e286=>isNullOrUndefined(_0x5b417d[_0x16e286])?'':'\x22'+_0x5b417d[_0x16e286]+'\x22');_0x7eee92+=_0x16ffc5['join'](',')+'\x0a';}return _0x7eee92;}__name(convertToCsv,'convertToCsv');async function formatItemForExport(_0x48155,_0x548a2d){const _0x1bf9ce={'id':_0x48155['id']??''};for(const [_0x3e4794,_0x5442a7]of Object['entries'](_0x48155)){const _0x45baa1=_0x548a2d['properties'][_0x3e4794];if(_0x3e4794!==withIdProps['id']&&!isObject(_0x5442a7)&&_0x45baa1){const _0x476b0b=_0x45baa1['displayName'];_0x1bf9ce[_0x476b0b]=isNullOrUndefined(_0x5442a7)?'':_0x5442a7;}}return _0x1bf9ce;}__name(formatItemForExport,'formatItemForExport');async function formatData(_0x107dcf,_0x5e1fcb){const _0x433ca1=_0x107dcf['map'](_0x1480be=>formatItemForExport(_0x1480be,_0x5e1fcb)),_0x1636e9=await Promise['allSettled'](_0x433ca1);return _0x1636e9['filter'](isPromiseFulfilled)['map'](_0x246ef2=>_0x246ef2['value']);}__name(formatData,'formatData');

export { convertToCsv };
