"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTemplateData = exports.getSubtypeData = exports.getAvailableSubtypes = exports.isSubtypesEnable = exports.getAvailableTypes = exports.TypesData = void 0;
const content_types_1 = require("@ewizardjs/content-types");
const getDeepCopy_1 = require("../../utils/getDeepCopy");
exports.TypesData = {
    [content_types_1.ContentTypes.EMAIL]: {
        url: 'https://git.qapint.com/ewizardjs/templates/email',
        components: 'git+https://git.qapint.com/ewizardjs/email/components',
        root: '.',
        type: content_types_1.ContentTypes.EMAIL,
        version: 'master',
    },
    ['email-fragment']: {
        url: 'https://git.qapint.com/ewizardjs/templates/email-fragment',
        components: 'git+https://git.qapint.com/ewizardjs/email/components',
        root: '.',
        type: 'email-fragment',
        version: 'master',
    },
    [content_types_1.ContentTypes.EDETAILER]: {
        url: 'https://git.qapint.com/ewizardjs/templates/edetailer',
        components: 'git+https://git.qapint.com/ewizardjs/edetailer/components',
        root: '.',
        type: content_types_1.ContentTypes.EDETAILER,
        version: 'master',
    },
    [content_types_1.ContentTypes.COMPONENT]: {
        url: 'https://git.qapint.com/ewizardjs/templates/component',
        components: '',
        root: './demo',
        type: content_types_1.ContentTypes.COMPONENT,
        version: 'master',
    },
    [content_types_1.ContentTypes.BLOCK]: {
        url: 'https://git.qapint.com/ewizardjs/templates/block',
        components: 'git+https://git.qapint.com/ewizardjs/email/components',
        root: '.',
        type: content_types_1.ContentTypes.BLOCK,
        version: 'master',
    },
    [content_types_1.ContentTypes.MODULE]: {
        url: 'https://git.qapint.com/ewizardjs/templates/module',
        components: 'git+https://git.qapint.com/ewizardjs/email/components',
        root: '.',
        type: content_types_1.ContentTypes.MODULE,
        version: 'master',
    },
    [content_types_1.ContentTypes.SITE]: {
        url: 'https://git.qapint.com/ewizardjs/templates/site',
        components: 'git+https://git.qapint.com/ewizardjs/site/components',
        root: '.',
        type: content_types_1.ContentTypes.SITE,
        version: 'master',
    },
    [content_types_1.ContentTypes.MESSENGER_AD]: {
        url: 'https://git.qapint.com/ewizardjs/templates/messenger-ad',
        components: 'git+https://git.qapint.com/ewizardjs/site/components',
        root: '.',
        type: content_types_1.ContentTypes.MESSENGER_AD,
        version: 'master',
    },
};
function getAvailableTypes() {
    return Object.keys(exports.TypesData);
}
exports.getAvailableTypes = getAvailableTypes;
function isSubtypesEnable(type) {
    const templateData = exports.TypesData[type];
    return Array.isArray(templateData);
}
exports.isSubtypesEnable = isSubtypesEnable;
function getAvailableSubtypes(type) {
    const templateData = exports.TypesData[type];
    return Array.isArray(templateData) ? templateData.map(({ type }) => type) : [];
}
exports.getAvailableSubtypes = getAvailableSubtypes;
function updateByTemplate(templateData, template) {
    const [url = '', version = ''] = template.url.split('#');
    return Object.assign(templateData, { url, version });
}
function updateByVersion(templateData, version) {
    return Object.assign(templateData, { version });
}
function getSubtypeData(templateData, subtype, version) {
    const result = templateData.find(({ type }) => type === subtype);
    return version ? updateByVersion(result, version) : result;
}
exports.getSubtypeData = getSubtypeData;
function getTemplateData({ type, subtype }, template, version) {
    let templateData = (0, getDeepCopy_1.default)(exports.TypesData[type]);
    if (!Array.isArray(templateData)) {
        templateData =
            !Array.isArray(templateData) && template && template.url
                ? updateByTemplate(templateData, template)
                : templateData;
        return !Array.isArray(templateData) && version
            ? updateByVersion(templateData, version)
            : templateData;
    }
    return Array.isArray(templateData) && subtype
        ? getSubtypeData(templateData, subtype, version)
        : templateData;
}
exports.getTemplateData = getTemplateData;
//# sourceMappingURL=index.js.map