"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.RadioButtonLabel = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _context = require("../../context");
var _core = require("../../core");
var _hapticFeedback = require("../../functions/haptic-feedback/hapticFeedback");
var _accessibility = require("../../utils/accessibility");
var _H = require("../typography/H6");
var _AnimatedRadio = require("./AnimatedRadio");
var _jsxRuntime = require("react/jsx-runtime");
const DISABLED_OPACITY = 0.5;
/**
 * A radio button with the automatic state management that uses a {@link AnimatedRadio}
 * The toggleValue change when a `onPress` event is received and dispatch the `onValueChange`.
 *
 * @param props
 * @constructor
 */
const RadioButtonLabel = ({
  label,
  checked,
  disabled,
  onValueChange,
  accessibilityLabel,
  accessibilityHint
}) => {
  const {
    dynamicFontScale,
    spacingScaleMultiplier
  } = (0, _accessibility.useIOFontDynamicScale)();
  const theme = (0, _context.useIOTheme)();
  const [toggleValue, setToggleValue] = (0, _react.useState)(checked ?? false);
  const toggleRadioButton = () => {
    (0, _hapticFeedback.triggerHaptic)("impactLight");
    setToggleValue(!toggleValue);
    if (onValueChange !== undefined) {
      onValueChange(!toggleValue);
    }
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
    onPress: toggleRadioButton,
    style: {
      alignSelf: "flex-start",
      opacity: disabled ? DISABLED_OPACITY : 1
    },
    disabled: disabled,
    accessibilityRole: "radio",
    accessibilityState: {
      checked: checked ?? toggleValue,
      disabled: !!disabled
    },
    accessibilityLabel: accessibilityLabel,
    accessibilityHint: accessibilityHint,
    testID: "AnimatedRadioButton",
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
      style: {
        flexDirection: "row",
        alignItems: "flex-start",
        flexShrink: 1,
        width: "100%",
        columnGap: 8 * dynamicFontScale * spacingScaleMultiplier
      },
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
        pointerEvents: "none",
        accessibilityElementsHidden: true,
        importantForAccessibility: "no-hide-descendants",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_AnimatedRadio.AnimatedRadio, {
          size: _core.IOSelectionTickVisualParams.size * dynamicFontScale,
          checked: checked ?? toggleValue
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_H.H6, {
        style: {
          flexShrink: 1
        },
        color: theme["textBody-default"],
        children: label
      })]
    })
  });
};
exports.RadioButtonLabel = RadioButtonLabel;
//# sourceMappingURL=RadioButtonLabel.js.map