"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__, {
    GroupNode: ()=>GroupNode
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const react_cjs_namespaceObject = require("../../xyflow/react.cjs");
const external_react_namespaceObject = require("react");
const external_constants_cjs_namespaceObject = require("../../constants.cjs");
const icon_registry_cjs_namespaceObject = require("../../utils/icon-registry.cjs");
const external_GroupNode_styles_cjs_namespaceObject = require("./GroupNode.styles.cjs");
const external_GroupNodeConfigContext_cjs_namespaceObject = require("./GroupNodeConfigContext.cjs");
const minWidth = 12 * external_constants_cjs_namespaceObject.GRID_SPACING;
const minHeight = 12 * external_constants_cjs_namespaceObject.GRID_SPACING;
const COLLAPSED_HEADER_HEIGHT = 64;
const GroupNodeComponent = ({ id, data, selected })=>{
    const { setNodes, setEdges, getNodes } = (0, react_cjs_namespaceObject.useReactFlow)();
    const { headerActions, executionStatus, onMoreOptions, hideMoreOptions, hideCollapseButton } = (0, external_GroupNodeConfigContext_cjs_namespaceObject.useGroupNodeConfig)();
    const title = data.title || 'Group';
    const iconName = data.iconName;
    const backgroundColor = data.backgroundColor;
    const borderColor = data.borderColor;
    const collapsed = data.collapsed || false;
    const handleToggleCollapse = (0, external_react_namespaceObject.useCallback)(()=>{
        const willCollapse = !collapsed;
        const childNodeIds = new Set(getNodes().filter((n)=>n.parentId === id).map((n)=>n.id));
        if (willCollapse) setNodes((nodes)=>nodes.map((node)=>{
                if (node.id === id) {
                    const styleHeight = node.style?.height;
                    const parsedStyleHeight = 'number' == typeof styleHeight ? styleHeight : 'string' == typeof styleHeight ? parseFloat(styleHeight) || void 0 : void 0;
                    const currentHeight = node.height ?? node.measured?.height ?? parsedStyleHeight ?? minHeight;
                    return {
                        ...node,
                        height: COLLAPSED_HEADER_HEIGHT,
                        style: {
                            ...node.style,
                            height: COLLAPSED_HEADER_HEIGHT
                        },
                        data: {
                            ...node.data,
                            collapsed: true,
                            expandedHeight: currentHeight
                        }
                    };
                }
                if (childNodeIds.has(node.id)) return {
                    ...node,
                    hidden: true
                };
                return node;
            }));
        else {
            const expandedHeight = data.expandedHeight ?? minHeight;
            setNodes((nodes)=>nodes.map((node)=>{
                    if (node.id === id) return {
                        ...node,
                        height: expandedHeight,
                        style: {
                            ...node.style,
                            height: expandedHeight
                        },
                        data: {
                            ...node.data,
                            collapsed: false
                        }
                    };
                    if (childNodeIds.has(node.id)) return {
                        ...node,
                        hidden: false
                    };
                    return node;
                }));
        }
        setEdges((edges)=>edges.map((edge)=>childNodeIds.has(edge.source) || childNodeIds.has(edge.target) ? {
                    ...edge,
                    hidden: willCollapse
                } : edge));
    }, [
        id,
        collapsed,
        data.expandedHeight,
        getNodes,
        setNodes,
        setEdges
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
        children: [
            !collapsed && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_cjs_namespaceObject.NodeResizeControl, {
                        style: {
                            background: 'transparent',
                            border: 'none',
                            zIndex: 100
                        },
                        position: "top-left",
                        minWidth: minWidth,
                        minHeight: minHeight,
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.ResizeHandle, {
                            selected: selected,
                            cursor: "nwse-resize"
                        })
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_cjs_namespaceObject.NodeResizeControl, {
                        style: {
                            background: 'transparent',
                            border: 'none',
                            zIndex: 100
                        },
                        position: "top-right",
                        minWidth: minWidth,
                        minHeight: minHeight,
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.ResizeHandle, {
                            selected: selected,
                            cursor: "nesw-resize"
                        })
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_cjs_namespaceObject.NodeResizeControl, {
                        style: {
                            background: 'transparent',
                            border: 'none',
                            zIndex: 100
                        },
                        position: "bottom-left",
                        minWidth: minWidth,
                        minHeight: minHeight,
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.ResizeHandle, {
                            selected: selected,
                            cursor: "nesw-resize"
                        })
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(react_cjs_namespaceObject.NodeResizeControl, {
                        style: {
                            background: 'transparent',
                            border: 'none',
                            zIndex: 100
                        },
                        position: "bottom-right",
                        minWidth: minWidth,
                        minHeight: minHeight,
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.ResizeHandle, {
                            selected: selected,
                            cursor: "nwse-resize"
                        })
                    })
                ]
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_GroupNode_styles_cjs_namespaceObject.GroupContainer, {
                backgroundColor: backgroundColor,
                borderColor: borderColor,
                selected: selected,
                collapsed: collapsed,
                executionStatus: executionStatus,
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.TopCornerIndicators, {
                        selected: selected
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.BottomCornerIndicators, {
                        selected: selected
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_GroupNode_styles_cjs_namespaceObject.GroupHeader, {
                        children: [
                            iconName && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.GroupIconWrapper, {
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                                    icon: iconName,
                                    size: 16
                                })
                            }),
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.GroupTitle, {
                                children: title
                            }),
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_GroupNode_styles_cjs_namespaceObject.GroupControls, {
                                children: [
                                    headerActions && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
                                        children: [
                                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.GroupHeaderSeparator, {}),
                                            headerActions
                                        ]
                                    }),
                                    !hideCollapseButton && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
                                        children: [
                                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.GroupHeaderSeparator, {}),
                                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.GroupHeaderButton, {
                                                type: "button",
                                                className: "nodrag nopan",
                                                onClick: handleToggleCollapse,
                                                "aria-label": collapsed ? 'Expand group' : 'Collapse group',
                                                title: collapsed ? 'Expand group' : 'Collapse group',
                                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                                                    icon: collapsed ? 'chevron-down' : 'chevron-up',
                                                    size: 16
                                                })
                                            })
                                        ]
                                    }),
                                    !hideMoreOptions && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.GroupHeaderButton, {
                                        type: "button",
                                        className: "nodrag nopan",
                                        onClick: onMoreOptions,
                                        "aria-label": "More options",
                                        title: "More options",
                                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                                            icon: "ellipsis-vertical",
                                            size: 16
                                        })
                                    })
                                ]
                            })
                        ]
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_GroupNode_styles_cjs_namespaceObject.GroupContent, {
                        collapsed: collapsed
                    })
                ]
            })
        ]
    });
};
const GroupNode = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(GroupNodeComponent);
exports.GroupNode = __webpack_exports__.GroupNode;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "GroupNode"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
