import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2019-2026 GoodData Corporation
import { useIntl } from "react-intl";
import { Dropdown, DropdownButton } from "@gooddata/sdk-ui-kit";
import { useDashboardUserInteraction } from "../../../../../model/react/useDashboardUserInteraction.js";
import { DrillOriginSelectorBody } from "./DrillOriginSelectorBody.js";
const DROPDOWN_ALIGN_POINTS = [
    {
        align: "bl tl",
        offset: {
            x: 0,
            y: 4,
        },
    },
    {
        align: "tl bl",
        offset: {
            x: 0,
            y: -4,
        },
    },
];
export function DrillOriginSelector(props) {
    const { items, widgetRef } = props;
    const onSelect = (selected) => {
        props.onSelect(selected, widgetRef);
    };
    const intl = useIntl();
    const { addInteractionClicked } = useDashboardUserInteraction();
    if (!items.measures?.length && !items.attributes?.length) {
        return null;
    }
    return (_jsx(Dropdown, { className: "gd-drill-origin-selector", closeOnParentScroll: true, closeOnMouseDrag: false, closeOnOutsideClick: true, alignPoints: DROPDOWN_ALIGN_POINTS, renderButton: ({ isOpen, toggleDropdown }) => (_jsx(DropdownButton, { value: intl.formatMessage({ id: "configurationPanel.drillConfig.addInteraction" }), iconLeft: "gd-icon-add", className: "s-drill-show-measures customizable", isOpen: isOpen, onClick: () => {
                toggleDropdown();
                if (!isOpen) {
                    addInteractionClicked();
                }
            } })), renderBody: ({ closeDropdown }) => (_jsx(DrillOriginSelectorBody, { supportedItems: items, onSelect: onSelect, onCloseDropdown: closeDropdown })) }));
}
