import { useState, useEffect } from 'react';
import { B as BreakpointXxl, a as BreakpointXl, b as BreakpointLg, c as BreakpointMd, d as BreakpointSm } from './primitive-DXlHdTFb.js';

const breakpoints = {
  sm: parseInt(BreakpointSm.value),
  md: parseInt(BreakpointMd.value),
  lg: parseInt(BreakpointLg.value),
  xl: parseInt(BreakpointXl.value),
  xxl: parseInt(BreakpointXxl.value)
};
const areBreakpointsDefined = Object.values(breakpoints).every(
  (breakpoint2) => breakpoint2
);
function getBreakpointFlags(name) {
  const breakpointOrder = ["xs", "sm", "md", "lg", "xl", "xxl"];
  const currentIndex = breakpointOrder.indexOf(name);
  return {
    xs: currentIndex >= 0,
    sm: currentIndex >= 1,
    md: currentIndex >= 2,
    lg: currentIndex >= 3,
    xl: currentIndex >= 4,
    xxl: currentIndex >= 5
  };
}
function breakpoint(name, min, max) {
  if (globalThis.innerWidth == null || globalThis.innerHeight == null) {
    return void 0;
  }
  const viewportWidth = globalThis.innerWidth;
  const viewportHeight = globalThis.innerHeight;
  if ((min == null || viewportWidth >= min) && (max == null || viewportWidth < max)) {
    return {
      name,
      min,
      max,
      orientation: viewportHeight > viewportWidth ? "portrait" : "landscape",
      innerWidth: viewportWidth,
      innerHeight: viewportHeight,
      ...getBreakpointFlags(name)
    };
  }
  return void 0;
}
const onResize = () => {
  if (!areBreakpointsDefined) {
    return;
  }
  const { sm, md, lg, xl, xxl } = breakpoints;
  return breakpoint("xs", void 0, sm) ?? breakpoint("sm", sm, md) ?? breakpoint("md", md, lg) ?? breakpoint("lg", lg, xl) ?? breakpoint("xl", xl, xxl) ?? breakpoint("xxl", xxl, void 0);
};
const useBreakpoint = (props) => {
  const [size, setSize] = useState(onResize);
  useEffect(() => {
    if (!areBreakpointsDefined || props?.disable) return;
    const updateSize = () => {
      setSize(onResize());
    };
    globalThis.addEventListener("resize", updateSize);
    return () => {
      globalThis.removeEventListener("resize", updateSize);
    };
  }, [props?.disable]);
  if (props?.disable) return;
  return size;
};

export { useBreakpoint as u };
//# sourceMappingURL=useBreakpoint-CeaUyHxh.js.map
