import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2020-2026 GoodData Corporation
import { useIntl } from "react-intl";
import { Dropdown, DropdownList } from "@gooddata/sdk-ui-kit";
import { DRILL_TARGET_TYPE } from "../../../../drill/types.js";
import { ButtonWithIcon } from "../ButtonWithIcon.js";
import { DrillTargetTypeListItem } from "./DrillTargetTypeListItem.js";
const ITEM_HEIGHT = 25;
const DROPDOWN_BODY_WIDTH = 200;
const getTargetBySelection = (selection, targets) => {
    return targets.find((target) => target.id === selection);
};
const getIconClassNameBySelection = (selection) => {
    const icons = {
        [DRILL_TARGET_TYPE.DRILL_TO_DASHBOARD]: "gd-icon-drill-to-dashboard",
        [DRILL_TARGET_TYPE.DRILL_TO_INSIGHT]: "gd-icon-drill-to-insight",
        [DRILL_TARGET_TYPE.DRILL_DOWN]: "gd-icon-drill-down",
        [DRILL_TARGET_TYPE.DRILL_TO_URL]: "gd-icon-hyperlink-disabled",
    };
    return selection ? icons[selection] : undefined;
};
export function DrillTargetType(props) {
    const { selection, enabledDrillTargetTypeItems, isButtonDisabled } = props;
    const intl = useIntl();
    const targetBySelection = getTargetBySelection(selection, enabledDrillTargetTypeItems);
    const buttonValue = targetBySelection
        ? targetBySelection.title
        : intl.formatMessage({ id: "configurationPanel.drillConfig.select" });
    const onSelect = (target) => {
        props.onSelect(target.id);
    };
    return (_jsx(Dropdown, { closeOnParentScroll: true, closeOnMouseDrag: false, closeOnOutsideClick: true, alignPoints: [
            {
                align: "bl tl",
            },
            {
                align: "tl bl",
            },
        ], renderButton: ({ isOpen, toggleDropdown }) => (_jsx(ButtonWithIcon, { className: "s-drill-config-panel-target-button", value: buttonValue, icon: getIconClassNameBySelection(selection), isOpen: isOpen, disabled: isButtonDisabled, onClick: toggleDropdown })), renderBody: ({ closeDropdown }) => (_jsx(DropdownList, { width: DROPDOWN_BODY_WIDTH, itemHeight: ITEM_HEIGHT, items: enabledDrillTargetTypeItems, className: "gd-drill-config-panel-target s-drill-config-panel-target-type-open", renderItem: ({ item }) => {
                const isSelected = targetBySelection?.id === item.id;
                const drillIconClassName = getIconClassNameBySelection(item.id);
                return (_jsx(DrillTargetTypeListItem, { item: item, icon: drillIconClassName, isSelected: isSelected, onClick: () => {
                        onSelect(item);
                        closeDropdown();
                    } }));
            } })) }));
}
//# sourceMappingURL=DrillTargetType.js.map