function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
import { HolderOutlined } from "@ant-design/icons";
import { Tooltip } from "antd";
import React, { useContext } from "react";
import { I18nContext } from "../../../I18n";
import { useEditorStore } from "../store";
export var DragHandle = function DragHandle(props) {
    var _editorProps_drag;
    var ref = React.useRef(null);
    var _useEditorStore = useEditorStore(), store = _useEditorStore.store, editorProps = _useEditorStore.editorProps, readonly = _useEditorStore.readonly;
    var locale = useContext(I18nContext).locale;
    if (!store) return null;
    if (readonly === true) return null;
    if ((editorProps === null || editorProps === void 0 ? void 0 : (_editorProps_drag = editorProps.drag) === null || _editorProps_drag === void 0 ? void 0 : _editorProps_drag.enable) !== true) return null;
    return /*#__PURE__*/ React.createElement(Tooltip, {
        title: (locale === null || locale === void 0 ? void 0 : locale.dragToMove) || '拖拽移动'
    }, /*#__PURE__*/ React.createElement("span", {
        "data-drag-handle": true,
        "data-testid": "drag-handle",
        style: _object_spread({}, props.style),
        contentEditable: false,
        ref: ref,
        onMouseDown: function onMouseDown(e) {
            var _parent_parentElement;
            var parent = ref.current.parentElement;
            if (((_parent_parentElement = parent.parentElement) === null || _parent_parentElement === void 0 ? void 0 : _parent_parentElement.dataset.be) === 'list-item') {
                if (!parent.previousSibling || parent.previousSibling.hasAttribute('data-check-item')) {
                    parent = parent.parentElement;
                }
            }
            e.stopPropagation();
            parent.draggable = true;
            store.draggedElement = parent;
        }
    }, /*#__PURE__*/ React.createElement("div", {
        "data-drag-icon": true
    }, /*#__PURE__*/ React.createElement(HolderOutlined, null))));
};
