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

const router = createRouter({
  history: createWebHistory(),
  scrollBehavior: () => ({ left: 0, top: 0 }),
  routes: [
    // ==================== 公开路由 ====================
    {
      path: '/login',
      name: 'Login',
      component: () => import('@/views/login/index.vue'),
      meta: { title: '登录', hidden: true }
    },
    {
      path: '/404',
      name: 'NotFound',
      component: () => import('@/views/error/404.vue'),
      meta: { title: '404', hidden: true }
    },

    // ==================== 仪表盘 ====================
    {
      path: '/',
      component: () => import('@/layouts/BasicLayout.vue'),
      redirect: '/dashboard',
      meta: { order: 0 },
      children: [
        {
          path: '/dashboard',
          name: 'Dashboard',
          component: () => import('@/views/dashboard/index.vue'),
          meta: { title: '仪表盘', icon: 'Odometer', keepAlive: true }
        }
      ]
    },

    // ==================== 商品管理 ====================
    {
      path: '/product',
      component: () => import('@/layouts/BasicLayout.vue'),
      redirect: '/product/list',
      meta: { title: '商品管理', icon: 'Goods' },
      children: [
        {
          path: '/product/list',
          name: 'ProductList',
          component: () => import('@/views/product/list.vue'),
          meta: { title: '商品列表', icon: 'List' }
        },
        {
          path: '/product/category',
          name: 'ProductCategory',
          component: () => import('@/views/product/category.vue'),
          meta: { title: '商品分类', icon: 'Menu' }
        }
      ]
    },

    // ==================== 订单管理 ====================
    {
      path: '/order',
      component: () => import('@/layouts/BasicLayout.vue'),
      redirect: '/order/list',
      children: [
        {
          path: '/order/list',
          name: 'OrderList',
          component: () => import('@/views/order/list.vue'),
          meta: { title: '订单管理', icon: 'Document' }
        }
      ]
    },

    // ==================== 营销管理 ====================
    {
      path: '/marketing',
      component: () => import('@/layouts/BasicLayout.vue'),
      redirect: '/marketing/coupon',
      meta: { title: '营销管理', icon: 'Present' },
      children: [
        {
          path: '/marketing/coupon',
          name: 'CouponList',
          component: () => import('@/views/coupon/list.vue'),
          meta: { title: '优惠券', icon: 'Ticket' }
        },
        {
          path: '/marketing/seckill',
          name: 'SeckillList',
          component: () => import('@/views/seckill/list.vue'),
          meta: { title: '限时抢购', icon: 'AlarmClock' }
        }
      ]
    },

    // ==================== 系统管理 ====================
    {
      path: '/system',
      component: () => import('@/layouts/BasicLayout.vue'),
      redirect: '/system/admin',
      meta: { title: '系统管理', icon: 'Setting', order: 1 },
      children: [
        {
          path: '/system/admin',
          name: 'AdminList',
          component: () => import('@/views/admin/index.vue'),
          meta: { title: '管理员管理', icon: 'UserFilled' }
        },
        {
          path: '/system/user',
          name: 'UserList',
          component: () => import('@/views/user/list.vue'),
          meta: { title: '用户管理', icon: 'User' }
        },
        {
          path: '/system/notice/list',
          name: 'NoticeList',
          component: () => import('@/views/notice/list.vue'),
          meta: { title: '系统公告', icon: 'Bell' }
        },
        {
          path: '/system/banner/list',
          name: 'BannerList',
          component: () => import('@/views/banner/list.vue'),
          meta: { title: '轮播图管理', icon: 'Picture' }
        },
        {
          path: '/system/profile',
          name: 'Profile',
          component: () => import('@/views/profile/index.vue'),
          meta: { title: '个人中心', icon: 'User', hidden: true }
        }
      ]
    },

    // ==================== 客服消息 ====================
    {
      path: '/chat',
      component: () => import('@/layouts/BasicLayout.vue'),
      redirect: '/chat/list',
      children: [
        {
          path: '/chat/list',
          name: 'ChatList',
          component: () => import('@/views/chat/list.vue'),
          meta: { title: '客服消息', icon: 'ChatDotRound' }
        }
      ]
    },

    // ==================== 404 兜底（放最后） ====================
    {
      path: '/:pathMatch(.*)*',
      redirect: '/404'
    }
  ]
})

export default router
