import { createWebHistory, createRouter } from "vue-router";
/* Layout */
import Layout from "@/layout";
import basicInfo from "../views/admin/enterprise/account/basicInfo.vue";

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: "/",
    name: "Home",
    component: () => import("../views/website/website-layout.vue"),
    hidden: true,
    children: [
      {
        path: "login",
        name: "login",
        component: () => import("@/views/website/login/index.vue"),
        children: [],
      },
      {
        path: "",
        component: () => import("../views/website/home/index.vue"),
      },
      {
        path: "searchList/enterprise",
        component: () => import("../views/website/searchList/enterprise.vue"),
      },
      {
        path: "searchList/enterprise/detail/:id",
        component: () =>
          import("../views/website/searchList/enterpriseDetail.vue"),
      },
      {
        path: "searchList/patent",
        component: () => import("../views/website/searchList/patent.vue"),
      },
      {
        path: "searchList/patent/detail/:id",
        component: () => import("../views/website/searchList/patentDetail.vue"),
      },
      {
        path: "searchList/expert",
        component: () => import("../views/website/searchList/expert.vue"),
      },
      {
        path: "solution/:name",
        name: "solution",
        component: () => import("../views/website/solution/solution.vue"),
      },
      {
        path: "solution/detail/:id",
        name: "solutionDetail",
        component: () => import("../views/website/solution/detail.vue"),
      },
      {
        path: "/innovate",
        name: "innovate",
        component: () => import("../views/website/innovate/innovate.vue"),
      },
      {
        path: "innovate/detail/:id",
        name: "innovateDetail",
        component: () => import("../views/website/innovate/detail.vue"),
      },
      {
        path: "activity",
        name: "activity",
        component: () => import("../views/website/activity/activity.vue"),
        // children: [
        //   {
        //     path: '',
        //     name: 'activityList',
        //     component: () => import('../views/website/activity/list.vue'),
        //   },
        //   {
        //     path: 'detail/:id',
        //     name: 'activityDetail',
        //     component: () => import('../views/website/activity/detail.vue'),
        //   },
        // ]
      },
      {
        path: "about",
        name: "about",
        component: () => import("../views/website/about/about.vue"),
      },
    ],
  },

  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index.vue"),
      },
    ],
  },
  // {
  //   path: "/login",
  //   component: () => import("@/views/login"),
  //   hidden: true,
  // },
  // {
  //   path: "/register",
  //   component: () => import("@/views/register"),
  //   hidden: true,
  // },
  {
    path: "/:pathMatch(.*)*",
    component: () => import("@/views/error/404"),
    hidden: true,
  },
  {
    path: "/401",
    component: () => import("@/views/error/401"),
    hidden: true,
  },

  {
    path: "/identity",
    component: () => import("@/views/identity/layout"),
    hidden: true,
    children: [
      {
        path: "index",
        component: () => import("@/views/identity/index"),
        name: "index",
        meta: { title: "身份选择" },
      },
      {
        path: "enterprise",
        component: () => import("@/views/identity/enterprise"),
        name: "enterprise",
        meta: { title: "企业入驻" },
      },
      {
        path: "expert",
        component: () => import("@/views/identity/expert"),
        name: "expert",
        meta: { title: "专家入驻" },
      },
      // {
      //   path:'research',
      //   component: () => import('@/views/identity/research'),
      //   name: 'research',
      //   meta: { title: '研究机构入驻'}
      // },
      // {
      //   path:'laboratory',
      //   component: () => import('@/views/identity/laboratory'),
      //   name: 'laboratory',
      //   meta: { title: '实验室入驻'}
      // },
      // {
      //   path:'agent',
      //   component: () => import('@/views/identity/agent'),
      //   name: 'agent',
      //   meta: { title: '科技经纪人入驻'}
      // }
    ],
  },
  {
    path: "/admin",
    component: Layout,
    redirect: "/admin/index",
    children: [
      {
        path: "index",
        component: () => import("@/views/admin/index"),
        name: "Index",
        meta: { title: "首页", icon: "dashboard", affix: true },
      },
    ],
  },

  // {
  //   path: '',
  //   component: Layout,
  //   redirect: '/index',
  //   children: [
  //     {
  //       path: '/index',
  //       component: () => import('@/views/index'),
  //       name: 'Index',
  //       meta: { title: '首页', icon: 'dashboard', affix: true }
  //     }
  //   ]
  // },
  {
    path: "/user",
    component: Layout,
    hidden: true,
    redirect: "noredirect",
    children: [
      {
        path: "profile",
        component: () => import("@/views/system/user/profile/index"),
        name: "Profile",
        meta: { title: "个人中心", icon: "user" },
      },
    ],
  },
];

// 企业后台路由表
export const enterpriseRoutes = [
  {
    path: "/account",
    component: Layout,
    meta: { title: "账号管理", icon: "dashboard" },
    alwaysShow: true,
    redirect: "/account/basicInfo",
    children: [
      {
        path: "basicInfo",
        component: basicInfo,
        name: "basicInfo",
        meta: { title: "基本资料", icon: "list" },
      },
      {
        path: "joinMembership",
        component: () =>
          import("@/views/admin/enterprise/account/joinMembership"),
        name: "joinMembership",
        meta: { title: "开通会员", icon: "list" },
      },
      {
        path: "bill",
        component: () => import("@/views/admin/enterprise/account/bill"),
        name: "Bill",
        meta: { title: "账单列表", icon: "list" },
      },
      // {
      //   path: "record",
      //   component: () => import("@/views/admin/enterprise/account/record"),
      //   name: "Record",
      //   meta: { title: "创新币兑换记录", icon: "list" },
      // },
    ],
  },
  {
    path: "/extension",
    component: Layout,
    meta: { title: "产品推广", icon: "dashboard" },
    alwaysShow: true,
    redirect: "/extension/product",
    children: [
      {
        path: "product",
        component: () => import("@/views/admin/enterprise/extension/product"),
        name: "Product",
        meta: { title: "产品列表", icon: "list" },
      },
      {
        path: "release",
        component: () => import("@/views/admin/enterprise/extension/release"),
        hidden: true,
        name: "Release",
        meta: { title: "发布产品", icon: "list" },
      },
      {
        path: "results",
        component: () => import("@/views/admin/enterprise/extension/results"),
        hidden: true,
        name: "Results",
        meta: { title: "匹配结果", icon: "list" },
      },
      {
        path: "business",
        component: () => import("@/views/admin/enterprise/extension/business"),
        hidden: true,
        name: "Business",
        meta: { title: "浏览信息", icon: "list" },
      },
    ],
  },
  {
    path: "/demand",
    component: Layout,
    meta: { title: "需求管理", icon: "dashboard" },
    alwaysShow: true,
    redirect: "/demand/serviceDemand",
    children: [
      {
        path: "serviceDemand",
        component: () =>
          import("@/views/admin/enterprise/demand/serviceDemand"),
        name: "serviceDemand",
        meta: { title: "服务需求", icon: "list" },
      },
      {
        path: "releaseService",
        component: () =>
          import("@/views/admin/enterprise/demand/releaseService"),
        hidden: true,
        name: "releaseService",
        meta: { title: "发布服务需求", icon: "list" },
      },
      {
        path: "technology",
        component: () => import("@/views/admin/enterprise/demand/technology"),
        name: "technology",
        meta: { title: "技术需求", icon: "list" },
      },
      {
        path: "releaseTechnology",
        component: () =>
          import("@/views/admin/enterprise/demand/releaseTechnology"),
        hidden: true,
        name: "releaseTechnology",
        meta: { title: "发布技术需求", icon: "list" },
      },
      {
        path: "results",
        component: () => import("@/views/admin/enterprise/demand/results"),
        hidden: true,
        name: "results",
        meta: { title: "匹配结果", icon: "list" },
      },
    ],
  },
  {
    path: "/activity",
    component: Layout,
    meta: { title: "活动管理", icon: "dashboard" },
    alwaysShow: true,
    redirect: "/activity/active",
    children: [
      {
        path: "active",
        component: () => import("@/views/admin/enterprise/activity/active"),
        name: "Active",
        meta: { title: "活动列表", icon: "list" },
      },
    ],
  },
];

// 专家后台路由表
export const expertRoutes = [
  {
    path: "/account",
    component: Layout,
    meta: { title: "账号管理", icon: "dashboard" },
    alwaysShow: true,
    // redirect: 'noRedirect',
    redirect: "/account/bill",
    children: [
      // {
      //   path: "bill",
      //   component: () => import("@/views/admin/expert/account/bill"),
      //   name: "Bill",
      //   meta: { title: "账单列表", icon: "list" },
      // },
      // {
      //   path: "exchange",
      //   component: () => import("@/views/admin/expert/account/exchange"),
      //   name: "Exchange",
      //   meta: { title: "兑换记录", icon: "list" },
      // },
      {
        path: "basicInfo",
        component: () => import("@/views/admin/expert/account/basicInfo"),
        name: "basicInfo",
        meta: { title: "基本资料", icon: "list" },
      },
      // {
      //   path: "transactionAuth",
      //   component: () => import("@/views/admin/expert/account/transactionAuth"),
      //   name: "transactionAuth",
      //   meta: { title: "交易认证", icon: "list" },
      // },
      // {
      //   path: "profit",
      //   component: () => import("@/views/admin/expert/account/profit"),
      //   name: "profit",
      //   meta: { title: "收益管理", icon: "list" },
      // },
      // {
      //   path: "withdrawal",
      //   component: () => import("@/views/admin/expert/account/withdrawal"),
      //   hidden: true,
      //   name: "Withdrawal",
      //   meta: { title: "提现记录", icon: "list" },
      // },
    ],
  },
  {
    path: "/technology",
    component: Layout,
    meta: { title: "技术管理", icon: "dashboard" },
    alwaysShow: true,
    redirect: "/technology/achievement",
    children: [
      {
        path: "achievement",
        component: () => import("@/views/admin/expert/technology/achievement"),
        name: "Achievement",
        meta: { title: "成果列表", icon: "list" },
      },
      {
        path: "release",
        component: () => import("@/views/admin/expert/technology/release"),
        hidden: true,
        name: "Release",
        meta: { title: "发布成果", icon: "list" },
      },
      // {
      //   path: "results",
      //   component: () => import("@/views/admin/expert/technology/results"),
      //   hidden: true,
      //   name: "Results",
      //   meta: { title: "匹配结果", icon: "list" },
      // },
      // {
      //   path: "patent",
      //   component: () => import("@/views/admin/expert/technology/patent"),
      //   name: "patent",
      //   meta: { title: "专利列表", icon: "list" },
      // },
      // {
      //   path: "claimPatent",
      //   component: () => import("@/views/admin/expert/technology/claimPatent"),
      //   hidden: true,
      //   name: "claimPatent",
      //   meta: { title: "认领专利", icon: "list" },
      // },
      {
        path: "paper",
        component: () => import("@/views/admin/expert/technology/paper"),
        name: "Paper",
        meta: { title: "论文列表", icon: "list" },
      },
      {
        path: "research",
        component: () => import("@/views/admin/expert/technology/research"),
        name: "Research",
        meta: { title: "科研项目列表", icon: "list" },
      },
    ],
  },
  {
    path: "/demand",
    component: Layout,
    meta: { title: "需求管理", icon: "dashboard" },
    alwaysShow: true,
    redirect: "/demand/serviceDemand",
    children: [
      {
        path: "serviceDemand",
        component: () => import("@/views/admin/expert/demand/serviceDemand"),
        name: "serviceDemand",
        meta: { title: "服务需求", icon: "list" },
      },
      {
        path: "release",
        component: () => import("@/views/admin/expert/demand/release"),
        hidden: true,
        name: "release",
        meta: { title: "发布需求", icon: "list" },
      },
      {
        path: "already",
        component: () => import("@/views/admin/expert/demand/already"),
        name: "already",
        meta: { title: "已合作企业", icon: "list" },
      },
      {
        path: "think",
        component: () => import("@/views/admin/expert/demand/think"),
        name: "think",
        meta: { title: "想合作企业", icon: "list" },
      },
    ],
  },

  {
    path: "/activity",
    component: Layout,
    meta: { title: "活动管理", icon: "dashboard" },
    alwaysShow: true,
    redirect: "/activity/active",
    children: [
      {
        path: "active",
        component: () => import("@/views/admin/expert/activity/active"),
        name: "Active",
        meta: { title: "活动列表", icon: "list" },
      },
    ],
  },
];
// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: "/system/user-auth",
    component: Layout,
    hidden: true,
    permissions: ["system:user:edit"],
    children: [
      {
        path: "role/:userId(\\d+)",
        component: () => import("@/views/system/user/authRole"),
        name: "AuthRole",
        meta: { title: "分配角色", activeMenu: "/system/user" },
      },
    ],
  },
  {
    path: "/system/role-auth",
    component: Layout,
    hidden: true,
    permissions: ["system:role:edit"],
    children: [
      {
        path: "user/:roleId(\\d+)",
        component: () => import("@/views/system/role/authUser"),
        name: "AuthUser",
        meta: { title: "分配用户", activeMenu: "/system/role" },
      },
    ],
  },
  {
    path: "/system/dict-data",
    component: Layout,
    hidden: true,
    permissions: ["system:dict:list"],
    children: [
      {
        path: "index/:dictId(\\d+)",
        component: () => import("@/views/system/dict/data"),
        name: "Data",
        meta: { title: "字典数据", activeMenu: "/system/dict" },
      },
    ],
  },
  {
    path: "/monitor/job-log",
    component: Layout,
    hidden: true,
    permissions: ["monitor:job:list"],
    children: [
      {
        path: "index",
        component: () => import("@/views/monitor/job/log"),
        name: "JobLog",
        meta: { title: "调度日志", activeMenu: "/monitor/job" },
      },
    ],
  },
  {
    path: "/tool/gen-edit",
    component: Layout,
    hidden: true,
    permissions: ["tool:gen:edit"],
    children: [
      {
        path: "index/:tableId(\\d+)",
        component: () => import("@/views/tool/gen/editTable"),
        name: "GenEdit",
        meta: { title: "修改生成配置", activeMenu: "/tool/gen" },
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  },
});

export default router;
