import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2024-2025 GoodData Corporation
import { useCallback, useRef, useState } from "react";
import { v4 as uuidv4 } from "uuid";
import { Bubble } from "@gooddata/sdk-ui-kit";
const ALIGN_POINTS = [{ align: "bc tr" }, { align: "tc br" }];
export function Popup({ children, popup, }) {
    const [isOpen, setIsOpen] = useState(false);
    const { current: id } = useRef(`popup-${uuidv4()}`);
    const toggle = useCallback(() => setIsOpen((x) => !x), []);
    const close = useCallback(() => setIsOpen(false), []);
    return (_jsxs(_Fragment, { children: [children({ toggle, id }), isOpen ? (_jsx(Bubble, { alignPoints: ALIGN_POINTS, alignTo: `#${id}`, closeOnOutsideClick: true, closeOnParentScroll: true, onClose: close, children: popup })) : null] }));
}
//# sourceMappingURL=Popup.js.map