"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 () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDragModifiers = exports.createVerticalAxisModifier = exports.createHorizontalAxisModifier = void 0;
const React = __importStar(require("react"));
/**
 * 创建水平轴限制 modifier
 * 让列拖拽预览固定在表格内，只能水平移动
 */
const createHorizontalAxisModifier = (containerRef) => {
    return ({ transform, draggingNodeRect }) => {
        var _a;
        const containerRect = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
        if (!containerRect || !draggingNodeRect)
            return transform;
        // 计算让预览贴着表格顶部需要的 y 偏移
        const offsetY = containerRect.top - (draggingNodeRect.top + transform.y);
        return {
            ...transform,
            y: transform.y + offsetY, // 让预览贴着表格顶部
        };
    };
};
exports.createHorizontalAxisModifier = createHorizontalAxisModifier;
/**
 * 创建垂直轴限制 modifier
 * 让行拖拽预览固定在表格内，只能垂直移动
 */
const createVerticalAxisModifier = (containerRef) => {
    return ({ transform, draggingNodeRect }) => {
        var _a;
        const containerRect = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
        if (!containerRect || !draggingNodeRect)
            return transform;
        // 计算让预览贴着表格左侧需要的 x 偏移
        const offsetX = containerRect.left - (draggingNodeRect.left + transform.x);
        return {
            ...transform,
            x: transform.x + offsetX, // 让预览贴着表格左侧
        };
    };
};
exports.createVerticalAxisModifier = createVerticalAxisModifier;
/**
 * Hook: 创建拖拽 modifiers
 */
const useDragModifiers = (containerRef) => {
    const restrictToHorizontalAxis = React.useCallback(({ transform, draggingNodeRect }) => {
        var _a;
        const containerRect = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
        if (!containerRect || !draggingNodeRect)
            return transform;
        const offsetY = containerRect.top - (draggingNodeRect.top + transform.y);
        return {
            ...transform,
            y: transform.y + offsetY,
        };
    }, []);
    const restrictToVerticalAxis = React.useCallback(({ transform, draggingNodeRect }) => {
        var _a;
        const containerRect = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
        if (!containerRect || !draggingNodeRect)
            return transform;
        const offsetX = containerRect.left - (draggingNodeRect.left + transform.x);
        return {
            ...transform,
            x: transform.x + offsetX,
        };
    }, []);
    return {
        restrictToHorizontalAxis,
        restrictToVerticalAxis,
    };
};
exports.useDragModifiers = useDragModifiers;
