/**
 * 窗口尺寸 Hook
 * 提供屏幕尺寸监听
 */

import { useState, useEffect } from 'react';
import { Dimensions, ScaledSize } from 'react-native';

/**
 * 获取窗口尺寸，支持屏幕旋转响应
 * 替代 Dimensions.get('window')，提供实时尺寸更新
 */
export function useWindowDimensions(): ScaledSize {
  const [dimensions, setDimensions] = useState(() => Dimensions.get('window'));

  useEffect(() => {
    const subscription = Dimensions.addEventListener('change', ({ window }) => {
      setDimensions(window);
    });

    return () => {
      subscription.remove();
    };
  }, []);

  return dimensions;
}
