import { useRef as f, useState as S, useCallback as m, useEffect as g } from "react";
const h = "table-horizontal-scroll", R = (r) => {
  const o = r?.currentTarget;
  if (o && "scrollLeft" in o)
    return o.scrollLeft;
  const e = r?.target;
  return e && "scrollLeft" in e ? e.scrollLeft : 0;
}, z = ({ enabled: r, hasFooterCells: o = !0 }) => {
  const e = f(null), c = f(null), a = f(0), [L, i] = S(!1), [H, u] = S(!1), l = m(
    (s) => {
      const n = (t) => {
        if (t) {
          if (s === 0) {
            t.style.removeProperty("transform");
            return;
          }
          t.style.transform = `translateX(-${s}px)`;
        }
      };
      n(e.current), o ? n(c.current) : c.current && c.current.style.removeProperty("transform");
    },
    [o]
  ), p = m(
    (s) => {
      const n = s?.currentTarget, t = R(s), y = n ? Math.max(n.scrollWidth - n.clientWidth, 0) : 0, E = Math.max(y - t, 0);
      i(t > 0), u(E > 1), r && l(t), t !== a.current && (a.current = t, window.dispatchEvent(new CustomEvent(h)));
    },
    [r, l]
  );
  return g(() => {
    r || (a.current = 0, i(!1), u(!1), l(0));
  }, [r, l]), {
    handleBodyScroll: p,
    hasHorizontalScrollEndOffset: H,
    hasHorizontalScrollStartOffset: L,
    tableFooterRowRef: c,
    tableHeadRowRef: e
  };
};
export {
  h as TABLE_HORIZONTAL_SCROLL_EVENT,
  z as useHorizontalSectionSync
};
//# sourceMappingURL=useHorizontalSectionSync.js.map
