// (C) 2025-2026 GoodData Corporation
import { GeoLayerTypes, attributeDisplayFormRef, bucketAttribute, bucketsFind, geoLayerTypeFromVisualizationType, insightBuckets, insightVisualizationType, serializeObjRef, } from "@gooddata/sdk-model";
import { BucketNames, isGeoVisualizationUsingNewEngine, resolveDefaultDisplayFormRefForDisplayForm, } from "@gooddata/sdk-ui";
export function getGeoDefaultDisplayFormRefs(insight, settings, catalogAttributes, preloadedAttributesWithReferences) {
    const type = insightVisualizationType(insight);
    if (!isGeoVisualizationUsingNewEngine(type, settings)) {
        return undefined;
    }
    const layerType = geoLayerTypeFromVisualizationType(type);
    if (!layerType) {
        return undefined;
    }
    return resolveGeoDefaultDisplayFormRefs(layerType, insightBuckets(insight), catalogAttributes, preloadedAttributesWithReferences);
}
export function resolveGeoDefaultDisplayFormRefs(layerType, buckets, catalogAttributes, preloadedAttributesWithReferences) {
    const bucketName = layerType === GeoLayerTypes.AREA ? BucketNames.AREA : BucketNames.LOCATION;
    const geoBucket = bucketsFind(buckets, bucketName);
    const geoAttribute = geoBucket ? bucketAttribute(geoBucket) : undefined;
    if (!geoAttribute) {
        return undefined;
    }
    const geoDisplayFormRef = attributeDisplayFormRef(geoAttribute);
    const defaultDisplayFormRef = resolveDefaultDisplayFormRefForDisplayForm(geoDisplayFormRef, catalogAttributes, preloadedAttributesWithReferences);
    if (!defaultDisplayFormRef) {
        return undefined;
    }
    return new Map([[serializeObjRef(geoDisplayFormRef), defaultDisplayFormRef]]);
}
