// (C) 2025-2026 GoodData Corporation
import { useMemo } from "react";
import { defineMessages, useIntl } from "react-intl";
import { useDashboardSelector } from "../../../model/react/DashboardStoreProvider.js";
import { selectEnableImplicitDrillToUrl } from "../../../model/store/config/configSelectors.js";
import { DrillType } from "../DrillSelect/types.js";
const groupMenuItemMessages = defineMessages({
    drillDown: { id: "drill_modal_picker.drill-down" },
    drillInto: { id: "drill_modal_picker.drill-into" },
    crossFilter: { id: "drill_modal_picker.cross-filter" },
    keyDriverAnalysis: { id: "drill_modal_picker.key-driver-analysis" },
    drillToUrl: { id: "drill_modal_picker.drill-to-url" },
});
export const useDrillSelectDropdownMenuItems = ({ drillDownItems, drillItems, crossFilteringItems, keyDriverAnalysisItems, drillToUrlItems, onSelect, }) => {
    const { formatMessage } = useIntl();
    const enableImplicitDrillToUrl = useDashboardSelector(selectEnableImplicitDrillToUrl);
    return useMemo(() => {
        const createMenuGroup = (items, groupId, groupTitle) => ({
            type: "group",
            id: groupId,
            stringTitle: formatMessage({ id: groupTitle }),
            data: `${groupTitle} Data`,
            subItems: items.map((item, index) => ({
                type: "interactive",
                id: `${groupId}-${index}`,
                stringTitle: item.name,
                isDisabled: item.isDisabled,
                tooltip: item.tooltipText,
                ariaAttributes: {
                    "aria-haspopup": item.type === DrillType.DRILL_TO_INSIGHT || item.type === DrillType.DRILL_DOWN
                        ? "dialog"
                        : undefined,
                },
                data: {
                    type: item.type,
                    name: item.name,
                    attributeValue: item.attributeValue,
                    drillDefinition: item.drillDefinition,
                    onSelect: () => {
                        onSelect(item.drillDefinition, item.context);
                    },
                },
            })),
        });
        const drillDownMenuItems = drillDownItems.length > 0
            ? [createMenuGroup(drillDownItems, "drill-down", groupMenuItemMessages.drillDown.id)]
            : [];
        const drillToUrlMenuItems = enableImplicitDrillToUrl && drillToUrlItems.length > 0
            ? [createMenuGroup(drillToUrlItems, "drill-to-url", groupMenuItemMessages.drillToUrl.id)]
            : [];
        const drillMenuItems = drillItems.length > 0
            ? [createMenuGroup(drillItems, "drill-into", groupMenuItemMessages.drillInto.id)]
            : [];
        const crossFilteringMenuItems = crossFilteringItems.length > 0
            ? [createMenuGroup(crossFilteringItems, "cross-filter", groupMenuItemMessages.crossFilter.id)]
            : [];
        const keyDriverAnalysisMenu = keyDriverAnalysisItems.length > 0
            ? [
                createMenuGroup(keyDriverAnalysisItems, "key-driver-analysis", groupMenuItemMessages.keyDriverAnalysis.id),
            ]
            : [];
        return [
            ...drillDownMenuItems,
            ...drillMenuItems,
            ...crossFilteringMenuItems,
            ...keyDriverAnalysisMenu,
            ...drillToUrlMenuItems,
        ];
    }, [
        drillDownItems,
        drillItems,
        crossFilteringItems,
        keyDriverAnalysisItems,
        drillToUrlItems,
        formatMessage,
        onSelect,
        enableImplicitDrillToUrl,
    ]);
};
//# sourceMappingURL=useDrillSelectDropdownMenuItems.js.map