"use strict";

exports.__esModule = true;
exports.useTableSyncProps = useTableSyncProps;
var _providers = require("../../providers");
var _react = require("react");
var _react2 = require("@wix/bex-core/react");
var _useTagsBulkAssignUtils = require("../Tags/useTagsBulkAssignUtils");
var _mobx = require("mobx");
function useTableSyncProps(props) {
  var _state$tableDragAndDr;
  const {
    state,
    scrollElement: scrollElementProp
  } = props;
  const {
    scrollableContentRef
  } = (0, _providers.useScrollableContentContext)();
  const {
    modalsContainerRef
  } = (0, _react2.usePageContext)();
  const [scrollElement, setScrollElement] = (0, _react.useState)(() => scrollElementProp ?? (scrollableContentRef == null ? void 0 : scrollableContentRef.current));
  (0, _react.useState)(() => {
    var _props$dragAndDrop;
    (_props$dragAndDrop = props.dragAndDrop) == null || _props$dragAndDrop.setStateObject({
      state,
      modalsContainerRef
    });
  });
  const collectionDragAndDropState = (_state$tableDragAndDr = state.tableDragAndDropState) == null ? void 0 : _state$tableDragAndDr.dragAndDrop;
  if (collectionDragAndDropState) {
    collectionDragAndDropState.dragAndDropCancel = props.dragAndDropCancel;
  }
  (0, _useTagsBulkAssignUtils.useTagsBulkAssignUtils)({
    state
  });
  (0, _react.useEffect)(() => {
    const {
      collection
    } = state;
    const scrollableContent = scrollElementProp ?? (scrollableContentRef == null ? void 0 : scrollableContentRef.current);
    if (scrollableContent) {
      setScrollElement(scrollableContent);
      (0, _mobx.runInAction)(() => {
        collection.scrollableContent = scrollableContent instanceof HTMLElement ? scrollableContent : scrollableContent.current;
      });
    }
    return () => {
      (0, _mobx.runInAction)(() => {
        collection.scrollableContent = null;
      });
    };
  }, [scrollElementProp]);
  return {
    scrollElement
  };
}
//# sourceMappingURL=useTableSyncProps.js.map