// (C) 2021-2025 GoodData Corporation
import { insightSanitize } from "@gooddata/sdk-model";
import { BucketNames } from "@gooddata/sdk-ui";
import { pivotTableAdditionalFactories } from "./pivotTableAdditionalFactories.js";
import { pivotTableConfigFromInsight } from "./pivotTableConfigFromInsight.js";
import { PluggablePivotTable } from "./PluggablePivotTable.js";
import { executionConfigInsightConversion, filtersInsightConversion, getInsightToPropsConverter, getReactEmbeddingCodeGenerator, insightConversion, localeInsightConversion, multipleAttributesBucketConversion, multipleAttributesOrMeasuresBucketConversion, sortsInsightConversion, totalsInsightConversion, } from "../../../utils/embeddingCodeGenerator/index.js";
import { BaseChartDescriptor } from "../baseChart/BaseChartDescriptor.js";
import { MIN_VISUALIZATION_HEIGHT_TABLE_REPEATER_FLEXIBLE_LAYOUT } from "../constants.js";
import { addIntersectionFiltersToInsight, modifyBucketsAttributesForDrillDown, sanitizeTableProperties, } from "../drillDownUtil.js";
export class PivotTableDescriptor extends BaseChartDescriptor {
    getFactory() {
        return (params) => new PluggablePivotTable(params);
    }
    getSizeInfo(_insight, layoutDescriptor, settings) {
        return {
            width: {
                default: 4,
                min: 2,
                max: layoutDescriptor.gridColumnsCount,
            },
            height: {
                default: this.getDefaultHeight(settings),
                min: this.getMinHeight(settings),
                max: this.getMaxHeight(settings),
            },
        };
    }
    getMinHeight(_settings) {
        // Flexible layout is always enabled now
        return MIN_VISUALIZATION_HEIGHT_TABLE_REPEATER_FLEXIBLE_LAYOUT;
    }
    applyDrillDown(insight, drillDownContext, backendSupportsElementUris) {
        const drillDownInsight = modifyBucketsAttributesForDrillDown(insight, drillDownContext.drillDefinition);
        const drillDownInsightWithFilters = addIntersectionFiltersToInsight(drillDownInsight, drillDownContext.event.drillContext.intersection, backendSupportsElementUris);
        return sanitizeTableProperties(insightSanitize(drillDownInsightWithFilters));
    }
    getEmbeddingCode = getReactEmbeddingCodeGenerator({
        component: {
            importType: "named",
            name: "PivotTable",
            package: "@gooddata/sdk-ui-pivot",
        },
        insightToProps: getInsightToPropsConverter({
            measures: multipleAttributesOrMeasuresBucketConversion("measures", BucketNames.MEASURES),
            rows: multipleAttributesBucketConversion("rows", BucketNames.ATTRIBUTE),
            columns: multipleAttributesBucketConversion("columns", BucketNames.COLUMNS),
            filters: filtersInsightConversion("filters"),
            sortBy: sortsInsightConversion("sortBy"),
            totals: totalsInsightConversion("totals"),
            config: insightConversion("config", {
                typeImport: {
                    importType: "named",
                    name: "IPivotTableConfig",
                    package: "@gooddata/sdk-ui-pivot",
                },
                cardinality: "scalar",
            }, pivotTableConfigFromInsight),
            locale: localeInsightConversion("locale"),
            execConfig: executionConfigInsightConversion("execConfig"),
        }),
        additionalFactories: pivotTableAdditionalFactories,
    });
    getMeta() {
        return {
            documentationUrl: "https://www.gooddata.com/docs/gooddata-ui/latest/references/visual_components/pivot_table",
            supportsExport: true,
            supportsZooming: false,
        };
    }
}
//# sourceMappingURL=PivotTableDescriptor.js.map