import { useRef as A, useEffect as S } from "react";
import { expandingParentContainer as v } from "../helpers/expandingParentContainer.js";
import { shrinkingParentContainer as C } from "../helpers/shrinkingParentContainer.js";
const x = (g) => {
  const {
    containerElement: f,
    containerSize: t,
    bounds: n,
    minWindowWidth: l,
    minWindowHeight: d,
    stateRef: e,
    wrapperRef: c,
    setCurrentState: w,
    allowHeightResizeContainer: p,
    allowWidthResizeContainer: m
  } = g, o = A(void 0);
  S(() => {
    if (!f || !t || !c.current || e.current?.dragging || e.current?.resizing || t.containerHeight === 0 && t.containerWidth === 0)
      return;
    o.current || (o.current = { ...t });
    const r = { ...e.current }, h = (a, z = !1, W) => {
      if (e.current?.containerSize && c.current) {
        const s = `container${a}`, i = t[s], u = W[s];
        i > u ? v(
          r,
          i,
          a,
          i - u,
          n
        ) : i < u && C(
          r,
          e.current,
          i,
          c.current,
          a,
          z,
          l,
          d,
          i - u,
          n
        );
      }
    };
    h("Width", m, o.current), h("Height", p, o.current), (r.x !== e.current.x || r.y !== e.current.y || r.width !== e.current.width || r.height !== e.current.height || r.shrinkLeftAt !== e.current.shrinkLeftAt || r.shrinkTopAt !== e.current.shrinkTopAt || r.overflowWidthAt !== e.current.overflowWidthAt || r.overflowHeightAt !== e.current.overflowHeightAt) && (e.current = {
      ...e.current,
      ...r
    }, w(r)), o.current = { ...t };
  }, [
    f,
    c.current,
    n?.left,
    n?.top,
    n?.right,
    n?.bottom,
    t?.containerWidth,
    t?.containerHeight
  ]);
};
export {
  x as useRNDDimensionEffects
};
