import {createWebHashHistory, createRouter} from 'vue-router'

import HomeView from '@/views/homepage/index.vue'

const routes = [
  // ============================================  首页  ============================================
  {path: '/', component: HomeView},

  // ============================================  产品中心  ============================================
  {
    path: '/product/hardwareSystem',
    name: 'HardwareSystem',
    component: () => import('@/views/product/hardwareSystem.vue'),
    meta: {
      title: '低空监管体系',
    },
  },
  {
    path: '/product/softwareSystem',
    name: 'SoftwareSystem',
    component: () => import('@/views/product/softwareSystem.vue'),
    meta: {
      title: '低空远程识别设备',
    },
  },
  {
    path: '/product/detail',
    name: 'ProductDetail',
    component: () => import('@/views/product/detail.vue'),
    meta: {
      title: '产品详情',
    },
  },

  // ============================================  服务与支撑  ============================================
  {
    path: '/services',
    name: 'Services',
    component: () => import('@/views/services/index.vue'),
    meta: {
      title: '服务与支撑',
    },
  },

  // ============================================  新闻中心  ============================================
  {
    path: '/news',
    name: 'News',
    component: () => import('@/views/news/index.vue'),
    meta: {
      title: '新闻中心',
    },
  },
  {
    path: '/news/detail',
    name: 'NewsDetail',
    component: () => import('@/views/news/detail.vue'),
    meta: {
      title: '新闻详情',
    },
  },

  // ============================================  关于我们  ============================================
  {
    path: '/about',
    name: 'About',
    component: () => import('@/views/about/index.vue'),
    meta: {
      title: '关于我们',
    },
  },

  // ============================================  联系我们  ============================================
  {
    path: '/link',
    name: 'Link',
    component: () => import('@/views/link/index.vue'),
    meta: {
      title: '联系我们',
    },
  },

  // ============================================  下载中心  ============================================
  {
    path: '/download',
    name: 'Download',
    component: () => import('@/views/download/index.vue'),
    meta: {
      title: '下载中心',
    },
  },
  // ============================================  管理页面  ============================================
  {
    path: '/manager',
    name: 'Manager',
    component: () => import('@/views/manager/index.vue'),
    meta: {
      title: '管理中心',
    },
  },
]

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

// router.beforeEach(async (to, from, next) => {
//   const {useNavStore} = await import('@/store/nav.js')
//   const navStore = useNavStore()
//   navStore.setLoad(true)
//   next()
// })

router.afterEach((to, from) => {
  // 只有路径变化时才滚动到顶部
  if (to.path !== from.path) {
    requestAnimationFrame(() => {
      window.scrollTo({top: 0, behavior: 'instant'})
    })
  }
})

export default router
