"use strict";
"use client";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/Grid/Item.tsx
var Item_exports = {};
__export(Item_exports, {
  DEFAULT_SPAN: () => DEFAULT_SPAN,
  GridItem: () => GridItem,
  getBreakpointMap: () => getBreakpointMap
});
module.exports = __toCommonJS(Item_exports);
var import_react2 = require("react");
var import_dedupe = __toESM(require("classnames/dedupe"));

// 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
  };
};

// src/components/Grid/Item.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var getBreakpointMap = (config) => Object.entries(config).reduce(
  (prev, [key, value]) => {
    const previous = Object.values(prev);
    const lastDefined = previous[previous.length - 1];
    return { ...prev, [key]: value || lastDefined };
  },
  {}
);
var DEFAULT_SPAN = 12;
var GridItem = ({ ref, ...props }) => {
  const {
    breakpoint: { size: breakpointSize }
  } = useBreakpoint();
  const {
    span,
    xs = Array.isArray(span) ? DEFAULT_SPAN : span,
    sm,
    md,
    lg,
    xl,
    xxl,
    alignSelf,
    justifySelf,
    className,
    ...rest
  } = props;
  const breakpointMap = getBreakpointMap({
    xs,
    sm,
    md,
    lg,
    xl,
    xxl
  });
  const [responsiveSpan, setResponsiveSpan] = (0, import_react2.useState)();
  const classes = (0, import_dedupe.default)("mobius", "mobius-grid__item", className);
  (0, import_react2.useEffect)(() => {
    setResponsiveSpan(breakpointMap[breakpointSize]);
  }, [breakpointSize, breakpointMap]);
  const styles = {
    gridColumn: responsiveSpan ? `span ${responsiveSpan}` : void 0,
    alignSelf,
    justifySelf
  };
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref, style: { ...styles }, className: classes, ...rest });
};
GridItem.displayName = "GridItem";
//# sourceMappingURL=Item.js.map
