/**
 * 路由配置模块
 * 用于集中管理应用的路由配置
 */

// 主布局路由
export const mainRoutes = [
  // 根路径重定向到仪表盘
  {
    path: '/',
    redirect: '/dashboard',
    meta: {
      requiresAuth: true
    }
  },
  // 确保 /admin/ 路径也重定向到仪表盘（兼容旧版本）
  {
    path: '/admin/',
    redirect: '/dashboard',
    meta: {
      requiresAuth: true
    }
  },
  // 确保 /admin 路径也重定向到仪表盘（兼容旧版本）
  {
    path: '/admin',
    redirect: '/dashboard',
    meta: {
      requiresAuth: true
    }
  },
  {
    path: '/dashboard',
    name: 'Dashboard',
    component: () => import('../views/Dashboard.vue'),
    meta: {
      title: '系统概览',
      requiresAuth: true,
      icon: 'dashboard-outlined'
    }
  },
  {
    path: '/smart-devices',
    name: 'SmartDevices',
    redirect: '/smart-devices/eartag',
    meta: {
      title: '智能设备',
      requiresAuth: true,
      icon: 'SettingOutlined',
      permission: 'smart_device:view',
      menu: 'smart_device.main',
      isSubmenu: true
    },
    children: [
      {
        path: '/smart-devices/eartag',
        name: 'SmartEartag',
        component: () => import('../views/SmartEartag.vue'),
        meta: {
          title: '智能耳标',
          requiresAuth: true,
          permission: 'smart_eartag:view',
          menu: 'smart_device.eartag',
          parent: 'SmartDevices'
        }
      },
  
      {
        path: '/smart-devices/collar',
        name: 'SmartCollar',
        component: () => import('../views/SmartCollar.vue'),
        meta: {
          title: '智能项圈',
          requiresAuth: true,
          permission: 'smart_collar:view',
          menu: 'smart_device.collar',
          parent: 'SmartDevices'
        }
      },
      {
        path: '/smart-devices/host',
        name: 'SmartHost',
        component: () => import('../views/SmartHost.vue'),
        meta: {
          title: '智能主机',
          requiresAuth: true,
          permission: 'smart_host:view',
          menu: 'smart_device.host',
          parent: 'SmartDevices'
        }
      },
      {
        path: '/smart-devices/fence',
        name: 'ElectronicFence',
        component: () => import('../views/ElectronicFence.vue'),
        meta: {
          title: '电子围栏',
          requiresAuth: true,
          permission: 'smart_fence:view',
          menu: 'smart_device.fence',
          parent: 'SmartDevices'
        }
      }
    ]
  },
  {
    path: '/smart-alerts',
    name: 'SmartAlerts',
    redirect: '/smart-alerts/eartag',
    meta: {
      title: '智能预警总览',
      requiresAuth: true,
      icon: 'AlertOutlined',
      permission: 'smart_alert:view',
      menu: 'smart_alert.main',
      isSubmenu: true
    },
    children: [
      {
        path: '/smart-alerts/eartag',
        name: 'SmartEartagAlert',
        component: () => import('../views/SmartEartagAlert.vue'),
        meta: {
          title: '智能耳标预警',
          requiresAuth: true,
          permission: 'smart_eartag_alert:view',
          menu: 'smart_alert.eartag',
          parent: 'SmartAlerts'
        }
      },
      {
        path: '/smart-alerts/collar',
        name: 'SmartCollarAlert',
        component: () => import('../views/SmartCollarAlert.vue'),
        meta: {
          title: '智能项圈预警',
          requiresAuth: true,
          permission: 'smart_collar_alert:view',
          menu: 'smart_alert.collar',
          parent: 'SmartAlerts'
        }
      }
    ]
  },
  {
    path: '/cattle-management',
    name: 'CattleManagement',
    redirect: '/cattle-management/archives',
    meta: {
      title: '牛只管理',
      requiresAuth: true,
      icon: 'BugOutlined',
      permission: 'animal:view',
      menu: 'animal.management',
      isSubmenu: true
    },
    children: [
      {
        path: '/cattle-management/archives',
        name: 'CattleArchives',
        component: () => import('../views/Animals.vue'),
        meta: {
          title: '牛只档案',
          requiresAuth: true,
          permission: 'cattle:archives:view',
          menu: 'cattle.archives',
          parent: 'CattleManagement'
        }
      },
      {
        path: '/cattle-management/pens',
        name: 'CattlePens',
        component: () => import('../views/CattlePens.vue'),
        meta: {
          title: '栏舍设置',
          requiresAuth: true,
          permission: 'cattle:pens:view',
          menu: 'cattle.pens',
          parent: 'CattleManagement'
        }
      },
      {
        path: '/cattle-management/batches',
        name: 'CattleBatches',
        component: () => import('../views/CattleBatches.vue'),
        meta: {
          title: '批次设置',
          requiresAuth: true,
          permission: 'cattle:batches:view',
          menu: 'cattle.batches',
          parent: 'CattleManagement'
        }
      },
      {
        path: '/cattle-management/transfer-records',
        name: 'CattleTransferRecords',
        component: () => import('../views/CattleTransferRecords.vue'),
        meta: {
          title: '转栏记录',
          requiresAuth: true,
          permission: 'cattle:transfer:view',
          menu: 'cattle.transfer',
          parent: 'CattleManagement'
        }
      },
      {
        path: '/cattle-management/exit-records',
        name: 'CattleExitRecords',
        component: () => import('../views/CattleExitRecords.vue'),
        meta: {
          title: '离栏记录',
          requiresAuth: true,
          permission: 'cattle:exit:view',
          menu: 'cattle.exit',
          parent: 'CattleManagement'
        }
      }
    ]
  },

  {
    path: '/farm-management',
    name: 'FarmManagement',
    redirect: '/farm-management/info',
    meta: {
      title: '养殖场管理',
      requiresAuth: true,
      icon: 'HomeOutlined',
      permission: 'farm:view',
      menu: 'farm.main',
      isSubmenu: true
    },
    children: [
      {
        path: '/farm-management/info',
        name: 'FarmInfoManagement',
        component: () => import('../views/FarmInfoManagement.vue'),
        meta: {
          title: '养殖场信息管理',
          requiresAuth: true,
          permission: 'farm_info:view',
          menu: 'farm.info',
          parent: 'FarmManagement'
        }
      },
      {
        path: '/farm-management/pens',
        name: 'PenManagement',
        component: () => import('../views/PenManagement.vue'),
        meta: {
          title: '栏舍管理',
          requiresAuth: true,
          permission: 'pen:view',
          menu: 'farm.pens',
          parent: 'FarmManagement'
        }
      },
      {
        path: '/farm-management/users',
        name: 'Users',
        component: () => import('../views/Users.vue'),
        meta: {
          title: '用户管理',
          requiresAuth: true,
          permission: 'user:view',
          menu: 'farm.users',
          parent: 'FarmManagement'
        }
      },
      {
        path: '/farm-management/role-permissions',
        name: 'RolePermissions',
        component: () => import('../views/RolePermissions.vue'),
        meta: {
          title: '角色权限管理',
          requiresAuth: true,
          permission: 'role:view',
          menu: 'farm.role_permissions',
          parent: 'FarmManagement'
        }
      }
    ]
  },

  {
    path: '/system',
    name: 'System',
    redirect: '/system/config',
    meta: {
      title: '系统管理',
      requiresAuth: true,
      icon: 'setting-outlined',
      permission: 'system:view',
      menu: 'system.main',
      isSubmenu: true
    },
    children: [
      {
        path: '/system/config',
        name: 'SystemConfig',
        component: () => import('../views/System.vue'),
        meta: {
          title: '系统配置',
          requiresAuth: true,
          permission: 'system:config',
          menu: 'system.config',
          parent: 'System'
        }
      },
      {
        path: '/system/logs',
        name: 'FormLogManagement',
        component: () => import('../views/FormLogManagement.vue'),
        meta: {
          title: '表单日志管理',
          requiresAuth: true,
          permission: 'log:view',
          menu: 'system.logs',
          parent: 'System'
        }
      },
      {
        path: '/system/search-monitor',
        name: 'SearchMonitor',
        component: () => import('../views/SearchMonitor.vue'),
        meta: {
          title: '搜索监听数据查询',
          requiresAuth: true,
          permission: 'log:view',
          menu: 'system.search_monitor',
          parent: 'System'
        }
      },
      {
        path: '/system/operation-logs',
        name: 'OperationLogs',
        component: () => import('../views/OperationLogs.vue'),
        meta: {
          title: '操作日志',
          requiresAuth: true,
          permission: 'operation_log:view',
          menu: 'system.operation_logs',
          parent: 'System'
        }
      }
    ]
  },

]

// 认证相关路由
export const authRoutes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue'),
    meta: {
      title: '登录',
      requiresAuth: false,
      layout: 'blank'
    }
  }
]

// 错误页面路由
export const errorRoutes = [
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('../views/NotFound.vue'),
    meta: {
      title: '页面未找到',
      requiresAuth: false
    }
  }
]

// 导出所有路由
export default [
  ...authRoutes,
  ...mainRoutes,
  ...errorRoutes
]