"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/hooks/useBreakpoint/index.tsx
var useBreakpoint_exports = {};
__export(useBreakpoint_exports, {
  DEFAULT_BREAKPOINTS: () => DEFAULT_BREAKPOINTS,
  useBreakpoint: () => useBreakpoint
});
module.exports = __toCommonJS(useBreakpoint_exports);

// src/hooks/useBreakpoint/useBreakpoint.tsx
var import_mobius_hooks = require("@simplybusiness/mobius-hooks");
var import_react = require("react");
var DEFAULT_BREAKPOINTS = [
  { size: "xs", value: 320 },
  { size: "sm", value: 480 },
  { size: "md", value: 670 },
  { size: "lg", value: 960 },
  { size: "xl", value: 1200 },
  { size: "xxl", value: 1320 }
];
var PASSIVE = { passive: true };
var getBreakpoint = (breakpoints, windowWidth) => {
  const closest = breakpoints.findIndex(
    (breakpoint) => breakpoint.value >= windowWidth + 1
  );
  const smallest = breakpoints[0];
  const largest = breakpoints[breakpoints.length - 1];
  const match = breakpoints[closest - 1];
  if (closest === 0) return smallest;
  if (closest === -1) return largest;
  return match;
};
var useBreakpoint = (customBreakpoints) => {
  const isClientSide = (0, import_mobius_hooks.useIsClient)();
  const breakpoints = customBreakpoints || DEFAULT_BREAKPOINTS;
  const defaultBreakpoint = breakpoints[0];
  const [windowWidth, setWindowWidth] = (0, import_react.useState)(
    typeof globalThis?.window !== "undefined" ? window.innerWidth : defaultBreakpoint.value
  );
  (0, import_mobius_hooks.useWindowEvent)("resize", () => setWindowWidth(window.innerWidth), PASSIVE);
  const debouncedWidth = (0, import_mobius_hooks.useDebouncedValue)(windowWidth, 200);
  const currentBreakpoint = (0, import_react.useMemo)(
    () => !isClientSide || breakpoints.length === 0 ? defaultBreakpoint : getBreakpoint(breakpoints, debouncedWidth),
    [isClientSide, breakpoints, defaultBreakpoint, debouncedWidth]
  );
  const up = (0, import_react.useCallback)(
    (size) => {
      const sizeIndex = breakpoints.findIndex((item) => item.size === size);
      if (sizeIndex === -1) {
        return false;
      }
      const currentIndex = breakpoints.findIndex(
        (item) => item.size === currentBreakpoint.size
      );
      return currentIndex >= sizeIndex;
    },
    [currentBreakpoint, breakpoints]
  );
  const down = (0, import_react.useCallback)(
    (size) => {
      const sizeIndex = breakpoints.findIndex((item) => item.size === size);
      if (sizeIndex === -1) {
        return true;
      }
      const currentIndex = breakpoints.findIndex(
        (item) => item.size === currentBreakpoint.size
      );
      return currentIndex <= sizeIndex;
    },
    [currentBreakpoint, breakpoints]
  );
  return {
    breakpoint: currentBreakpoint,
    up,
    down
  };
};
//# sourceMappingURL=index.js.map
