"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPlugins = createPlugins;
const file_html_1 = __importDefault(require("./plugins/file-html"));
const file_md_1 = __importDefault(require("./plugins/file-md"));
const file_vue_1 = __importDefault(require("./plugins/file-vue"));
const vue_root_tags_1 = __importDefault(require("./plugins/vue-root-tags"));
const vue_script_js_1 = __importDefault(require("./plugins/vue-script-js"));
const vue_sfc_customblocks_1 = __importDefault(require("./plugins/vue-sfc-customblocks"));
const vue_sfc_scripts_1 = __importDefault(require("./plugins/vue-sfc-scripts"));
const vue_sfc_styles_1 = __importDefault(require("./plugins/vue-sfc-styles"));
const vue_sfc_template_1 = __importDefault(require("./plugins/vue-sfc-template"));
const vue_style_css_1 = __importDefault(require("./plugins/vue-style-css"));
const vue_template_html_1 = __importDefault(require("./plugins/vue-template-html"));
const vue_template_inline_css_1 = __importDefault(require("./plugins/vue-template-inline-css"));
const vue_template_inline_ts_1 = __importDefault(require("./plugins/vue-template-inline-ts"));
const vue_tsx_1 = __importDefault(require("./plugins/vue-tsx"));
const types_1 = require("./types");
function createPlugins(pluginContext) {
    const plugins = [
        file_vue_1.default,
        file_md_1.default,
        file_html_1.default,
        vue_root_tags_1.default,
        vue_tsx_1.default,
        vue_script_js_1.default,
        vue_style_css_1.default,
        vue_template_html_1.default,
        vue_template_inline_css_1.default,
        vue_template_inline_ts_1.default,
        vue_sfc_styles_1.default,
        vue_sfc_customblocks_1.default,
        vue_sfc_scripts_1.default,
        vue_sfc_template_1.default,
        ...pluginContext.vueCompilerOptions.plugins,
    ];
    const pluginInstances = plugins
        .flatMap(plugin => {
        try {
            const moduleConfig = plugin.__moduleConfig ?? {};
            const instance = plugin({ ...pluginContext, config: moduleConfig });
            if (Array.isArray(instance)) {
                for (let i = 0; i < instance.length; i++) {
                    instance[i].name ??= `${moduleConfig.name} (${i})`;
                }
            }
            else {
                instance.name ??= moduleConfig.name;
            }
            return instance;
        }
        catch (err) {
            console.warn('[Vue] Failed to create plugin', err);
        }
    })
        .filter(plugin => !!plugin)
        .sort((a, b) => {
        const aOrder = a.order ?? 0;
        const bOrder = b.order ?? 0;
        return aOrder - bOrder;
    });
    return pluginInstances.filter(plugin => {
        if (!types_1.validVersions.includes(plugin.version)) {
            console.warn(`[Vue] Plugin ${plugin.name} is not compatible with the current Vue language tools version. (version: ${plugin.version}, supported versions: ${JSON.stringify(types_1.validVersions)})`);
            return false;
        }
        return true;
    });
}
//# sourceMappingURL=plugins.js.map