"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (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 = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > 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__, {
    FloatingCanvasPanel: ()=>FloatingCanvasPanel
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const react_cjs_namespaceObject = require("../../xyflow/react.cjs");
const apollo_wind_namespaceObject = require("@uipath/apollo-wind");
const external_react_namespaceObject = require("react");
const external_react_dom_namespaceObject = require("react-dom");
const external_CanvasPortal_cjs_namespaceObject = require("./CanvasPortal.cjs");
const external_PanelChrome_cjs_namespaceObject = require("./PanelChrome.cjs");
const external_useFloatingPosition_cjs_namespaceObject = require("./useFloatingPosition.cjs");
const PANEL_BASE_CLASS = 'text-(--canvas-foreground) bg-(--canvas-background-raised) border border-(--canvas-border-de-emp) text-sm flex flex-col transition-opacity duration-200 ease-in-out';
const PANEL_FLOATING_MAX_HEIGHT = 600;
const PANEL_FLOATING_MIN_HEIGHT = 100;
const PANEL_FLOATING_CLASS = 'rounded-lg shadow-[0_4px_16px_rgba(0,0,0,0.12)] w-auto min-w-[280px] max-w-none h-auto max-h-[600px]';
const PANEL_PINNED_CLASS = 'rounded-none shadow-none w-[320px] min-w-[320px] max-w-[320px] h-screen max-h-screen';
function FloatingCanvasPanel({ open = true, nodeId, anchorRect, placement = 'right-start', offset = 20, fallbackPlacement, isPinned = false, useFixedPosition = false, portalToBody = false, title, header, headerActions, children, onClose, scrollKey, scrollableContent = true, onMouseEnter, onMouseLeave }) {
    const { computedAnchor, floatingStyles, availableHeight, refs, mergedReferenceRef } = (0, external_useFloatingPosition_cjs_namespaceObject.useFloatingPosition)({
        open,
        nodeId,
        anchorRect,
        placement,
        offset,
        fallbackPlacement
    });
    const panelClassName = (0, external_react_namespaceObject.useMemo)(()=>(0, apollo_wind_namespaceObject.cn)(PANEL_BASE_CLASS, isPinned ? PANEL_PINNED_CLASS : PANEL_FLOATING_CLASS), [
        isPinned
    ]);
    const sizingStyle = (0, external_react_namespaceObject.useMemo)(()=>{
        if (isPinned || null == availableHeight) return {};
        const maxHeight = Math.min(PANEL_FLOATING_MAX_HEIGHT, availableHeight);
        const occupiedHeight = Math.max(PANEL_FLOATING_MIN_HEIGHT, maxHeight);
        return {
            maxHeight: `${maxHeight}px`,
            minHeight: `${PANEL_FLOATING_MIN_HEIGHT}px`,
            ['--floating-available-height']: `${occupiedHeight}px`
        };
    }, [
        isPinned,
        availableHeight
    ]);
    if (!open || !computedAnchor) return null;
    if (useFixedPosition && anchorRect) {
        const getScreenSpacePosition = ()=>{
            const anchorCenterX = computedAnchor.x + computedAnchor.width / 2;
            switch(placement){
                case 'top':
                case 'top-start':
                case 'top-end':
                    return {
                        left: anchorCenterX,
                        bottom: window.innerHeight - computedAnchor.y + offset,
                        transform: 'translateX(-50%)'
                    };
                case 'bottom':
                case 'bottom-start':
                case 'bottom-end':
                    return {
                        left: anchorCenterX,
                        top: computedAnchor.y + computedAnchor.height + offset,
                        transform: 'translateX(-50%)'
                    };
                case 'right':
                case 'right-start':
                case 'right-end':
                    return {
                        left: computedAnchor.x + computedAnchor.width + offset,
                        top: computedAnchor.y
                    };
                case 'left':
                case 'left-start':
                case 'left-end':
                    return {
                        right: window.innerWidth - computedAnchor.x + offset,
                        top: computedAnchor.y
                    };
                default:
                    return {
                        left: anchorCenterX,
                        bottom: window.innerHeight - computedAnchor.y + offset,
                        transform: 'translateX(-50%)'
                    };
            }
        };
        const screenPosition = getScreenSpacePosition();
        const fixedContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            className: (0, apollo_wind_namespaceObject.cn)('nodrag nopan nowheel', panelClassName),
            onPointerEnter: onMouseEnter,
            onPointerLeave: onMouseLeave,
            style: {
                position: 'fixed',
                ...screenPosition,
                ...sizingStyle,
                zIndex: 1100,
                pointerEvents: 'auto'
            },
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_PanelChrome_cjs_namespaceObject.PanelChrome, {
                title: title,
                header: header,
                headerActions: headerActions,
                onClose: onClose,
                scrollKey: scrollKey,
                scrollableContent: scrollableContent,
                children: children
            })
        });
        return portalToBody ? /*#__PURE__*/ (0, external_react_dom_namespaceObject.createPortal)(fixedContent, document.body) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasPortal_cjs_namespaceObject.CanvasPortal, {
            children: fixedContent
        });
    }
    const panelContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        ref: refs.setFloating,
        className: (0, apollo_wind_namespaceObject.cn)('nodrag nopan nowheel', panelClassName),
        onPointerEnter: onMouseEnter,
        onPointerLeave: onMouseLeave,
        style: {
            ...isPinned ? {} : floatingStyles,
            ...sizingStyle,
            position: isPinned ? 'fixed' : 'absolute',
            right: isPinned ? 0 : void 0,
            top: isPinned ? 0 : void 0,
            zIndex: 1100,
            pointerEvents: 'auto'
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_PanelChrome_cjs_namespaceObject.PanelChrome, {
            title: title,
            header: header,
            headerActions: headerActions,
            onClose: onClose,
            scrollKey: scrollKey,
            scrollableContent: scrollableContent,
            children: children
        })
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_cjs_namespaceObject.ViewportPortal, {
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    ref: mergedReferenceRef,
                    style: {
                        position: 'absolute',
                        width: computedAnchor.width,
                        height: computedAnchor.height,
                        transform: `translate(${computedAnchor.x}px, ${computedAnchor.y}px)`,
                        pointerEvents: 'none',
                        background: 'none'
                    }
                })
            }),
            portalToBody ? /*#__PURE__*/ (0, external_react_dom_namespaceObject.createPortal)(panelContent, document.body) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_CanvasPortal_cjs_namespaceObject.CanvasPortal, {
                children: panelContent
            })
        ]
    });
}
exports.FloatingCanvasPanel = __webpack_exports__.FloatingCanvasPanel;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "FloatingCanvasPanel"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
