import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import About from '../views/About.vue'
import ThinkTankDetail from '@/views/ThinkTankDetail/index.vue'
import ReportDetail from '@/views/ReportDetail/index.vue'

// 法案相关组件
import BillHome from '@/views/billHome/index.vue'
import BillLayoutContainer from '@/views/billLayout/index.vue'
import BillLayout from '@/views/bill/index.vue'
import BillIntroduction from '@/views/bill/introdoction/index.vue'
import BillBackground from '@/views/bill/background/index.vue'
import BillTemplate from '@/views/bill/template/index.vue'

// 深度挖掘相关组件
import DeepDigLayout from '@/views/deepDig/index.vue'
import DeepDigProcessOverview from '@/views/deepDig/processOverview/index.vue'
import DeepDigProcessAnalysis from '@/views/deepDig/processAnalysis/index.vue'
import DeepDigProgressOverview from '@/views/deepDig/progressAnalysis/index.vue'

// 影响分析相关组件
import InfluenceLayout from '@/views/influence/index.vue'
import InfluenceIndustry from '@/views/influence/industry/index.vue'
import InfluenceScientificResearch from '@/views/influence/scientificResearch/index.vue'

// 出口管制
import ExportControl from '@/views/exportControl/index.vue'

// 政令
import Decree from '@/views/decree/decreeHome/index.vue'
import DecreeLayoutContainer from '@/views/decree/decreeLayout/index.vue'
import OverviewLayout from '@/views/decree/decreeLayout/overview/index.vue'
import DecreeIntroduction from '@/views/decree/decreeLayout/overview/introduction/index.vue'
import DecreeBackground from '@/views/decree/decreeLayout/overview/background/index.vue'
import DecreeDeepDig from '@/views/decree/decreeLayout/deepdig/index.vue'

// 市场准入限制
import MarketAccessRestrictions from '@/views/marketAccessRestrictions/marketAccessHome/index.vue'
import MarketAccessLayout from '@/views/marketAccessRestrictions/marketAccessLayout/index.vue'
import MarketAccessOverview from '@/views/marketAccessRestrictions/marketAccessLayout/overview/index.vue'
import MarketAccessCase from '@/views/marketAccessRestrictions/marketAccessLayout/case/index.vue'

const routes = [
  // 智库系统的主要路由
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      title: '首页'
    },
  },
  {
    path: '/about',
    name: 'About',
    component: About,
    meta: {
      title: '关于我们'
    }
  },
  {
    path: '/think-tank/:id',
    name: 'ThinkTankDetail',
    component: ThinkTankDetail,
    meta: {
      title: '智库详情'
    }
  },
  {
    path: '/report/:id',
    name: 'ReportDetail',
    component: ReportDetail,
    meta: {
      title: '报告详情'
    }
  },

  // 法案系统路由
  {
    path: '/billHome',
    name: 'BillHome',
    component: BillHome,
    meta: {
      title: '法案首页'
    },
  },
  {
    path: '/billLayout',
    name: 'BillLayoutContainer',
    component: BillLayoutContainer,
    redirect: '/billLayout/bill',
    meta: {
      title: '法案布局'
    },
    children: [
      // 法案分析路由
      {
        path: 'bill',
        name: 'BillLayout',
        component: BillLayout,
        redirect: '/billLayout/bill/introduction',
        meta: {
          title: '法案分析'
        },
        children: [
          {
            path: 'introduction',
            name: 'BillIntroduction',
            component: BillIntroduction,
            meta: { title: '法案简介' }
          },
          {
            path: 'background',
            name: 'BillBackground',
            component: BillBackground,
            meta: { title: '法案背景' }
          },
          {
            path: 'template',
            name: 'BillTemplate',
            component: BillTemplate,
            meta: { title: '内容概要' }
          }
        ]
      },
      // 深度挖掘路由
      {
        path: 'deepDig',
        name: 'DeepDigLayout',
        component: DeepDigLayout,
        redirect: '/billLayout/deepDig/processOverview',
        meta: {
          title: '深度挖掘'
        },
        children: [
          {
            path: 'processOverview',
            name: 'DeepDigProcessOverview',
            component: DeepDigProcessOverview,
            meta: { title: '流程概要' }
          },
          {
            path: 'processAnalysis',
            name: 'DeepDigProcessAnalysis',
            component: DeepDigProcessAnalysis,
            meta: { title: '流程分析' }
          },
          {
            path: 'progressAnalysis',
            name: 'DeepDigProgressAnalysis',
            component: DeepDigProgressOverview,
            meta: { title: '进程分析' }
          },
        ]
      },
      // 影响分析路由
      {
        path: 'influence',
        name: 'InfluenceLayout',
        component: InfluenceLayout,
        redirect: '/billLayout/influence/industry',
        meta: {
          title: '影响分析'
        },
        children: [
          {
            path: 'industry',
            name: 'InfluenceIndustry',
            component: InfluenceIndustry,
            meta: { title: '对华产业影响' }
          },
          {
            path: 'scientificResearch',
            name: 'InfluenceScientificResearch',
            component: InfluenceScientificResearch,
            meta: { title: '对华科研影响' }
          }
        ]
      }
    ]
  },

  // 出口管制首页
  {
    path: '/exportControl',
    name: 'ExportControl',
    component: ExportControl,
    meta: {
      title: '出口管制'
    },
  },

  // 政令首页
  {
    path: '/decree',
    name: 'Decree',
    component: Decree,
    meta: {
      title: '政令'
    },
  },
  {
    path: '/decreeLayout',
    name: 'DecreeLayoutContainer',
    component: DecreeLayoutContainer,
    redirect: '/decreeLayout/overview',
    meta: {
      title: '政令布局'
    },
    children: [
      {
        path: 'overview',
        name: 'OverviewLayout',
        component: OverviewLayout,
        redirect: '/decreeLayout/overview/introduction',
        meta: {
          title: '政令概况'
        },
        children: [
          {
            path: 'introduction',
            name: 'DecreeIntroduction',
            component: DecreeIntroduction,
            meta: { title: '政令简介' }
          },
          {
            path: 'background',
            name: 'DecreeBackground',
            component: DecreeBackground,
            meta: { title: '政令背景' }
          },
        ]
      },
      // 深度挖掘路由
      {
        path: 'deepDig',
        name: 'DeepDig',
        component: DecreeDeepDig,
        meta: {
          title: '深度挖掘'
        },
      },
      // // 影响分析路由
      // {
      //   path: 'influence',
      //   name: 'InfluenceLayout',
      //   component: InfluenceLayout,
      //   redirect: '/billLayout/influence/industry',
      //   meta: {
      //     title: '影响分析'
      //   },
      //   children: [
      //     {
      //       path: 'industry',
      //       name: 'InfluenceIndustry',
      //       component: InfluenceIndustry,
      //       meta: { title: '对华产业影响' }
      //     },
      //     {
      //       path: 'scientificResearch',
      //       name: 'InfluenceScientificResearch',
      //       component: InfluenceScientificResearch,
      //       meta: { title: '对华科研影响' }
      //     }
      //   ]
      // }
    ]
  },

  // 市场准入限制首页
  {
    path: '/marketAccessRestrictions',
    name: 'MarketAccessRestrictions',
    component: MarketAccessRestrictions,
    meta: {
      title: '市场准入限制'
    },
  },
  {
    path: '/marketAccessLayout',
    name: 'MarketAccessLayout',
    component: MarketAccessLayout,
    redirect: '/marketAccessLayout/overview',
    meta: {
      title: '市场准入限制布局'
    },
    children: [
      {
        path: 'overview',
        name: 'MarketAccessOverview',
        component: MarketAccessOverview,
        meta: {
          title: '调查概况'
        },
      },
      {
        path: 'case',
        name: 'MarketAccessCase',
        component: MarketAccessCase,
        meta: {
          title: '调查案件'
        },
      },

    ]
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫 - 设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    // document.title = `${to.meta.title} - Think Tank`
  }
  next()
})

export default router