"use strict";

exports.__esModule = true;
exports.GridSortableContext = void 0;
var _react = _interopRequireWildcard(require("react"));
var _core = require("@wix/wix-style-react-incubator/dnd-kit/core");
var _sortable = require("@wix/wix-style-react-incubator/dnd-kit/sortable");
var _modifiers = require("@wix/wix-style-react-incubator/dnd-kit/modifiers");
var _CollectionContext = require("../CollectionContext");
var _mobxReactLite = require("mobx-react-lite");
var _sortableGridKeyboardCoordinates = require("./sortableGridKeyboardCoordinates");
var _DragAndDropAnnouncements = require("../DragAndDrop/DragAndDropAnnouncements");
var _react2 = require("@wix/bex-core/react");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/GridDragAndDropDndKit/GridSortableContext.tsx";
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); }
function _GridSortableContext(props) {
  const {
    state: grid,
    children,
    onSubmit
  } = props;
  const collection = (0, _CollectionContext.useCollectionContext)();
  const {
    modalsContainerRef
  } = (0, _react2.usePageContext)();
  const {
    result: {
      keyedItems
    }
  } = collection;
  const state = grid.collectionDragAndDropState;
  const pointerSensor = (0, _core.useSensor)(_core.PointerSensor, {
    activationConstraint: state.dnd.activationConstraint
  });
  const [coordinateGetter] = (0, _react.useState)(() => (0, _sortableGridKeyboardCoordinates.sortableGridKeyboardCoordinates)({
    containerDistanceThreshold: 0.1
  }));
  const keyboardSensor = (0, _core.useSensor)(_core.KeyboardSensor, {
    keyboardCodes: state.dnd.keyboardCodes,
    coordinateGetter
  });

  // in jsdom we mock drag-and-drop by setting a custom events to draggable elements
  const sensors = (0, _core.useSensors)(...(process.env.NODE_ENV === 'test' ? [] : [pointerSensor, keyboardSensor]));
  (0, _react.useEffect)(() => state.init(), []);
  state.dnd.onSubmit = onSubmit;
  return /*#__PURE__*/_react.default.createElement(_core.DndContext, {
    sensors: sensors,
    autoScroll: {
      activator: _core.AutoScrollActivator.DraggableRect,
      freeze: true,
      acceleration: 4,
      threshold: {
        y: 0.01,
        x: 0.2
      }
    },
    accessibility: {
      container: modalsContainerRef.current,
      announcements: state.dnd.nullAnnouncements,
      screenReaderInstructions: {
        draggable: ''
      },
      restoreFocus: false
    },
    collisionDetection: _core.closestCenter,
    modifiers: [_modifiers.restrictToWindowEdges],
    cancelDrop: ev => state.dnd.beforeDrop(ev),
    onDragStart: ev => {
      state.dnd.onDragStart(ev);
    },
    onDragMove: ev => {
      state.dnd.onDragMove(ev);
    },
    onDragEnd: ev => {
      state.dnd.onDragEnd(ev);
    },
    onDragCancel: () => {
      state.dnd.onDragCancel();
    },
    onDragOver: ev => {
      state.dnd.onDragOver(ev);
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 71,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_sortable.SortableContext, {
    items: keyedItems,
    strategy: _sortable.rectSortingStrategy,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 109,
      columnNumber: 7
    }
  }, children, /*#__PURE__*/_react.default.createElement(_DragAndDropAnnouncements.DragAndDropAnnouncements, {
    state: state.dnd,
    dataHook: "grid-dnd-live-region",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 111,
      columnNumber: 9
    }
  })));
}
const GridSortableContext = exports.GridSortableContext = (0, _mobxReactLite.observer)(_GridSortableContext);
//# sourceMappingURL=GridSortableContext.js.map