'use strict';
import { promises } from 'fs';
import { dirname, relative } from 'path';
import _0x1c3e3a from 'node:path';
import { generatedPaths, folders, packagesPath } from '../../../base-repo/app-constants/project-paths.js';
import { fileSuffixes } from '../../../base-repo/constants/internal-extensions.js';
import { getRelativeFuncsPath } from '../../meta/server/resources/dynamic-properties.js';
import { npmPackages } from '../../../base-repo/constants/packages.js';
import { fileExtensionsWithoutDot } from '../../../base-repo/app-constants/internal-system-constants.js';

var __defProp=Object['defineProperty'],__name=(_0x37d5e0,_0x53f89b)=>__defProp(_0x37d5e0,'name',{'value':_0x53f89b,'configurable':!![]});async function generateHandlerMap(_0x3d58e3){const _0xf3acc2=_0x3d58e3?.['isCombined'],_0x48d19d=process['cwd'](),_0x2d8dae=dirname(generatedPaths['crudHandlerMap']),_0xa145fe={};let _0x3f73f0;_0xf3acc2?_0x3f73f0=[folders['nodeModules']]:_0x3f73f0=[folders['nodeModules'],packagesPath['packagesRanksters'],packagesPath['packagesTest']];const _0x268921=await findLocalHandlerFiles(_0x48d19d,_0x3f73f0);_0x268921['forEach'](_0x979bca=>{const _0x32bf65=getRelativeFuncsPath(_0x979bca);_0xa145fe[_0x32bf65]='()\x20=>\x0a\x20import(\x22'+getImportPath(_0x2d8dae,_0x979bca,fileExtensionsWithoutDot['ts'])+'\x22)';});if(_0xf3acc2){const _0x500845=_0x1c3e3a['join'](folders['nodeModules'],npmPackages['saasKit']),_0x23fbc7=await findPackageHandlerFiles(_0x500845);_0x23fbc7['forEach'](_0x1950cc=>{const _0x3cc327=getRelativeFuncsPath(_0x1950cc);if(!_0xa145fe[_0x3cc327]){const _0x29b3f8=getImportPath(_0x2d8dae,_0x1950cc,fileExtensionsWithoutDot['js']);_0xa145fe[_0x3cc327]='()\x20=>\x0a\x20import(\x22'+_0x29b3f8+'\x22)';}});}const _0x30d7b2=generateMapCode(_0xa145fe),_0x3ecc4a=generatedPaths['crudHandlerMap'];await promises['mkdir'](_0x2d8dae,{'recursive':!![]}),await promises['writeFile'](_0x3ecc4a,_0x30d7b2);}__name(generateHandlerMap,'generateHandlerMap');async function findLocalHandlerFiles(_0x3ac15c,_0x3b4aa2){let _0x6aaf80=[];const _0x5366ae=await promises['readdir'](_0x3ac15c,{'withFileTypes':!![]});for(const _0x174884 of _0x5366ae){const _0x2a5977=_0x3ac15c+'/'+_0x174884['name'];if(_0x174884['isDirectory']())!_0x3b4aa2['some'](_0x68eee0=>_0x2a5977['includes'](_0x68eee0))&&(_0x6aaf80=_0x6aaf80['concat'](await findLocalHandlerFiles(_0x2a5977,_0x3b4aa2)));else _0x174884['isFile']()&&_0x174884['name']['endsWith'](fileSuffixes['handlers'])&&_0x6aaf80['push'](_0x2a5977);}return _0x6aaf80;}__name(findLocalHandlerFiles,'findLocalHandlerFiles');function getImportPath(_0x5d531d,_0x3f7357,_0x539d6f){return relative(_0x5d531d,_0x3f7357)['replace'](/\\/g,'/')['replace'](new RegExp('\x5c.'+_0x539d6f+'$'),'');}__name(getImportPath,'getImportPath');function generateMapCode(_0x12b1be){const _0x1cc4c0=Object['entries'](_0x12b1be)['map'](([_0x4b4d99,_0x251f94])=>'\x22'+_0x4b4d99+'\x22:'+_0x251f94)['join'](',\x0a');return 'export\x20const\x20resourceHandlerDynamicImportMap:\x20Record<string,\x20()\x20=>\x20Promise<unknown>>\x20=\x20{\x0a'+_0x1cc4c0+',\x0a};';}__name(generateMapCode,'generateMapCode');async function findPackageHandlerFiles(_0x5ba49d){let _0x5ccdde=[];const _0x89ac11=await promises['readdir'](_0x5ba49d,{'withFileTypes':!![]});for(const _0x5ada23 of _0x89ac11){const _0x18765d=_0x5ba49d+'/'+_0x5ada23['name'];if(_0x5ada23['isDirectory']())_0x5ccdde=_0x5ccdde['concat'](await findPackageHandlerFiles(_0x18765d));else _0x5ada23['isFile']()&&_0x5ada23['name']['endsWith'](fileSuffixes['handlersJs'])&&_0x5ccdde['push'](_0x18765d);}return _0x5ccdde;}__name(findPackageHandlerFiles,'findPackageHandlerFiles');

export { findLocalHandlerFiles, generateHandlerMap, generateMapCode, getImportPath };
