import { clientApplicationTemplatesBlock } from '../client/support/files.mjs';
export const reactFiles = {
    client: [
        {
            condition: generator => !generator.embedded,
            ...clientApplicationTemplatesBlock(),
            templates: [
                'entities/_entityFolder_/_entityFile_-detail.tsx',
                'entities/_entityFolder_/_entityFile_.tsx',
                'entities/_entityFolder_/_entityFile_.reducer.ts',
                'entities/_entityFolder_/index.tsx',
            ],
        },
        {
            ...clientApplicationTemplatesBlock(),
            renameTo: data => `${data.clientSrcDir}app/shared/model/${data.entityModelFileName}.model.ts`,
            templates: ['entities/_entityFolder_/_entityModel_.model.ts'],
        },
        {
            condition: generator => !generator.readOnly && !generator.embedded,
            ...clientApplicationTemplatesBlock(),
            templates: ['entities/_entityFolder_/_entityFile_-delete-dialog.tsx', 'entities/_entityFolder_/_entityFile_-update.tsx'],
        },
    ],
    test: [
        {
            condition: generator => !generator.embedded,
            ...clientApplicationTemplatesBlock(),
            templates: ['entities/_entityFolder_/_entityFile_-reducer.spec.ts'],
        },
    ],
};
export async function writeEntitiesFiles({ application, entities }) {
    for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtIn)) {
        await this.writeFiles({
            sections: reactFiles,
            context: { ...application, ...entity },
        });
    }
}
export async function postWriteEntitiesFiles({ application, entities }) {
    for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtIn)) {
        if (!entity.embedded) {
            const { entityInstance, entityClass, entityAngularName, entityFolderName, entityFileName } = entity;
            const { applicationTypeMicroservice, clientSrcDir } = application;
            this.needleApi.clientReact.addEntityToModule(entityInstance, entityClass, entityAngularName, entityFolderName, entityFileName, {
                applicationTypeMicroservice,
                clientSrcDir,
            });
            this.addEntityToMenu(entity.entityPage, application.enableTranslation, entity.entityTranslationKeyMenu, entity.entityClassHumanized);
        }
    }
}
export function cleanupEntitiesFiles({ application, entities }) {
    for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtIn)) {
        const { entityFolderName, entityFileName } = entity;
        if (this.isJhipsterVersionLessThan('7.0.0-beta.1')) {
            this.removeFile(`${application.clientTestDir}spec/app/entities/${entityFolderName}/${entityFileName}-reducer.spec.ts`);
        }
    }
}
