import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2007-2026 GoodData Corporation
import { useMemo } from "react";
import { insightVisualizationType, isInsight } from "@gooddata/sdk-model";
import { useDashboardSelector } from "../../../../../model/react/DashboardStoreProvider.js";
import { selectInsightsMap } from "../../../../../model/store/insights/insightsSelectors.js";
import { isDrillToInsightConfig } from "../../../../drill/types.js";
import { InsightDropdown } from "../../../../widget/common/InsightDropdown.js";
export function DrillingInsightDropdown({ insightConfig, onSelect }) {
    const { insight, insightType, insightRef } = useDrillToInsightData(insightConfig);
    return (_jsx(InsightDropdown, { insight: insight, insightRef: insightRef, insightType: insightType, onSelect: onSelect }));
}
function useDrillToInsightData(insightConfig) {
    const insights = useDashboardSelector(selectInsightsMap);
    return useMemo(() => {
        if (isDrillToInsightConfig(insightConfig) && insightConfig.insightRef) {
            const insight = insights.get(insightConfig.insightRef);
            if (isInsight(insight)) {
                const insightType = insightVisualizationType(insight);
                return {
                    insight,
                    insightRef: insightConfig.insightRef,
                    insightType: insightType,
                };
            }
        }
        return {};
    }, [insightConfig, insights]);
}
//# sourceMappingURL=DrillingInsightDropdown.js.map