import type { AppRouteRecordRaw } from '/@/router/types';
import { t } from '/@/hooks/web/useI18n';
import {
  REDIRECT_NAME,
  PLATFORM_LAYOUT,
  EXCEPTION_COMPONENT,
  PAGE_NOT_FOUND_NAME,
  DEFAULT_PLATFORM_LAYOUT,
  PLATFORM_WORKBENCH_LAYOUT,
} from '/@/router/constant';
// 404 on a page
import FrameLayout from '/@/views/platform/application/FramePage.vue';
export const PAGE_NOT_FOUND_ROUTE: AppRouteRecordRaw = {
  path: '/:path(.*)*',
  name: PAGE_NOT_FOUND_NAME + '123',
  component: DEFAULT_PLATFORM_LAYOUT,
  meta: {
    title: 'ErrorPage',
    hideBreadcrumb: true,
    hideMenu: true,
  },
  children: [
    {
      path: '/:path(.*)*',
      name: PAGE_NOT_FOUND_NAME,
      component: EXCEPTION_COMPONENT,
      meta: {
        title: 'ErrorPage',
        hideBreadcrumb: true,
        hideMenu: true,
      },
    },
  ],
};

export const REDIRECT_ROUTE: AppRouteRecordRaw = {
  path: '/redirect',
  component: DEFAULT_PLATFORM_LAYOUT,
  name: 'RedirectTo',
  meta: {
    title: REDIRECT_NAME,
    hideBreadcrumb: true,
    hideMenu: true,
  },
  children: [
    {
      path: '/redirect/:path(.*)',
      name: REDIRECT_NAME,
      component: () => import('/@/views/sys/redirect/index.vue'),
      meta: {
        title: REDIRECT_NAME,
        hideBreadcrumb: true,
      },
    },
  ],
};

export const ERROR_LOG_ROUTE: AppRouteRecordRaw = {
  path: '/error-log',
  name: 'ErrorLog',
  component: DEFAULT_PLATFORM_LAYOUT,
  redirect: '/error-log/list',
  meta: {
    title: 'ErrorLog',
    hideBreadcrumb: true,
    hideChildrenInMenu: true,
  },
  children: [
    {
      path: 'list',
      name: 'ErrorLogList',
      component: () => import('/@/views/sys/error-log/index.vue'),
      meta: {
        title: t('错误日志列表'),
        hideBreadcrumb: true,
        currentActiveMenu: '/error-log',
      },
    },
  ],
};
// TODO 添加应用路由
export const IframeComponentTypeString = 'iframe';
export const ApplicationMenuList = [
  {
    title: '电脑端页面',
    icon: 'platform-icon1',
    url: '/application/designForm',
    name: 'ApplicationFormDesign',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'form/release/index.vue',
    path: 'designForm',
    meta: {
      affix: false,
      title: t('电脑端页面'),
    },
  },
  {
    title: '移动端页面',
    icon: 'platform-icon2',
    url: '/application/mobileDesign',
    name: 'ApplicationMobileDesign',
    path: 'mobileDesign',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'mobileDesign/dataDesign/index.vue',
    meta: {
      affix: false,
      title: t('移动端页面'),
    },
  },
  {
    title: '在线接口',
    icon: 'platform-icon3',
    url: '/application/magicDesign',
    name: 'ApplicationMagicDesign',
    componentType: IframeComponentTypeString,
    path: 'magicDesign',
    // componentPath: '',
    component: null,
    meta: {
      iframeSrc: 'http://192.168.0.108:8080/magic/web/index.html?Authorization=#{token}',
      affix: false,
      title: t('在线接口'),
    },
  },
  {
    title: '脚本管理',
    icon: 'platform-icon4',
    url: '/application/scriptDemo',
    name: 'ApplicationScriptDemo',
    path: 'scriptDemo',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'dataconfig/scriptDemo/index.vue',
    meta: {
      affix: false,
      title: t('脚本管理'),
    },
  },
  {
    title: '数据库管理',
    icon: 'platform-icon5',
    url: '/application/databaselink',
    name: 'ApplicationDatabaselink',
    path: 'databaselink',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'dataconfig/databaselink/index.vue',
    meta: {
      affix: false,
      title: t('数据库管理'),
    },
  },
  {
    title: '外部系统接口',
    icon: 'platform-icon6',
    url: '/application/loginSetting',
    name: 'ApplicationLoginSetting',
    path: 'loginSetting',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'system/loginSetting/loginInfo.vue',
    meta: {
      affix: false,
      title: t('外部系统接口'),
    },
  },
  {
    title: '流程服务',
    icon: 'platform-icon7',
    url: '/application/workflowDesign',
    name: 'ApplicationWorkflowDesign',
    path: 'workflowDesign',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'workflow/design/index.vue',
    meta: {
      affix: false,
      title: t('流程服务'),
    },
  },
  {
    title: '规则编排',
    icon: 'platform-icon8',
    url: '/application/ruleProcess',
    name: 'ApplicationRuleProcess',
    path: 'ruleProcess',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'ruleProcess/index.vue',
    meta: {
      affix: false,
      title: t('规则编排'),
    },
  },
  {
    title: '数据权限',
    icon: 'platform-icon9',
    url: '/application/authorityList',
    name: 'ApplicationAuthorityList',
    path: 'authorityList',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'system/dataAuthority/index.vue',
    meta: {
      affix: false,
      title: t('数据权限'),
    },
  },
  {
    title: '打印模板',
    icon: 'platform-icon10',
    url: '/application/printTemplate',
    name: 'ApplicationPrintTemplate',
    path: 'printTemplate',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'generator/print/index.vue',
    meta: {
      affix: false,
      title: t('打印设计'),
    },
  },
  {
    title: '组织架构',
    icon: 'platform-icon11',
    url: '/application/oragin',
    name: 'ApplicatioOragin',
    path: 'oragin',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'system/user/index.vue',
    meta: {
      affix: false,
      title: t('用户管理'),
    },
  },
  {
    title: '定时任务',
    icon: 'platform-icon12',
    url: '/application/xjrsoftjob',
    name: 'ApplicationXjrsoftjob',
    path: 'xjrsoftjob',
    // componentPath: '',
    component: null,
    componentType: IframeComponentTypeString,
    meta: {
      affix: false,
      title: t('定时任务'),
      iframeSrc: 'http://192.168.0.124:7700/#/welcome?appName=xjrsoft-boot&password=123456',
    },
  },
  {
    title: '消息模版',
    icon: 'platform-icon13',
    url: '/application/messageTemplate',
    name: 'ApplicationMessageTemplate',
    path: 'messageTemplate',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'system/messageTemplate/index.vue',
    meta: {
      affix: false,
      title: t('消息模版'),
    },
  },
  {
    title: '设置',
    icon: 'platform-icon14',
    url: '/application/strutureInfo',
    name: 'ApplicationStrutureInfo',
    path: 'strutureInfo',
    componentType: '',
    component: () => import('/@/views/platform/demo/Index.vue'),
    // componentPath: 'system/logoSetting/strutureInfo.vue',
    meta: {
      affix: false,
      title: t('设置'),
    },
  },
];
export const PlatformMenuList1 = [
  {
    title: '工作台',
    icon: 'platform-icon1-1',
    activeIcon: 'platform-icon1-2',
    url: '/workbench/index',
    name: 'PlatformWorkbench',
    path: 'index',
    componentType: '',
    component: () => import('/@/views/platform/workbench/index.vue'),
    // componentPath: 'platform/workbench/index.vue',
    meta: {
      title: t('工作台'),
      affix: true,
      isHide: true,
    },
  },
];
export const PlatformMenuList2 = [
  {
    title: '应用',
    icon: 'platform-icon2-1',
    activeIcon: 'platform-icon2-2',
    url: '/platform/application',
    name: 'PlatformApplication',
    path: 'application',
    componentType: '',
    component: () => import('/@/views/platform/workbench/Application.vue'),
    // componentPath: 'platform/workbench/Application.vue',
    meta: {
      title: t('应用'),
      affix: false,
      isHide: true,
    },
  },
  {
    title: '模版',
    icon: 'platform-icon3-1',
    activeIcon: 'platform-icon3-2',
    url: '/platform/template',
    name: 'PlatformTemplate',
    path: 'template',
    componentType: '',
    component: () => import('/@/views/platform/workbench/Template.vue'),
    // componentPath: 'platform/workbench/Template.vue',
    meta: {
      title: t('模版'),
      affix: false,
      isHide: true,
    },
  },
  {
    title: '日志',
    icon: 'platform-icon4-1',
    activeIcon: 'platform-icon4-2',
    url: '/platform/log',
    name: 'PlatformLog',
    path: 'log',
    componentType: '',
    component: () => import('/@/views/platform/workbench/Log.vue'),
    // componentPath: 'platform/workbench/Log.vue',
    meta: {
      title: t('日志'),
      affix: false,
      isHide: true,
    },
  },
  {
    title: '开发者管理',
    icon: 'platform-icon5-1',
    activeIcon: 'platform-icon5-2',
    url: '/platform/developer',
    name: 'PlatformDeveloper',
    path: 'developer',
    componentType: '',
    component: () => import('/@/views/platform/workbench/Developer.vue'),
    // componentPath: 'platform/workbench/Developer.vue',
    meta: {
      title: t('开发者管理'),
      affix: false,
      isHide: true,
    },
  },
  {
    title: '脚手架下载',
    icon: 'platform-icon6-1',
    activeIcon: 'platform-icon6-2',
    url: '/platform/scaffold',
    name: 'PlatformScaffold',
    path: 'scaffold',
    componentType: '',
    component: () => import('/@/views/platform/workbench/Rigger.vue'),
    // componentPath: 'platform/workbench/Rigger.vue',
    meta: {
      title: t('脚手架下载'),
      affix: false,
      isHide: true,
    },
  },
];
export const PlatformMenuList = [...PlatformMenuList1, ...PlatformMenuList2];
function getRouteChildren(menuList) {
  const list: Array<any> = [];
  if (menuList && menuList.length > 0) {
    menuList.forEach((element) => {
      if (element.componentType == IframeComponentTypeString) {
        list.push({
          path: element.path,
          name: element.name,
          component: FrameLayout,
          meta: element.meta,
        });
      } else {
        list.push({
          path: element.path,
          name: element.name,
          component: element.component,
          meta: element.meta,
        });
      }
    });
  }
  return list;
}
export const PLATFORM_ROUTE: AppRouteRecordRaw = {
  path: '/platform',
  name: 'Platform',
  component: PLATFORM_LAYOUT,
  redirect: '/platform/template',
  meta: {
    orderNo: 10,
    icon: 'ion:grid-outline',
    title: t('首页'),
  },
  children: [...getRouteChildren(PlatformMenuList2)],
};
export const PLATFORM_WORKBENCH_ROUTE: AppRouteRecordRaw = {
  path: '/workbench',
  name: 'Workbench',
  component: PLATFORM_WORKBENCH_LAYOUT,
  redirect: '/workbench/index',
  meta: {
    orderNo: 10,
    icon: 'ion:grid-outline',
    title: t('首页'),
  },
  children: [...getRouteChildren(PlatformMenuList1)],
};

export const APPLICATION_ROUTE: AppRouteRecordRaw = {
  path: '/application',
  name: 'Application',
  component: DEFAULT_PLATFORM_LAYOUT,
  redirect: '/application/index',
  meta: {
    orderNo: 10,
    icon: 'ion:grid-outline',
    title: t('应用'),
  },
  children: [
    {
      path: 'index',
      name: 'ApplicationIndex',
      component: () => import('/@/views/platform/demo/Index.vue'),
      meta: {
        affix: true,
        title: t('应用配置'),
      },
    },
    ...getRouteChildren(ApplicationMenuList),
  ],
};
