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

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

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

const routes: RouteRecordRaw[] = [
  {
    path: '/micro',
    name: 'Micro',
    meta: {
      title: '微应用容器',
      icon: 'ant-design:appstore-outlined',
      hideInMenu: !isDevMode,
    },
    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: {
          hideInMenu: true,
          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,
            accessToken: localStorage.getItem('y-code-access-token'),
          };
        },
      },
      {
        path: 'y-code-v1',
        name: 'YCodeV1',
        meta: {
          keepAlive: false,
          title: '悦码 1.0',
          icon: 'ant-design:delete-outlined',
        },
        component: RendererAdapter,
        props: () => {
          return {
            url: `${VITE_V1_URL}`,
            accessToken: localStorage.getItem('y-code-access-token'),
          };
        },
      },
    ],
  },
];

export default routes;
