"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const lowcode_code_generator_1 = require("@alilc/lowcode-code-generator");
const lodash_1 = tslib_1.__importDefault(require("lodash"));
const const_1 = require("./const");
const pluginFactory = (config) => {
    const cfg = Object.assign({ fileType: 'vue' }, config);
    const plugin = (pre) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        const next = Object.assign({}, pre);
        const ir = next.ir;
        if (!ir.methods) {
            return next;
        }
        const createMethodsContent = () => {
            let pieces = [];
            lodash_1.default.forIn(ir.methods, (item, methodName) => {
                if (item.type === 'JSFunction') {
                    const modifiedString = item.value.replace("function (", `function ${methodName} (`);
                    pieces.push(modifiedString);
                }
            });
            return pieces.join('\n');
        };
        next.chunks.push({
            type: lowcode_code_generator_1.ChunkType.STRING,
            fileType: cfg.fileType,
            name: const_1.VUE_CHUNK_NAME.ScriptMethods,
            content: createMethodsContent(),
            linkAfter: [const_1.VUE_CHUNK_NAME.ScriptStart, const_1.VUE_CHUNK_NAME.ScriptVueImp, const_1.VUE_CHUNK_NAME.ScriptInitState, const_1.VUE_CHUNK_NAME.ScriptLifeCycles],
        });
        return next;
    });
    return plugin;
};
exports.default = pluginFactory;
//# sourceMappingURL=methods.js.map