"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    DndContext: ()=>DndContext
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const core_namespaceObject = require("@dnd-kit/core");
const external_react_i18next_namespaceObject = require("react-i18next");
const external_index_js_namespaceObject = require("../../../index.js");
const index_js_namespaceObject = require("../../hooks/index.js");
const useDragEnd = (props)=>{
    const { refresh } = (0, index_js_namespaceObject.useDesignable)();
    const api = (0, external_index_js_namespaceObject.useAPIClient)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    return (event)=>{
        var _active_data_current, _active_data, _over_data_current, _over_data, _over_data_current1, _over_data1, _over_data_current2, _over_data2, _over_data_current3, _over_data3, _over_data_current4, _over_data4, _over_data_current5, _over_data5;
        const { active, over } = event;
        const activeSchema = null == active ? void 0 : null === (_active_data = active.data) || void 0 === _active_data ? void 0 : null === (_active_data_current = _active_data.current) || void 0 === _active_data_current ? void 0 : _active_data_current.schema;
        const overSchema = null == over ? void 0 : null === (_over_data = over.data) || void 0 === _over_data ? void 0 : null === (_over_data_current = _over_data.current) || void 0 === _over_data_current ? void 0 : _over_data_current.schema;
        const insertAdjacent = null == over ? void 0 : null === (_over_data1 = over.data) || void 0 === _over_data1 ? void 0 : null === (_over_data_current1 = _over_data1.current) || void 0 === _over_data_current1 ? void 0 : _over_data_current1.insertAdjacent;
        const breakRemoveOn = null == over ? void 0 : null === (_over_data2 = over.data) || void 0 === _over_data2 ? void 0 : null === (_over_data_current2 = _over_data2.current) || void 0 === _over_data_current2 ? void 0 : _over_data_current2.breakRemoveOn;
        const wrapSchema = null == over ? void 0 : null === (_over_data3 = over.data) || void 0 === _over_data3 ? void 0 : null === (_over_data_current3 = _over_data3.current) || void 0 === _over_data_current3 ? void 0 : _over_data_current3.wrapSchema;
        const onSuccess = null == over ? void 0 : null === (_over_data4 = over.data) || void 0 === _over_data4 ? void 0 : null === (_over_data_current4 = _over_data4.current) || void 0 === _over_data_current4 ? void 0 : _over_data_current4.onSuccess;
        var _over_data_current_removeParentsIfNoChildren;
        const removeParentsIfNoChildren = null === (_over_data_current_removeParentsIfNoChildren = null == over ? void 0 : null === (_over_data5 = over.data) || void 0 === _over_data5 ? void 0 : null === (_over_data_current5 = _over_data5.current) || void 0 === _over_data_current5 ? void 0 : _over_data_current5.removeParentsIfNoChildren) || void 0 === _over_data_current_removeParentsIfNoChildren || _over_data_current_removeParentsIfNoChildren;
        if (!activeSchema || !overSchema) {
            var _props_onDragEnd;
            null == props || null === (_props_onDragEnd = props.onDragEnd) || void 0 === _props_onDragEnd || _props_onDragEnd.call(props, event);
            return;
        }
        if (activeSchema === overSchema) {
            var _props_onDragEnd1;
            null == props || null === (_props_onDragEnd1 = props.onDragEnd) || void 0 === _props_onDragEnd1 || _props_onDragEnd1.call(props, event);
            return;
        }
        if (activeSchema.parent === overSchema && 'beforeEnd' === insertAdjacent) {
            var _props_onDragEnd2;
            null == props || null === (_props_onDragEnd2 = props.onDragEnd) || void 0 === _props_onDragEnd2 || _props_onDragEnd2.call(props, event);
            return;
        }
        const dn = (0, index_js_namespaceObject.createDesignable)({
            t,
            api,
            refresh,
            current: overSchema
        });
        dn.loadAPIClientEvents();
        if (activeSchema.parent === overSchema.parent) {
            var _props_onDragEnd3;
            dn.insertBeforeBeginOrAfterEnd(activeSchema);
            null == props || null === (_props_onDragEnd3 = props.onDragEnd) || void 0 === _props_onDragEnd3 || _props_onDragEnd3.call(props, event);
            return;
        }
        if (insertAdjacent) {
            var _props_onDragEnd4;
            dn.insertAdjacent(insertAdjacent, activeSchema, {
                wrap: wrapSchema,
                breakRemoveOn,
                removeParentsIfNoChildren,
                onSuccess
            });
            null == props || null === (_props_onDragEnd4 = props.onDragEnd) || void 0 === _props_onDragEnd4 || _props_onDragEnd4.call(props, event);
            return;
        }
    };
};
const DndContext = (0, schema_namespaceObject.observer)((props)=>{
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const [visible, setVisible] = (0, external_react_namespaceObject.useState)(true);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(core_namespaceObject.DndContext, {
        collisionDetection: core_namespaceObject.rectIntersection,
        ...props,
        onDragStart: (event)=>{
            var _active_data_current, _active_data;
            const { active } = event;
            const activeSchema = null == active ? void 0 : null === (_active_data = active.data) || void 0 === _active_data ? void 0 : null === (_active_data_current = _active_data.current) || void 0 === _active_data_current ? void 0 : _active_data_current.schema;
            setVisible(!!activeSchema);
            if (null == props ? void 0 : props.onDragStart) {
                var _props_onDragStart;
                null == props || null === (_props_onDragStart = props.onDragStart) || void 0 === _props_onDragStart || _props_onDragStart.call(props, event);
            }
        },
        onDragEnd: useDragEnd(props),
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(core_namespaceObject.DragOverlay, {
                dropAnimation: {
                    duration: 10,
                    easing: 'cubic-bezier(0.18, 0.67, 0.6, 1.22)'
                },
                children: visible && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                    style: {
                        whiteSpace: 'nowrap'
                    },
                    children: t('Dragging')
                })
            }),
            props.children
        ]
    });
}, {
    displayName: 'DndContext'
});
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
});
