import { createRouter, createWebHistory } from 'vue-router'
import { useAuthStore } from '../stores/auth'
import Login from '../views/Login.vue'
import Downloader from '../views/Downloader.vue'
import Settings from '../views/Settings.vue'
import History from '../views/History.vue'

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: { requiresAuth: false }
  },
  {
    path: '/downloader',
    name: 'Downloader',
    component: Downloader,
    meta: { requiresAuth: true }
  },
  {
    path: '/settings',
    name: 'Settings',
    component: Settings,
    meta: { requiresAuth: true }
  },
  {
    path: '/history',
    name: 'History',
    component: History,
    meta: { requiresAuth: true }
  }
]

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

// 路由守卫
// router.beforeEach((to, from, next) => {
//   const authStore = useAuthStore()
  
//   // 初始化认证状态
//   if (!authStore.isAuthenticated) {
//     authStore.initialize()
//   }
  
//   if (to.meta.requiresAuth && !authStore.isAuthenticated) {
//     next('/login')
//   } else if (to.path === '/login' && authStore.isAuthenticated) {
//     next('/downloader')
//   } else {
//     next()
//   }
// })

export default router
