import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2007-2026 GoodData Corporation
import { useMemo } from "react";
import { MenuOpenedByClick } from "./MenuOpenedByClick.js";
import { MenuOpenedByHover } from "./MenuOpenedByHover.js";
const defaultProps = {
    openAction: "hover",
    alignment: ["right", "bottom"],
    spacing: 0,
    offset: 0,
    portalTarget: typeof document === "undefined" ? null : document.querySelector("body"),
};
export function MenuOpener(props) {
    // Filter out undefined values from props to avoid overriding defaults
    const definedProps = useMemo(() => {
        return Object.entries(props).reduce((acc, [key, value]) => {
            if (value !== undefined) {
                acc[key] = value;
            }
            return acc;
        }, {});
    }, [props]);
    const propsWithDefaults = useMemo(() => {
        return { ...defaultProps, ...definedProps };
    }, [definedProps]);
    const Component = useMemo(() => {
        switch (propsWithDefaults.openAction) {
            case "click":
                return MenuOpenedByClick;
            case "hover":
                return MenuOpenedByHover;
            default:
                return MenuOpenedByHover;
        }
    }, [propsWithDefaults.openAction]);
    return (_jsx(Component, { opened: propsWithDefaults.opened, onOpenedChange: propsWithDefaults.onOpenedChange, topLevelMenu: propsWithDefaults.topLevelMenu, alignment: propsWithDefaults.alignment, spacing: propsWithDefaults.spacing, offset: propsWithDefaults.offset, toggler: propsWithDefaults.toggler, togglerWrapperClassName: propsWithDefaults.togglerWrapperClassName, portalTarget: propsWithDefaults.portalTarget, children: _jsx("div", { className: "gd-menuOpener", children: propsWithDefaults.children }) }));
}
