/**
 * 路由工具函数
 * 用于获取项目中所有有效的路由路径
 */

/**
 * 获取所有有效的路由路径
 * @returns {Array} 有效路径数组
 */
export function getAllValidPaths() {
  const validPaths = [
    // 主要页面路径
    '/',
    '/home',
    '/miningAccount',
    '/readOnlyDisplay',
    '/reportBlock',
    '/broadcast',
    '/userManagement',
    '/userDetails',
    '/rate',
    '/allocationExplanation',
    '/apiFile',
    '/customerService',
    '/ServiceTerms',
    '/submitWorkOrder',
    '/workOrderRecords',
    '/userWorkDetails',
    '/workOrderBackend',
    '/BKWorkDetails',
    '/dataDisplay',
    '/alerts',
    '/helpCenter',
    '/commonProblem',
    '/announcementDetails',
    '/searchResult',
    '/announcements',
    '/announcementDetails',
    
    // 个人中心子页面
    '/personalCenter',
    '/personalCenter/personalMining',
    '/personalCenter/readOnly',
    '/personalCenter/securitySetting',
    '/personalCenter/personal',
    '/personalCenter/miningReport',
    '/personalCenter/personalAPI',
    
    // 接入矿池页面
    '/AccessMiningPool',
    '/AccessMiningPool/nexaAccess',
    '/AccessMiningPool/rxdAccess',
    '/AccessMiningPool/monaAccess',
    '/AccessMiningPool/grsAccess',
    '/AccessMiningPool/dgbqAccess',
    '/AccessMiningPool/dgboAccess',
    '/AccessMiningPool/dgbsAccess',
    // '/AccessMiningPool/enxAccess',
    '/AccessMiningPool/alphminingPool',
    
    // 独立页面
    '/login',
    '/register',
    '/simulation',
    '/resetPassword',
    '/404'
  ];
  
  return validPaths;
}

/**
 * 验证路径是否有效
 * @param {string} path - 要验证的路径
 * @returns {boolean} 是否为有效路径
 */
export function isValidPath(path) {
  if (!path || typeof path !== 'string') {
    return false;
  }
  
  const trimmedPath = path.trim();
  
  // 主页路径的特殊处理
  if (trimmedPath === '/' || trimmedPath === '') {
    return true;
  }
  
  // 去除开头的斜杠进行标准化
  const normalizedPath = trimmedPath.startsWith('/') ? trimmedPath.substring(1) : trimmedPath;
  
  const validPaths = getAllValidPaths();
  
  // 检查标准化路径是否匹配
  const pathsWithoutSlash = validPaths.map(p => p.replace(/^\//, '')).filter(p => p !== '');
  
  return pathsWithoutSlash.includes(normalizedPath);
}

/**
 * 获取路径建议列表（用于错误提示或自动完成）
 * @param {string} input - 用户输入的路径
 * @returns {Array} 建议的路径列表
 */
export function getPathSuggestions(input) {
  if (!input) {
    return getAllValidPaths().slice(0, 10); // 返回前10个路径作为建议
  }
  
  const validPaths = getAllValidPaths();
  const normalizedInput = input.toLowerCase().trim();
  
  // 查找包含输入内容的路径
  return validPaths.filter(path => 
    path.toLowerCase().includes(normalizedInput)
  ).slice(0, 5); // 最多返回5个建议
} 