"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__, {
    DragHandlePageTab: ()=>DragHandlePageTab
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const external_antd_style_namespaceObject = require("antd-style");
const index_js_namespaceObject = require("../../hooks/index.js");
const external_DragHandlePageTab_style_js_namespaceObject = require("./DragHandlePageTab.style.js");
const external_SortableItem_js_namespaceObject = require("./SortableItem.js");
const DragHandlePageTab = (props)=>{
    const { isSubMenu, children, className: overStyle, isAdminMenu } = props;
    const { draggable } = (0, external_react_namespaceObject.useContext)(external_SortableItem_js_namespaceObject.SortableContext);
    const { designable } = (0, index_js_namespaceObject.useDesignable)();
    const { attributes, listeners, setNodeRef, transform, isDragging } = draggable;
    const { styles } = (0, external_DragHandlePageTab_style_js_namespaceObject.useStyles)();
    const ref = (0, external_react_namespaceObject.useRef)(null);
    const [dimensions, setDimensions] = (0, external_react_namespaceObject.useState)({
        width: 0,
        height: 0
    });
    const [initialPosition, setInitialPosition] = (0, external_react_namespaceObject.useState)({
        x: 0,
        y: 0
    });
    const centerOffset = {
        x: 4 * dimensions.width,
        y: 3 * dimensions.height
    };
    const style = {
        position: isDragging ? 'fixed' : 'static',
        top: isDragging ? initialPosition.y - centerOffset.y : 0,
        left: isDragging ? initialPosition.x - centerOffset.x : 0,
        width: isDragging ? 'max-content' : '100%',
        height: isDragging ? 'max-content' : '100%',
        zIndex: isDragging ? 999 : 'auto',
        pointerEvents: isDragging ? 'none' : 'auto',
        transform: transform ? "translate3d(".concat(transform.x, "px, ").concat(transform.y, "px, 0) scale(").concat(isDragging ? 1.05 : 1, ")") : void 0,
        boxShadow: isDragging ? '0 4px 8px rgba(0, 0, 0, 0.1)' : 'none'
    };
    const handleMouseDown = (event)=>{
        if (ref.current) {
            const { width, height } = ref.current.getBoundingClientRect();
            const { clientX, clientY } = event;
            setDimensions({
                width,
                height
            });
            setInitialPosition({
                x: clientX,
                y: clientY
            });
        }
    };
    if (!designable) return children;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        ref: setNodeRef,
        className: (0, external_antd_style_namespaceObject.cx)(styles.dragHandleMenu, {
            draggable: isDragging,
            leftBorder: isSubMenu && isDragging,
            adminMenu: isAdminMenu && isDragging
        }, overStyle),
        style: style,
        ...listeners,
        ...attributes,
        role: "none",
        onMouseDown: handleMouseDown,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            ref: ref,
            className: 'wrapper',
            children: 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
});
