import type { RouteRecordRaw } from 'vue-router';

import RendererAdapter from '@sy/vue3-renderer-adapter';
import WujieVueRendererAdapter from '@sy/wujie-vue3-renderer-adapter';

import {
  isDevMode,
  LOW_CODE_PROJECT_ID,
  VITE_DESIGNER_URL,
  VITE_RENDERER_URL,
  VITE_V1_URL,
} from '#/constants';

const moduleName = 'micro';

const routes: RouteRecordRaw[] = [
  {
    path: '/micro',
    name: moduleName,
    meta: {
      title: '微应用容器',
      icon: 'ant-design:appstore-outlined',
    },
    children: [
      {
        path: 'admin-designer',
        name: 'AdminDesigner',
        meta: {
          hideInMenu: !isDevMode,
          title: '平台设计器',
          icon: 'ant-design:edit-outlined',
        },
        component: RendererAdapter,
        props: (route) => {
          return {
            url: `${VITE_DESIGNER_URL}`,
            projectId: LOW_CODE_PROJECT_ID,
            name: 'admin-designer',
            route,
          };
        },
      },
      {
        path: 'y-code-designer',
        name: 'YCodeDesigner',
        meta: {
          title: '低代码设计器',
          icon: 'ant-design:edit-outlined',
        },
        component: RendererAdapter,
        props: (route) => {
          return {
            url: `${VITE_DESIGNER_URL}`,
            projectId: route.query.projectId,
            name: `y-code-designer-${route.params.projectId}`,
            route,
          };
        },
      },
      {
        path: 'y-code-v1',
        name: 'YCodeV1',
        meta: {
          keepAlive: false,
          title: '悦码 1.0',
          icon: 'ant-design:delete-outlined',
        },
        component: RendererAdapter,
        props: {
          url: `${VITE_V1_URL}`,
          accessToken: localStorage.getItem('y-code-access-token'),
        },
      },
      {
        path: 'test',
        name: `Test`,
        meta: {
          keepAlive: false,
          title: '测试',
          icon: 'ant-design:delete-outlined',
        },
        component: WujieVueRendererAdapter,
        props: {
          url: `${VITE_RENDERER_URL}`,
          fileId: '45ud9h6n3',
          projectId: LOW_CODE_PROJECT_ID,
          degrade: false,
          name: '45ud9h6n3',
        },
      },
    ],
  },
];

export default routes;
