/**
 * useResponsive Hook (兼容层)
 * 
 * 此文件是为了保持向后兼容性而保留的，整合所有响应式功能。
 * 
 * 推荐使用新的专注 hooks：
 * - useBreakpoint() - 断点检测
 * - useScreenSize() - 屏幕尺寸
 * - useOrientation() - 方向检测
 * - usePlatform() - 平台检测
 * - useResponsiveValue() - 响应式值
 */

import { useMemo } from 'react';
import { useWindowDimensions } from './useScreenSize';
import { getBreakpoint, getFineBreakpoint } from './useBreakpoint';
import { getOrientation } from './useOrientation';
import { usePlatform } from './usePlatform';
import type { BreakpointKey, FineBreakpointKey, Orientation, PlatformInfo } from './types';

// ==================== 返回值类型 ====================
export interface ResponsiveInfo {
  // 基础尺寸
  width: number;
  height: number;
  
  // 基础断点
  breakpoint: BreakpointKey;
  isMobile: boolean;
  isTablet: boolean;
  isDesktop: boolean;
  isWide: boolean;
  isWideScreen: boolean;
  
  // 细粒度断点
  fineBreakpoint: FineBreakpointKey;
  isXS: boolean;
  isSM: boolean;
  isMD: boolean;
  isLG: boolean;
  isXL: boolean;
  is2XL: boolean;
  is3XL: boolean;
  is4XL: boolean;
  
  // 方向
  orientation: Orientation;
  isPortrait: boolean;
  isLandscape: boolean;
  
  // 平台检测
  platform: PlatformInfo;
}

/**
 * 响应式设计 Hook (兼容层)
 * 提供屏幕尺寸、断点、方向、平台检测等响应式信息
 * 
 * @deprecated 推荐使用新的专注 hooks
 * 
 * @returns ResponsiveInfo 响应式信息对象
 * 
 * @example
 * const { 
 *   width, height, 
 *   breakpoint, isMobile, isTablet, isDesktop, isWide,
 *   fineBreakpoint, isXS, isSM, isMD, isLG, isXL,
 *   orientation, isPortrait, isLandscape,
 *   platform: { isWeb, isIOS, isAndroid }
 * } = useResponsive();
 */
export function useResponsive(): ResponsiveInfo {
  const { width, height } = useWindowDimensions();
  const platform = usePlatform();

  return useMemo(() => {
    const breakpoint = getBreakpoint(width);
    const fineBreakpoint = getFineBreakpoint(width);
    const orientation = getOrientation(width, height);

    return {
      width,
      height,
      breakpoint,
      isMobile: breakpoint === 'mobile',
      isTablet: breakpoint === 'tablet',
      isDesktop: breakpoint === 'desktop',
      isWide: breakpoint === 'wide',
      isWideScreen: breakpoint === 'tablet' || breakpoint === 'desktop' || breakpoint === 'wide',
      fineBreakpoint,
      isXS: fineBreakpoint === 'xs',
      isSM: fineBreakpoint === 'sm',
      isMD: fineBreakpoint === 'md',
      isLG: fineBreakpoint === 'lg',
      isXL: fineBreakpoint === 'xl',
      is2XL: fineBreakpoint === '2xl',
      is3XL: fineBreakpoint === '3xl',
      is4XL: fineBreakpoint === '4xl',
      orientation,
      isPortrait: orientation === 'portrait',
      isLandscape: orientation === 'landscape',
      platform,
    };
  }, [width, height, platform]);
}

/**
 * 旧的 useResponsive 别名，保持完全向后兼容
 */
export const useLegacyResponsive = useResponsive;

export default useResponsive;
