// 从 vue-router 导入 createRouter（创建路由实例）和 createWebHistory（使用 HTML5 History 模式）
import { createRouter, createWebHistory } from 'vue-router'

// 导入组件
import Home from '@/views/user/Home.vue'
import Search from '@/views/user/Search.vue'
import FrontLayout from '@/views/user/FrontLayout.vue'
import Detail from '@/views/user/detail.vue'
import Type from '@/views/user/type.vue'
import Shopping from '@/views/user/Shopping.vue'
import Orders from '@/views/user/orders.vue'
import Location from '@/views/user/location.vue'
import SpendingChart from '@/views/user/SpendingChart.vue'
import About from '@/views/user/About.vue'
import Contact from '@/views/user/Contact.vue'

// 合并后的路由配置
const routes = [
  {
    path: '/user',
    component: FrontLayout,
    children: [
      {
        path: '',
        name: 'UserHome',
        component: Home,
      },
      {
        path: 'search',
        name: 'Search',
        component: Search,
      },
      {
        path: 'charts',
        name: 'SpendingChart',
        component: SpendingChart,
      },
      {
        path: 'detail/:id', // 路径包含动态参数 :id
        name: 'Detail', // 路由名称
        component: Detail, // 映射到 detail.vue 组件
        props: true, // 允许通过 props 传递路由参数
      },
      {
        path: 'type',
        name: 'Type',
        component: Type,
        props: (route: { query: { category: any; name: any } }) => ({
          category: route.query.category,
          name: route.query.name,
        }),
      },
      {
  path: '/alipay-result',
  name: 'AlipayResult',
  component: () => import('@/views/user/AlipayResult.vue')
  },
      {
        path: 'shopping',
        name: 'Shopping',
        component: Shopping,
      },
      {
        path: 'orders',
        name: 'Orders',
        component: Orders,
      },
      {
        path: 'location',
        name: 'Location',
        component: Location,
      },
      {
        path: 'about',
        name: 'About',
        component: About,
      },
      {
        path: 'contact',
        name: 'Contact',
        component: Contact,
      },
    ],
  },
]

// 创建路由实例
export const router = createRouter({
  history: createWebHistory(),
  routes,
})

export default router
