/**
 * Copyright 2013-2026 the original author or authors from the JHipster project.
 *
 * This file is part of the JHipster project, see https://www.jhipster.tech/
 * for more information.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { CLIENT_MAIN_SRC_DIR } from "../../generator-constants.js";
export const replaceEntityFilePath = (data, filepath) => filepath
    .replace(/_entityFolder_/, data.entityFolderName)
    .replace(/_entityFile_/, data.entityFileName)
    .replace(/_entityModel_/, data.entityModelFileName);
const CLIENT_TEMPLATES_SRC_DIR = CLIENT_MAIN_SRC_DIR;
export function clientRootTemplatesBlock(blockOrRelativePath = '') {
    return clientBlock({
        srcPath: '',
        destProperty: 'clientRootDir',
        blockOrRelativePath,
    });
}
export function clientSrcTemplatesBlock(blockOrRelativePath = '') {
    return clientBlock({
        srcPath: CLIENT_TEMPLATES_SRC_DIR,
        destProperty: 'clientSrcDir',
        blockOrRelativePath,
    });
}
export function clientApplicationTemplatesBlock(blockOrRelativePath = '') {
    return clientBlock({
        srcPath: CLIENT_TEMPLATES_SRC_DIR,
        relativeToSrc: 'app/',
        destProperty: 'clientSrcDir',
        blockOrRelativePath,
    });
}
function clientBlock({ srcPath, destProperty, blockOrRelativePath = '', relativeToSrc = '', }) {
    const block = typeof blockOrRelativePath === 'string' ? undefined : blockOrRelativePath;
    const blockRenameTo = typeof block?.renameTo === 'function' ? block.renameTo : undefined;
    const relativePath = typeof blockOrRelativePath === 'string' ? blockOrRelativePath : (blockOrRelativePath.relativePath ?? '');
    return {
        path: `${srcPath}${relativeToSrc}${relativePath}`,
        ...block,
        renameTo(data, filePath) {
            return `${data[destProperty]}${relativeToSrc}${replaceEntityFilePath(data, relativePath) ?? ''}${replaceEntityFilePath(data, blockRenameTo?.call?.(this, data, filePath) ?? filePath) ?? ''}`;
        },
    };
}
