import * as React from 'react';
/**
 * 创建水平轴限制 modifier
 * 让列拖拽预览固定在表格内，只能水平移动
 */
export 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, // 让预览贴着表格顶部
        };
    };
};
/**
 * 创建垂直轴限制 modifier
 * 让行拖拽预览固定在表格内，只能垂直移动
 */
export 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, // 让预览贴着表格左侧
        };
    };
};
/**
 * Hook: 创建拖拽 modifiers
 */
export 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,
    };
};
