"use strict";

exports.__esModule = true;
exports.useGridBaseSyncProps = useGridBaseSyncProps;
var _react = require("react");
var _mobx = require("mobx");
var _state = require("../../state");
var _providers = require("../../providers");
var _react2 = require("@wix/bex-core/react");
function useGridBaseSyncProps(props) {
  const {
    state,
    renderAddItem,
    preset,
    dragAndDrop,
    range,
    layoutType,
    imagePlacement
  } = props;
  const {
    scrollableContentRef
  } = (0, _providers.useScrollableContentContext)();
  const {
    modalsContainerRef
  } = (0, _react2.usePageContext)();
  (0, _react.useState)(() => {
    var _props$dragAndDrop;
    (_props$dragAndDrop = props.dragAndDrop) == null || _props$dragAndDrop.setStateObject({
      state,
      modalsContainerRef
    });
  });
  const collectionDragAndDropState = state.collectionDragAndDropState;
  if (collectionDragAndDropState) {
    collectionDragAndDropState.dragAndDropCancel = props.dragAndDropCancel;
  }
  (0, _react.useEffect)(() => {
    const {
      collection
    } = state;
    const scrollableContent = scrollableContentRef == null ? void 0 : scrollableContentRef.current;
    if (scrollableContent) {
      collection.scrollableContent = scrollableContent;
    }
    return () => {
      collection.scrollableContent = null;
    };
  }, []);
  (0, _react.useEffect)(() => {
    (0, _mobx.runInAction)(() => {
      state.trailingItemsCount = [renderAddItem].filter(Boolean).length;
    });
  }, [renderAddItem]);
  (0, _react.useEffect)(() => {
    (0, _mobx.runInAction)(() => {
      state._localLimit = range == null ? void 0 : range.length;
      state._localStart = (range == null ? void 0 : range.start) ?? 0;
    });
  }, [range]);
  (0, _react.useEffect)(() => {
    (0, _mobx.runInAction)(() => {
      state.preset = preset ?? 'title';
    });
  }, [preset]);
  (0, _react.useEffect)(() => {
    (0, _mobx.runInAction)(() => {
      state._draggable = dragAndDrop ? 'draggable' : 'none';
    });
  }, [dragAndDrop]);
  (0, _react.useEffect)(() => {
    (0, _mobx.runInAction)(() => {
      state.layoutType = layoutType ?? 'grid';
    });
  }, [layoutType]);
  (0, _react.useEffect)(() => {
    (0, _mobx.runInAction)(() => {
      const sizePreset = imagePlacement ? _state.gridSizePresets[imagePlacement] : undefined;
      if (!sizePreset) {
        return;
      }
      state._sizePreset = sizePreset;
    });
  }, [imagePlacement]);
}
//# sourceMappingURL=useGridBaseSyncProps.js.map