import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2019-2026 GoodData Corporation
import { useCallback } from "react";
import { cloneDeep, set } from "lodash-es";
import { useIntl } from "react-intl";
import { getTranslation } from "../../utils/translations.js";
import { DisabledBubbleMessage } from "../DisabledBubbleMessage.js";
export function CheckboxControl({ checked = false, disabled = false, showDisabledMessage = false, labelText, labelContent, valuePath, disabledMessageId, properties, pushData, isValueInverted = false, defaultValue, }) {
    const intl = useIntl();
    const onValueChanged = useCallback((event) => {
        const clonedProperties = cloneDeep(properties);
        const value = isValueInverted ? !event.target.checked : event.target.checked;
        // When the value matches the default, set to undefined so the property gets removed
        // during merge. This prevents the Save button from staying enabled when toggling
        // back to the default state.
        const valueToSet = value === defaultValue ? undefined : value;
        set(clonedProperties, `controls.${valuePath}`, valueToSet);
        pushData?.({ properties: clonedProperties });
    }, [properties, isValueInverted, pushData, valuePath, defaultValue]);
    return (_jsx(DisabledBubbleMessage, { showDisabledMessage: showDisabledMessage, messageId: disabledMessageId, children: _jsxs("label", { className: "input-checkbox-label", children: [
                _jsx("input", { "aria-label": valuePath, checked: checked, disabled: disabled, type: "checkbox", className: "input-checkbox", onChange: onValueChanged }), labelText ? (_jsx("span", { className: "input-label-text", children: getTranslation(labelText, intl) })) : null, labelContent ? _jsx("span", { className: "input-label-text", children: labelContent }) : null] }) }));
}
//# sourceMappingURL=CheckboxControl.js.map