/**
 * 断点范围检查 Hooks
 */

import { useMemo } from 'react';
import { useBreakpoint } from './useBreakpoint';
import { FineBreakpointKey, isBreakpointGTE, isBreakpointLT } from './constants';

/**
 * 检查当前断点是否大于等于目标断点
 * 
 * @example
 * const isMediumUp = useBreakpointGTE('md');
 */
export function useBreakpointGTE(target: FineBreakpointKey): boolean {
  const { fineBreakpoint } = useBreakpoint();
  return useMemo(() => isBreakpointGTE(fineBreakpoint, target), [fineBreakpoint, target]);
}

/**
 * 检查当前断点是否小于目标断点
 * 
 * @example
 * const isMobileOnly = useBreakpointLT('lg');
 */
export function useBreakpointLT(target: FineBreakpointKey): boolean {
  const { fineBreakpoint } = useBreakpoint();
  return useMemo(() => isBreakpointLT(fineBreakpoint, target), [fineBreakpoint, target]);
}

/**
 * 检查当前是否在指定断点范围内
 * 
 * @example
 * const isTabletRange = useBreakpointBetween('md', 'xl');
 */
export function useBreakpointBetween(
  min: FineBreakpointKey,
  max: FineBreakpointKey
): boolean {
  const { fineBreakpoint } = useBreakpoint();
  return useMemo(
    () => isBreakpointGTE(fineBreakpoint, min) && !isBreakpointGTE(fineBreakpoint, max),
    [fineBreakpoint, min, max]
  );
}
