"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    SortableItem: ()=>SortableItem,
    DraggableContext: ()=>DraggableContext,
    SortableProvider: ()=>SortableProvider,
    Sortable: ()=>Sortable,
    DragHandler: ()=>DragHandler,
    SortableContext: ()=>SortableContext
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const schema_namespaceObject = require("@tachybase/schema");
const tinycolor_namespaceObject = require("@ctrl/tinycolor");
const core_namespaceObject = require("@dnd-kit/core");
const react_namespaceObject = require("@floating-ui/react");
const external_classnames_namespaceObject = require("classnames");
var external_classnames_default = /*#__PURE__*/ __webpack_require__.n(external_classnames_namespaceObject);
const index_js_namespaceObject = require("../../antd/__builtins__/index.js");
const DraggableContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(null);
DraggableContext.displayName = 'DraggableContext';
const SortableContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(null);
SortableContext.displayName = 'SortableContext';
const SortableProvider = (props)=>{
    const { id, data, children } = props;
    const draggable = (0, core_namespaceObject.useDraggable)({
        id,
        data
    });
    const droppable = (0, core_namespaceObject.useDroppable)({
        id,
        data
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SortableContext.Provider, {
        value: {
            draggable,
            droppable
        },
        children: children
    });
};
const Sortable = /*#__PURE__*/ (0, external_react_namespaceObject.forwardRef)((props, ref)=>{
    var _draggable_active, _droppable_over;
    const { component, overStyle, style, children, openMode, ...others } = props;
    const { token } = (0, index_js_namespaceObject.useToken)();
    const { draggable, droppable } = (0, external_react_namespaceObject.useContext)(SortableContext);
    const { isOver, setNodeRef } = droppable;
    const mergedRef = (0, react_namespaceObject.useMergeRefs)([
        setNodeRef,
        ref
    ]);
    const droppableStyle = {
        ...style
    };
    if (isOver && (null == draggable ? void 0 : null === (_draggable_active = draggable.active) || void 0 === _draggable_active ? void 0 : _draggable_active.id) !== (null == droppable ? void 0 : null === (_droppable_over = droppable.over) || void 0 === _droppable_over ? void 0 : _droppable_over.id)) {
        droppableStyle['a' === component ? 'color' : 'background'] = new tinycolor_namespaceObject.TinyColor(token.colorSettings).setAlpha(0.15).toHex8String();
        Object.assign(droppableStyle, overStyle);
    }
    return /*#__PURE__*/ external_react_default().createElement(component || 'div', {
        role: 'none',
        ...others,
        className: external_classnames_default()('tb-sortable-designer', props.className),
        ref: mergedRef,
        style: droppableStyle
    }, children);
});
const useSortableItemProps = (props)=>{
    const id = useSortableItemId(props);
    const schema = (0, schema_namespaceObject.useFieldSchema)();
    if (props.schema) return {
        ...props,
        id
    };
    return {
        ...props,
        id,
        schema
    };
};
const useSortableItemId = (props)=>{
    const field = (0, schema_namespaceObject.useField)();
    if (props.id) return props.id;
    return field.address.toString();
};
const SortableItem = (0, schema_namespaceObject.observer)((props)=>{
    const { schema, id, eid, removeParentsIfNoChildren, ...others } = useSortableItemProps(props);
    const data = (0, external_react_namespaceObject.useMemo)(()=>({
            insertAdjacent: 'afterEnd',
            schema: schema,
            removeParentsIfNoChildren: null == removeParentsIfNoChildren || removeParentsIfNoChildren
        }), [
        schema,
        removeParentsIfNoChildren
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(SortableProvider, {
        id: id,
        data: data,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Sortable, {
            id: eid,
            ...others,
            ref: props.ref,
            children: props.children
        })
    });
}, {
    displayName: 'SortableItem',
    forwardRef: true
});
const DragHandler = (props)=>{
    const { draggable } = (0, external_react_namespaceObject.useContext)(SortableContext);
    const { attributes, listeners, setNodeRef } = draggable;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        style: {
            display: 'inline-block',
            width: 14,
            height: 14,
            lineHeight: '14px',
            textAlign: 'left'
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            ref: setNodeRef,
            style: {
                position: 'relative',
                zIndex: 1,
                lineHeight: 0,
                fontSize: 0,
                display: 'inline-block'
            },
            ...listeners,
            ...attributes,
            role: "none",
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                style: {
                    cursor: 'move',
                    fontSize: 14
                },
                children: props.children
            })
        })
    });
};
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
