/**
 * useOrientation Hook
 * 方向检测 - 检测设备方向
 */

import { useMemo } from 'react';
import { useWindowDimensions } from './useScreenSize';
import type { Orientation } from './types';

/**
 * 获取屏幕方向
 */
export function getOrientation(width: number, height: number): Orientation {
  return width > height ? 'landscape' : 'portrait';
}

/**
 * 方向检测 Hook
 * 提供便捷的方向检测方法
 * 
 * @returns 方向信息对象
 * 
 * @example
 * const { orientation, isPortrait, isLandscape } = useOrientation();
 */
export function useOrientation(): {
  orientation: Orientation;
  isPortrait: boolean;
  isLandscape: boolean;
} {
  const { width, height } = useWindowDimensions();
  
  return useMemo(() => {
    const orientation = getOrientation(width, height);
    return {
      orientation,
      isPortrait: orientation === 'portrait',
      isLandscape: orientation === 'landscape',
    };
  }, [width, height]);
}

export default useOrientation;
