"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const helpers_1 = require("../../utils/helpers");
const getAllFilesFromDir_1 = tslib_1.__importDefault(require("@vue-storefront/nuxt-theme/scripts/getAllFilesFromDir"));
const compileTemplate_1 = tslib_1.__importDefault(require("@vue-storefront/nuxt-theme/scripts/compileTemplate"));
const path = tslib_1.__importStar(require("path"));
const fs = tslib_1.__importStar(require("fs"));
exports.default = async (integration, targetPath) => {
    const agnosticThemePath = path.join(helpers_1.getDependencyPath('nuxt-theme'), 'theme');
    const agnosticThemeFiles = getAllFilesFromDir_1.default(agnosticThemePath)
        .filter(file => !file.includes(path.sep + 'static' + path.sep));
    const compileAgnosticTemplate = (filePath, targetPath, chopPhrase) => {
        const finalPath = helpers_1.buildFileTargetPath(filePath, targetPath, chopPhrase);
        if (fs.existsSync(finalPath)) {
            return;
        }
        return compileTemplate_1.default(path.isAbsolute(filePath)
            ? filePath
            : path.join(agnosticThemePath.replace(/\/theme$/, ''), filePath), finalPath.replace('theme', ''), {
            generate: {
                replace: {
                    apiClient: `@vue-storefront/${integration}-api`,
                    composables: `@vue-storefront/${integration}`
                }
            }
        });
    };
    await Promise.all(agnosticThemeFiles.map(absoluteDirectoryPath => compileAgnosticTemplate(absoluteDirectoryPath, path.isAbsolute(targetPath)
        ? targetPath
        : path.join(__dirname, targetPath), agnosticThemePath)));
};
//# sourceMappingURL=copyAgnosticTheme.js.map