"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TableWrapper = void 0;
var _react = _interopRequireWildcard(require("react"));
var _resizeObserverPolyfill = _interopRequireDefault(require("resize-observer-polyfill"));
var _classnames = _interopRequireDefault(require("classnames"));
var _types = require("../types");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const DEFAULT_TABLE_WIDTH = process.env.NODE_ENV === 'test' ? 600 : undefined;
const TableWrapper = ({
  className,
  testId,
  children,
  defaultWidth = DEFAULT_TABLE_WIDTH
}) => {
  const [width, setWidth] = (0, _react.useState)(defaultWidth);
  const wrapper = (0, _react.useRef)(null);
  (0, _react.useEffect)(() => {
    const outputWidth = () => {
      setWidth((wrapper.current?.offsetWidth || 0) - _types.COLUMN_SIZE.BORDER_OFFSET);
    };
    if (wrapper.current) {
      const observer = new _resizeObserverPolyfill.default(() => window.requestAnimationFrame(outputWidth));
      observer.observe(wrapper.current);
      return () => observer.disconnect();
    }
  }, []);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: (0, _classnames.default)('react-table-wrapper', className),
    "test-id": testId,
    ref: wrapper,
    children: width ? children({
      width
    }) : null
  });
};
exports.TableWrapper = TableWrapper;