"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CrosswalkDndComponent = void 0;
var react_1 = __importStar(require("react"));
var useDndBasicTableScrollModifier_1 = require("../../../hooks/useDndBasicTableScrollModifier");
var useDraggingCrosswalk_1 = require("../hooks/useDraggingCrosswalk");
var modifiers_1 = require("@dnd-kit/modifiers");
var core_1 = require("@dnd-kit/core");
var CrosswalkDragPreview_1 = require("../CrosswalkDragPreview");
var useTableDndKit_1 = require("react-components/dist/Table/hooks/useTableDndKit");
var CrosswalkDndComponent = function (_a) {
    var children = _a.children, tableRef = _a.tableRef, _b = _a.tableRowReorderingEnabled, tableRowReorderingEnabled = _b === void 0 ? false : _b;
    var _c = (0, useDndBasicTableScrollModifier_1.useDndBasicTableScrollModifier)({ tableRef: tableRef }), scrollModifier = _c.scrollModifier, stopScroll = _c.stopScroll;
    var _d = (0, useDraggingCrosswalk_1.useDraggingCrosswalk)(), draggingCrosswalk = _d.draggingCrosswalk, onDragEndCrosswalk = _d.onDragEnd, onCrosswalkDragStart = _d.onDragStart;
    var tableDnd = (0, useTableDndKit_1.useTableDndKit)({
        dndColumnReorderingEnabled: false,
        dndRowReorderingEnabled: tableRowReorderingEnabled
    });
    var onDragStart = (0, react_1.useCallback)(function (event) {
        onCrosswalkDragStart(event);
    }, [onCrosswalkDragStart]);
    var onDragEnd = (0, react_1.useCallback)(function () {
        onDragEndCrosswalk();
        stopScroll();
    }, [onDragEndCrosswalk, stopScroll]);
    var dndContextModifiers = (0, react_1.useMemo)(function () { return [scrollModifier]; }, [scrollModifier]);
    var crosswalkOverlayModifiers = (0, react_1.useMemo)(function () { return [modifiers_1.snapCenterToCursor]; }, []);
    return (react_1.default.createElement(core_1.DndContext, { sensors: tableDnd.sensors, collisionDetection: tableDnd.collisionDetection, measuring: tableDnd.measuring, autoScroll: tableDnd.autoScrollOptions, modifiers: dndContextModifiers, onDragStart: onDragStart, onDragEnd: onDragEnd },
        children,
        draggingCrosswalk ? (react_1.default.createElement(core_1.DragOverlay, { style: { width: 'max-content' }, modifiers: crosswalkOverlayModifiers, dropAnimation: null },
            react_1.default.createElement(CrosswalkDragPreview_1.CrosswalkDragPreview, { crosswalk: draggingCrosswalk }))) : null));
};
exports.CrosswalkDndComponent = CrosswalkDndComponent;
