import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { bucketIsEmpty, insightBucket } from "@gooddata/sdk-model";
import { BucketNames } from "@gooddata/sdk-ui";
import { doesGeoBasemapSupportColorScheme } from "@gooddata/sdk-ui-geo";
import { ConfigurationPanelContent, } from "./ConfigurationPanelContent.js";
import { hasColorMeasure, hasSegmentAttribute } from "./geoInsightBucketUtils.js";
import { messages } from "../../../locales.js";
import { isGeoBasemapConfigEnabled, isGeoChartsViewportConfigEnabled, isGeoSatelliteBasemapEnabled, } from "../../constants/featureFlags.js";
import { sanitizeGeoMapStyleOptions } from "../../constants/geoMapStyle.js";
import { BasemapDropdownControl } from "../configurationControls/BasemapDropdownControl.js";
import { ColorsSection } from "../configurationControls/colors/ColorsSection.js";
import { ColorSchemeDropdownControl } from "../configurationControls/ColorSchemeDropdownControl.js";
import { ConfigSection } from "../configurationControls/ConfigSection.js";
import { GeoViewportControl } from "../configurationControls/GeoViewportControl.js";
import { GeoLegendSection } from "../configurationControls/legend/GeoLegendSection.js";
/**
 * Configuration panel for GeoAreaChart
 *
 * @remarks
 * This panel provides configuration options specific to geo area maps:
 * - Legend settings
 * - Area styling (fill opacity, border color, border width)
 * - Viewport configuration
 * - Color mapping
 *
 * @internal
 */
export class GeoAreaConfigurationPanel extends ConfigurationPanelContent {
    getControlProperties() {
        return sanitizeGeoMapStyleOptions({
            basemap: this.props.properties?.controls?.["basemap"],
            legacyTileset: this.props.properties?.controls?.["tileset"],
            colorScheme: this.props.properties?.controls?.["colorScheme"],
        });
    }
    renderLegendSection() {
        const { insight, properties, propertiesMeta, pushData } = this.props;
        const controlsDisabled = this.isControlDisabled();
        const isAttributeOnlyLegend = hasAreaAttribute(insight) && !hasSegmentAttribute(insight) && !hasColorMeasure(insight);
        return (_jsx(GeoLegendSection, { properties: properties, propertiesMeta: propertiesMeta, controlsDisabled: controlsDisabled, defaultLegendEnabled: !isAttributeOnlyLegend, pushData: pushData }));
    }
    renderViewportSection() {
        const { properties, propertiesMeta, pushData, featureFlags } = this.props;
        const { basemap, colorScheme } = this.getControlProperties();
        const isBasemapConfigEnabled = isGeoBasemapConfigEnabled(featureFlags);
        const isSatelliteBasemapEnabled = isGeoSatelliteBasemapEnabled(featureFlags);
        const isViewportConfigEnabled = isGeoChartsViewportConfigEnabled(featureFlags);
        const isDisabled = this.isControlDisabled();
        const isColorSchemeSupported = basemap !== undefined && doesGeoBasemapSupportColorScheme(basemap);
        const isColorSchemeDisabled = isDisabled || !isColorSchemeSupported;
        return (_jsx(ConfigSection, { id: "map_section", title: messages["pointsMapTitle"].id, propertiesMeta: propertiesMeta, properties: properties, pushData: pushData, children: _jsx(GeoViewportControl, { properties: properties, disabled: isDisabled, pushData: pushData, getCurrentMapView: isViewportConfigEnabled ? this.props.getCurrentMapView : undefined, beforeNavigationContent: isBasemapConfigEnabled ? (_jsxs(_Fragment, { children: [
                        _jsx(BasemapDropdownControl, { valuePath: "basemap", labelText: messages["basemapTitle"].id, properties: properties, value: basemap, disabled: isDisabled, showDisabledMessage: isDisabled, showSatelliteBasemapOption: isSatelliteBasemapEnabled, pushData: pushData }), _jsx(ColorSchemeDropdownControl, { valuePath: "colorScheme", labelText: messages["colorSchemeTitle"].id, properties: properties, value: colorScheme, disabled: isColorSchemeDisabled, showDisabledMessage: isColorSchemeDisabled, pushData: pushData })
                    ] })) : null }) }));
    }
    renderConfigurationPanel() {
        return (_jsxs("div", { children: [this.renderLegendSection(), this.renderColorSection(), this.renderViewportSection(), this.renderInteractionsSection()] }));
    }
    renderColorSection() {
        const { properties, propertiesMeta, pushData, colors, references, isLoading } = this.props;
        const controlsDisabled = this.isControlDisabled();
        return (_jsx(ColorsSection, { properties: properties, propertiesMeta: propertiesMeta, references: references, colors: colors, controlsDisabled: controlsDisabled, pushData: pushData, hasMeasures // hasMeasures is true because color config is attribute-based
            : true, isLoading: isLoading, supportsChartFill: false }));
    }
    isControlDisabled() {
        const { insight, isError, isLoading } = this.props;
        return !!(!hasAreaAttribute(insight) || isError || isLoading);
    }
}
function hasAreaAttribute(insight) {
    if (!insight) {
        return false;
    }
    const bucket = insightBucket(insight, BucketNames.AREA);
    return bucket !== undefined && !bucketIsEmpty(bucket);
}
//# sourceMappingURL=GeoAreaConfigurationPanel.js.map