import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2019-2026 GoodData Corporation
import { PureComponent } from "react";
import { insightHasMeasures, insightMeasures, } from "@gooddata/sdk-model";
import { DefaultLocale } from "@gooddata/sdk-ui";
import { getChartFillIgnoredMeasureIdsFromMdObject, getMeasuresFromMdObject, } from "../../utils/bucketHelper.js";
import { isForecastEnabled } from "../../utils/forecastHelper.js";
import { InternalIntlWrapper } from "../../utils/internalIntlProvider.js";
import { AdvancedSection } from "../configurationControls/advanced/AdvancedSection.js";
import { AnomaliesSection } from "../configurationControls/anomalies/AnomaliesSection.js";
import { ColorsSection } from "../configurationControls/colors/ColorsSection.js";
import { ForecastSection } from "../configurationControls/forecast/ForecastSection.js";
import { InteractionsSection } from "../configurationControls/interactions/InteractionsSection.js";
import { LegendSection } from "../configurationControls/legend/LegendSection.js";
import { isInsightSupportedForAlerts, isInsightSupportedForScheduledExports, } from "../pluggableVisualizations/alerts.js";
import { isInsightSupportedForImplicitDrillToUrl } from "../pluggableVisualizations/drillDownUtil.js";
export class ConfigurationPanelContent extends PureComponent {
    static defaultProps = {
        properties: undefined,
        references: undefined,
        referencePoint: undefined,
        propertiesMeta: undefined,
        colors: undefined,
        locale: DefaultLocale,
        isError: false,
        isLoading: false,
        insight: undefined,
        pushData: () => { },
        featureFlags: {},
        permissions: undefined,
        axis: undefined,
        panelConfig: {},
    };
    supportedPropertiesList;
    constructor(props) {
        super(props);
        this.isControlDisabled = this.isControlDisabled.bind(this);
    }
    render() {
        return (_jsx("div", { children: _jsx(InternalIntlWrapper, { locale: this.props.locale, children: this.renderConfigurationPanel() }) }, `config-${this.props.type}`));
    }
    /**
     * Optionally pass a sectionName to specialize disabling logic for specific sections.
     * Default logic disables if no measures, error, or loading.
     */
    isControlDisabled(_sectionName) {
        const { insight, isError, isLoading } = this.props;
        return !!(!insight || !insightHasMeasures(insight) || isError || isLoading);
    }
    renderColorSection() {
        const { properties, propertiesMeta, pushData, colors, references, insight, isLoading, panelConfig } = this.props;
        const controlsDisabled = this.isControlDisabled();
        const hasMeasures = getMeasuresFromMdObject(insight).length > 0;
        const chartFillIgnoredMeasures = getChartFillIgnoredMeasureIdsFromMdObject(insight, properties);
        return (_jsx(ColorsSection, { properties: properties, propertiesMeta: propertiesMeta, references: references, colors: colors, controlsDisabled: controlsDisabled, pushData: pushData, hasMeasures: hasMeasures, isLoading: isLoading, supportsChartFill: panelConfig?.supportsChartFill, chartFillIgnoredMeasures: chartFillIgnoredMeasures, isChartFillDisabled: panelConfig?.isChartFillDisabled }));
    }
    renderLegendSection() {
        const { properties, propertiesMeta, pushData } = this.props;
        const controlsDisabled = this.isControlDisabled();
        return (_jsx(LegendSection, { properties: properties, propertiesMeta: propertiesMeta, controlsDisabled: controlsDisabled, pushData: pushData }));
    }
    renderInteractionsSection() {
        const { pushData, properties, propertiesMeta, panelConfig, configurationPanelRenderers, featureFlags, insight, } = this.props;
        const isAlertingEnabled = featureFlags?.enableAlerting;
        const isScheduledExportsEnabled = featureFlags?.enableScheduling;
        const showImplicitDrillToUrl = featureFlags?.enableImplicitDrillToUrl && isInsightSupportedForImplicitDrillToUrl(insight);
        const supportsKeyDriveAnalysis = featureFlags?.enableChangeAnalysis;
        const insightSupportsScheduledExports = isInsightSupportedForScheduledExports(insight);
        const insightSupportsAlerts = isInsightSupportedForAlerts(insight);
        const supportsAlertsConfiguration = insightSupportsAlerts && isAlertingEnabled;
        const supportsScheduledExportsConfiguration = insightSupportsScheduledExports && isScheduledExportsEnabled;
        const metrics = insight ? insightMeasures(insight) : [];
        return supportsAlertsConfiguration ||
            panelConfig?.supportsAttributeHierarchies ||
            showImplicitDrillToUrl ? (_jsx(InteractionsSection, { metrics: metrics, areControlsDisabledGetter: this.isControlDisabled, properties: properties, propertiesMeta: propertiesMeta, pushData: pushData, supportsAlertConfiguration: !!supportsAlertsConfiguration, supportsDrillDownConfiguration: panelConfig?.supportsAttributeHierarchies, supportsScheduledExportsConfiguration: !!supportsScheduledExportsConfiguration, InteractionsDetailRenderer: configurationPanelRenderers?.InteractionsDetailRenderer, showImplicitDrillToUrl: showImplicitDrillToUrl, supportsKeyDriveAnalysis: supportsKeyDriveAnalysis, 
            // enableDrillToUrlByDefault is actually not a feature flag, but setting
            // for some reason the property is called featureFlags, but contains both feature flags and settings
            enableDrillToUrlByDefault: featureFlags?.enableDrillToUrlByDefault })) : null;
    }
    renderForecastSection() {
        const { pushData, properties, propertiesMeta, type, featureFlags, referencePoint, insight } = this.props;
        if (!featureFlags?.["enableSmartFunctions"]) {
            return null;
        }
        const { enabled, visible } = isForecastEnabled(referencePoint, insight, type);
        if (!visible) {
            return null;
        }
        return (_jsx(ForecastSection, { controlsDisabled: this.isControlDisabled(), properties: properties, propertiesMeta: propertiesMeta, enabled: enabled, pushData: pushData }));
    }
    renderAnomaliesSection() {
        const { pushData, properties, permissions, propertiesMeta, type, featureFlags, referencePoint, insight, colors, } = this.props;
        if (!featureFlags?.["enableAnomalyDetectionVisualization"]) {
            return null;
        }
        if (!permissions?.canUseAiAssistant) {
            return null;
        }
        //NOTE: For now we keep it the same as forecast, but it should be different
        // in the future
        const { enabled, visible } = isForecastEnabled(referencePoint, insight, type);
        if (!visible || !colors) {
            return null;
        }
        return (_jsx(AnomaliesSection, { colors: colors, controlsDisabled: this.isControlDisabled(), properties: properties, propertiesMeta: propertiesMeta, enabled: enabled, pushData: pushData }));
    }
    renderAdvancedSection() {
        const { pushData, properties, propertiesMeta, featureFlags } = this.props;
        return featureFlags?.enableVisualizationFineTuning ? (_jsx(AdvancedSection, { controlsDisabled: this.isControlDisabled(), properties: properties, propertiesMeta: propertiesMeta, pushData: pushData })) : null;
    }
}
//# sourceMappingURL=ConfigurationPanelContent.js.map