import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2023-2025 GoodData Corporation
import { useIntl } from "react-intl";
import { CalculateAs, ComparisonPositionValues, } from "@gooddata/sdk-ui-charts";
import { comparisonMessages, messages } from "../../../../../locales.js";
import { CheckboxControl } from "../../CheckboxControl.js";
import { ConfigSubsection } from "../../ConfigSubsection.js";
import { InputControl } from "../../InputControl.js";
import { COMPARISON_LABEL_CONDITIONAL_ENABLED_VALUE_PATH, COMPARISON_LABEL_EQUALS_VALUE_PATH, COMPARISON_LABEL_NEGATIVE_VALUE_PATH, COMPARISON_LABEL_POSITIVE_VALUE_PATH, COMPARISON_LABEL_UNCONDITIONAL_VALUE_PATH, } from "../ComparisonValuePath.js";
const DISABLED_MESSAGE_ALIGN_POINTS = [{ align: "cr cl", offset: { x: 0, y: 7 } }];
const getLabelValues = (properties, defaultLabelKeys, conditionalEnabled, intl) => {
    const unconditionalValue = properties?.controls?.comparison?.labelConfig?.unconditionalValue ||
        intl.formatMessage({ id: defaultLabelKeys.nonConditionalKey });
    if (conditionalEnabled) {
        const positiveValue = properties?.controls?.comparison?.labelConfig?.positive ||
            intl.formatMessage({ id: defaultLabelKeys.positiveKey });
        const negativeValue = properties?.controls?.comparison?.labelConfig?.negative ||
            intl.formatMessage({ id: defaultLabelKeys.negativeKey });
        const equalsValue = properties?.controls?.comparison?.labelConfig?.equals ||
            intl.formatMessage({ id: defaultLabelKeys.equalsKey });
        return {
            unconditionalValue,
            positiveValue,
            negativeValue,
            equalsValue,
        };
    }
    return {
        unconditionalValue,
    };
};
function getDisabledMessageId(showDisabledMessage, isPositionOnTop, isCalculateAsRatio) {
    if (showDisabledMessage) {
        return messages["notApplicable"].id;
    }
    if (isPositionOnTop) {
        return comparisonMessages["labelPositionOnTopDisabled"].id;
    }
    if (isCalculateAsRatio) {
        return comparisonMessages["labelConditionalDisabledByRatio"].id;
    }
    return undefined;
}
export function LabelSubSection({ sectionDisabled, showDisabledMessage, defaultLabelKeys, calculationType, properties, pushData, }) {
    const intl = useIntl();
    const isCalculateAsRatio = calculationType === CalculateAs.RATIO;
    const isPositionOnTop = properties?.controls?.comparison?.position === ComparisonPositionValues.TOP;
    const disabled = sectionDisabled || isPositionOnTop;
    const shouldShowDisabledMessage = showDisabledMessage || isPositionOnTop;
    const conditionalDisabled = disabled || isCalculateAsRatio;
    const shouldShowConditionalDisabledMessage = shouldShowDisabledMessage || isCalculateAsRatio;
    const disabledMessageId = getDisabledMessageId(!!showDisabledMessage, isPositionOnTop, isCalculateAsRatio);
    const conditionalEnabled = !!properties?.controls?.comparison?.labelConfig?.isConditional &&
        calculationType !== CalculateAs.RATIO;
    const { unconditionalValue, positiveValue, negativeValue, equalsValue } = getLabelValues(properties, defaultLabelKeys, conditionalEnabled, intl);
    return (_jsxs(ConfigSubsection, { title: comparisonMessages["labelSubSectionTitle"].id, canBeToggled: false, children: [
            _jsx("div", { className: "comparison-label-conditional s-comparison-label-conditional", children: _jsx(CheckboxControl, { valuePath: COMPARISON_LABEL_CONDITIONAL_ENABLED_VALUE_PATH, labelText: comparisonMessages["labelConditionalTitle"].id, properties: properties, checked: conditionalEnabled, disabled: conditionalDisabled, showDisabledMessage: shouldShowConditionalDisabledMessage, disabledMessageId: disabledMessageId, pushData: pushData }) }), conditionalEnabled ? (_jsxs(_Fragment, { children: [
                    _jsx("div", { className: "comparison-label-itemline s-comparison-label-itemline", children: _jsx(InputControl, { type: "text", valuePath: COMPARISON_LABEL_POSITIVE_VALUE_PATH, properties: properties, labelText: comparisonMessages["labelPositiveTitle"].id, disabled: disabled, showDisabledMessage: shouldShowDisabledMessage, disabledMessageAlignPoints: DISABLED_MESSAGE_ALIGN_POINTS, disabledMessageId: disabledMessageId, placeholder: defaultLabelKeys.positiveKey, pushData: pushData, value: positiveValue }) }), _jsx("div", { className: "comparison-label-itemline s-comparison-label-itemline", children: _jsx(InputControl, { type: "text", valuePath: COMPARISON_LABEL_NEGATIVE_VALUE_PATH, properties: properties, labelText: comparisonMessages["labelNegativeTitle"].id, disabled: disabled, showDisabledMessage: shouldShowDisabledMessage, disabledMessageAlignPoints: DISABLED_MESSAGE_ALIGN_POINTS, disabledMessageId: disabledMessageId, placeholder: defaultLabelKeys.negativeKey, pushData: pushData, value: negativeValue }) }), _jsx("div", { className: "comparison-label-itemline s-comparison-label-itemline", children: _jsx(InputControl, { type: "text", valuePath: COMPARISON_LABEL_EQUALS_VALUE_PATH, properties: properties, labelText: comparisonMessages["labelEqualsTitle"].id, disabled: disabled, showDisabledMessage: shouldShowDisabledMessage, disabledMessageAlignPoints: DISABLED_MESSAGE_ALIGN_POINTS, disabledMessageId: disabledMessageId, placeholder: defaultLabelKeys.equalsKey, pushData: pushData, value: equalsValue }) })
                ] })) : (_jsx("div", { className: "comparison-label-itemline s-comparison-label-itemline", children: _jsx(InputControl, { type: "text", valuePath: COMPARISON_LABEL_UNCONDITIONAL_VALUE_PATH, properties: properties, labelText: comparisonMessages["labelNameTitle"].id, disabled: disabled, showDisabledMessage: shouldShowDisabledMessage, disabledMessageAlignPoints: DISABLED_MESSAGE_ALIGN_POINTS, disabledMessageId: disabledMessageId, placeholder: defaultLabelKeys.nonConditionalKey, pushData: pushData, value: unconditionalValue }) }))] }));
}
//# sourceMappingURL=LabelSubSection.js.map