"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const lowcode_code_generator_1 = require("@alilc/lowcode-code-generator");
const pluginFactory = () => {
    const plugin = (pre) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
        var _a;
        const next = Object.assign({}, pre);
        const ir = next.ir;
        const { routes } = ir;
        routes.map(route => {
            next.chunks.push({
                type: lowcode_code_generator_1.ChunkType.STRING,
                fileType: lowcode_code_generator_1.FileType.JS,
                name: lowcode_code_generator_1.COMMON_CHUNK_NAME.InternalDepsImport,
                content: `
        import ${route.componentName} from '@/pages/${route.fileName}/index.vue'
        `,
                linkAfter: [lowcode_code_generator_1.COMMON_CHUNK_NAME.ExternalDepsImport],
            });
        });
        next.chunks.push({
            type: lowcode_code_generator_1.ChunkType.STRING,
            fileType: lowcode_code_generator_1.FileType.JS,
            name: lowcode_code_generator_1.COMMON_CHUNK_NAME.InternalDepsImport,
            content: `
      import { createRouter, createWebHistory } from 'vue-router'
      `,
            linkAfter: [lowcode_code_generator_1.COMMON_CHUNK_NAME.ExternalDepsImport],
        });
        let firtRoute = (_a = ir.routes) === null || _a === void 0 ? void 0 : _a[0];
        next.chunks.push({
            type: lowcode_code_generator_1.ChunkType.STRING,
            fileType: lowcode_code_generator_1.FileType.JS,
            name: lowcode_code_generator_1.COMMON_CHUNK_NAME.FileVarDefine,
            content: `
      const router = createRouter({
        history: createWebHistory(import.meta.env.BASE_URL),
        routes: [
          {
            path: '/',
            redirect: '${firtRoute.path}',
          },
          ${ir.routes
                .map((route) => `
                            {
                              path: '${route.path}',
                              component: ${route.componentName},
                            }
                          `)
                .join(',')}
        ]
      })
      `,
            linkAfter: [
                lowcode_code_generator_1.COMMON_CHUNK_NAME.ExternalDepsImport,
                lowcode_code_generator_1.COMMON_CHUNK_NAME.InternalDepsImport,
                lowcode_code_generator_1.COMMON_CHUNK_NAME.ImportAliasDefine,
                lowcode_code_generator_1.COMMON_CHUNK_NAME.FileUtilDefine,
            ],
        });
        next.chunks.push({
            type: lowcode_code_generator_1.ChunkType.STRING,
            fileType: lowcode_code_generator_1.FileType.JS,
            name: lowcode_code_generator_1.COMMON_CHUNK_NAME.FileExport,
            content: `
      export default router;
      `,
            linkAfter: [
                lowcode_code_generator_1.COMMON_CHUNK_NAME.ExternalDepsImport,
                lowcode_code_generator_1.COMMON_CHUNK_NAME.InternalDepsImport,
                lowcode_code_generator_1.COMMON_CHUNK_NAME.FileUtilDefine,
                lowcode_code_generator_1.COMMON_CHUNK_NAME.ImportAliasDefine,
                lowcode_code_generator_1.COMMON_CHUNK_NAME.FileVarDefine,
                lowcode_code_generator_1.COMMON_CHUNK_NAME.FileMainContent,
            ],
        });
        return next;
    });
    return plugin;
};
exports.default = pluginFactory;
//# sourceMappingURL=router.js.map