"use strict";

exports.__esModule = true;
exports.ListDragAndDropContext = 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 _mobxReactLite = require("mobx-react-lite");
var _DragAndDropAnnouncements = require("../DragAndDrop/DragAndDropAnnouncements");
var _react2 = require("@wix/bex-core/react");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/ListDragAndDrop/ListDragAndDropContext.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 _ListDragAndDropContext(props) {
  const {
    state: parentState,
    children,
    onSubmit
  } = props;
  const {
    keyedItems
  } = parentState.collection;
  const state = parentState.collectionDragAndDropState;
  const {
    dnd
  } = state;
  const {
    modalsContainerRef
  } = (0, _react2.usePageContext)();
  const pointerSensor = (0, _core.useSensor)(_core.PointerSensor, {
    activationConstraint: dnd.activationConstraint
  });
  const keyboardSensor = (0, _core.useSensor)(_core.KeyboardSensor, {
    keyboardCodes: dnd.keyboardCodes,
    coordinateGetter: _sortable.sortableKeyboardCoordinates
  });

  // 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(), []);
  dnd.onSubmit = onSubmit;
  return /*#__PURE__*/_react.default.createElement(_core.DndContext, {
    sensors: sensors,
    autoScroll: {
      activator: _core.AutoScrollActivator.DraggableRect,
      acceleration: 4
    },
    accessibility: {
      container: modalsContainerRef.current,
      announcements: dnd.nullAnnouncements,
      screenReaderInstructions: {
        draggable: ''
      },
      restoreFocus: false
    },
    collisionDetection: _core.closestCenter,
    modifiers: [_modifiers.restrictToWindowEdges],
    cancelDrop: ev => dnd.beforeDrop(ev),
    onDragMove: ev => {
      dnd.onDragMove(ev);
    },
    onDragStart: ev => {
      dnd.onDragStart(ev);
    },
    onDragEnd: ev => {
      dnd.onDragEnd(ev);
    },
    onDragCancel: () => {
      dnd.onDragCancel();
    },
    onDragOver: ev => {
      dnd.onDragOver(ev);
    },
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 68,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement(_sortable.SortableContext, {
    items: keyedItems,
    strategy: _sortable.verticalListSortingStrategy,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 101,
      columnNumber: 7
    }
  }, children, /*#__PURE__*/_react.default.createElement(_DragAndDropAnnouncements.DragAndDropAnnouncements, {
    state: dnd,
    dataHook: "list-dnd-live-region",
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 106,
      columnNumber: 9
    }
  })));
}
const ListDragAndDropContext = exports.ListDragAndDropContext = (0, _mobxReactLite.observer)(_ListDragAndDropContext);
//# sourceMappingURL=ListDragAndDropContext.js.map