// (C) 2021-2026 GoodData Corporation
import { BucketNames } from "@gooddata/sdk-ui";
import { multipleSecondaryMeasuresBucketConversion, singleSecondaryMeasureBucketConversion, } from "./headlineBucketConversion.js";
import { headlineConfigFromInsight } from "./headlineConfigFromInsight.js";
import { PluggableHeadline } from "./PluggableHeadline.js";
import { getReactEmbeddingCodeGenerator } from "../../../utils/embeddingCodeGenerator/getReactEmbeddingCodeGenerator.js";
import { executionConfigInsightConversion, filtersInsightConversion, localeInsightConversion, singleMeasureBucketConversion, } from "../../../utils/embeddingCodeGenerator/insightToPropsConverter/convenience.js";
import { getInsightToPropsConverter, insightConversion, } from "../../../utils/embeddingCodeGenerator/insightToPropsConverter/convertor.js";
import { MAX_VISUALIZATION_HEIGHT } from "../constants.js";
const hasSecondaryMeasure = (insight) => insight.insight.buckets.filter((bucket) => bucket.items.length > 0).length > 1;
export class HeadlineDescriptor {
    getFactory() {
        return (params) => new PluggableHeadline(params);
    }
    getSizeInfo(insight, layoutDescriptor, _settings) {
        return {
            width: {
                default: 2,
                min: 2,
                max: layoutDescriptor.gridColumnsCount,
            },
            height: {
                default: this.getDefaultHeight(insight),
                min: this.getMinHeight(insight),
                max: this.getMaxHeight(insight),
            },
        };
    }
    getDefaultHeight(insight) {
        return hasSecondaryMeasure(insight) ? 11 : 8;
    }
    getMinHeight(insight) {
        return hasSecondaryMeasure(insight) ? 9 : 5;
    }
    getMaxHeight(_insight) {
        return MAX_VISUALIZATION_HEIGHT;
    }
    applyDrillDown(insight) {
        return insight;
    }
    getEmbeddingCode = getReactEmbeddingCodeGenerator({
        component: {
            importType: "named",
            name: "Headline",
            package: "@gooddata/sdk-ui-charts",
        },
        insightToProps: getInsightToPropsConverter({
            primaryMeasure: singleMeasureBucketConversion("primaryMeasure", BucketNames.MEASURES),
            secondaryMeasures: multipleSecondaryMeasuresBucketConversion("secondaryMeasures", BucketNames.SECONDARY_MEASURES),
            secondaryMeasure: singleSecondaryMeasureBucketConversion("secondaryMeasure", BucketNames.SECONDARY_MEASURES),
            filters: filtersInsightConversion("filters"),
            locale: localeInsightConversion("locale"),
            execConfig: executionConfigInsightConversion("execConfig"),
            config: insightConversion("config", {
                typeImport: {
                    importType: "named",
                    name: "IChartConfig",
                    package: "@gooddata/sdk-ui-charts",
                },
                cardinality: "scalar",
            }, headlineConfigFromInsight),
        }),
    });
    getMeta(settings) {
        return {
            documentationUrl: "https://www.gooddata.com/docs/gooddata-ui/latest/references/visual_components/headline",
            supportsExport: settings?.enableHeadlineExport ?? true,
            supportsZooming: false,
        };
    }
}
//# sourceMappingURL=HeadlineDescriptor.js.map