"use strict";

import { useState } from "react";
import { Pressable, View } from "react-native";
import { useIOTheme } from "../../context";
import { IOSelectionTickVisualParams } from "../../core";
import { triggerHaptic } from "../../functions/haptic-feedback/hapticFeedback";
import { useIOFontDynamicScale } from "../../utils/accessibility";
import { H6 } from "../typography/H6";
import { AnimatedRadio } from "./AnimatedRadio";
import { jsx as _jsx, jsxs as _jsxs } from "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
 */
export const RadioButtonLabel = ({
  label,
  checked,
  disabled,
  onValueChange,
  accessibilityLabel,
  accessibilityHint
}) => {
  const {
    dynamicFontScale,
    spacingScaleMultiplier
  } = useIOFontDynamicScale();
  const theme = useIOTheme();
  const [toggleValue, setToggleValue] = useState(checked ?? false);
  const toggleRadioButton = () => {
    triggerHaptic("impactLight");
    setToggleValue(!toggleValue);
    if (onValueChange !== undefined) {
      onValueChange(!toggleValue);
    }
  };
  return /*#__PURE__*/_jsx(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__*/_jsxs(View, {
      style: {
        flexDirection: "row",
        alignItems: "flex-start",
        flexShrink: 1,
        width: "100%",
        columnGap: 8 * dynamicFontScale * spacingScaleMultiplier
      },
      children: [/*#__PURE__*/_jsx(View, {
        pointerEvents: "none",
        accessibilityElementsHidden: true,
        importantForAccessibility: "no-hide-descendants",
        children: /*#__PURE__*/_jsx(AnimatedRadio, {
          size: IOSelectionTickVisualParams.size * dynamicFontScale,
          checked: checked ?? toggleValue
        })
      }), /*#__PURE__*/_jsx(H6, {
        style: {
          flexShrink: 1
        },
        color: theme["textBody-default"],
        children: label
      })]
    })
  });
};
//# sourceMappingURL=RadioButtonLabel.js.map