import { createRouter, createWebHistory } from 'vue-router'
import { useUserStore } from '@/stores/user'

// 在路由配置中添加个人中心路由
const routes = [
  { path: '/', meta: { title: '首页' }, name: 'Home', component: () => import('@/views/Home.vue') },
  { path: '/about', meta: { title: '公司介绍' }, name: 'About', component: () => import('@/views/About.vue') },
  { path: '/team', meta: { title: '团队介绍' }, name: 'Team', component: () => import('@/views/Team.vue') },
  { path: '/features', meta: { title: '公司特色' }, name: 'Features', component: () => import('@/views/Features.vue') },
  { path: '/careers', meta: { title: '加入我们' }, name: 'Careers', component: () => import('@/views/Careers.vue') },
]

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


export default router

router.beforeEach((to, from) => {
  // const userStore = useUserStore()
  // if (to.meta.requiresAuth && !userStore.user) {
  //   return { name: 'Login', query: { redirect: to.fullPath } }
  // }

  if (to.meta.title) {
    console.log('to.meta.title', to.meta)
    document.title = `${to.meta.title} | 上海酉佰`
  } else {
    document.title = `上海酉佰`
  }
})
