import React, { useEffect } from 'react';
import { AutoScrollActivator, closestCenter, DndContext, KeyboardSensor, PointerSensor, useSensor, useSensors, } from '@wix/wix-style-react-incubator/dnd-kit/core';
import { SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy, } from '@wix/wix-style-react-incubator/dnd-kit/sortable';
import { restrictToWindowEdges } from '@wix/wix-style-react-incubator/dnd-kit/modifiers';
import { observer } from 'mobx-react-lite';
import { DragAndDropAnnouncements } from '../DragAndDrop/DragAndDropAnnouncements';
import { usePageContext } from '@wix/bex-core/react';
function _ListDragAndDropContext(props) {
    const { state: parentState, children, onSubmit } = props;
    const { keyedItems } = parentState.collection;
    const state = parentState.collectionDragAndDropState;
    const { dnd } = state;
    const { modalsContainerRef } = usePageContext();
    const pointerSensor = useSensor(PointerSensor, {
        activationConstraint: dnd.activationConstraint,
    });
    const keyboardSensor = useSensor(KeyboardSensor, {
        keyboardCodes: dnd.keyboardCodes,
        coordinateGetter: sortableKeyboardCoordinates,
    });
    // in jsdom we mock drag-and-drop by setting a custom events to draggable elements
    const sensors = useSensors(...(process.env.NODE_ENV === 'test' ? [] : [pointerSensor, keyboardSensor]));
    useEffect(() => state.init(), []);
    dnd.onSubmit = onSubmit;
    return (React.createElement(DndContext, { sensors: sensors, autoScroll: {
            activator: AutoScrollActivator.DraggableRect,
            acceleration: 4,
        }, accessibility: {
            container: modalsContainerRef.current,
            announcements: dnd.nullAnnouncements,
            screenReaderInstructions: {
                draggable: '',
            },
            restoreFocus: false,
        }, collisionDetection: closestCenter, 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);
        } },
        React.createElement(SortableContext, { items: keyedItems, strategy: verticalListSortingStrategy },
            children,
            React.createElement(DragAndDropAnnouncements, { state: dnd, dataHook: "list-dnd-live-region" }))));
}
export const ListDragAndDropContext = observer(_ListDragAndDropContext);
//# sourceMappingURL=ListDragAndDropContext.js.map