/**
 * 路由调试工具
 * 用于诊断动态路由初始化问题
 */

export function debugRouteState() {
  const info = {
    timestamp: new Date().toISOString(),
    uiGlobalConfig: {
      exists: !!window.uiGlobalConfig,
      internalCode: window.uiGlobalConfig?.InternalCode || null,
      isAuthenticated: window.uiGlobalConfig?.IsAuthenticated || null,
      displayName: window.uiGlobalConfig?.DisplayName || null
    },
    localStorage: {
      token: !!localStorage.getItem('token'),
      dynamicRoutesCache: !!localStorage.getItem('dynamic_routes_cache'),
      userInfo: !!localStorage.getItem('userInfo')
    },
    router: {
      routes: (window as any).__VUE_ROUTER__?.getRoutes?.()?.length || 0,
      currentRoute: (window as any).__VUE_ROUTER__?.currentRoute?.value?.name || null
    }
  };

  console.group('🔍 路由状态调试信息');
  console.table(info);
  console.groupEnd();

  return info;
}

// 在全局暴露调试函数
if (typeof window !== 'undefined') {
  (window as any).debugRouteState = debugRouteState;
}

export function logRouteInitStep(step: string, details?: any) {
  console.log(`📍 路由初始化: ${step}`, details || '');
}

export function logRouteError(error: string, details?: any) {
  console.error(`❌ 路由错误: ${error}`, details || '');
}

export function logRouteSuccess(message: string, details?: any) {
  console.log(`✅ 路由成功: ${message}`, details || '');
}
