"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _reactNative = require("react-native");

var _v = require("@native-base/v3");

var _RadioGroup = require("./RadioGroup");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

const Radio = ({
  children,
  ...props
}) => {
  const {
    onChangeHandler,
    value: cValue,
    ...context
  } = _react.default.useContext(_RadioGroup.RadioContext);

  const {
    activeColor,
    borderColor,
    iconColor,
    onChange,
    isDisabled,
    value: pValue,
    ariaLabel,
    icon,
    size,
    newProps
  } = (0, _v.usePropsConfig)('Radio', { ...context,
    ...props
  });
  const radioState = cValue ? cValue === pValue : false;

  const pressHandler = () => {
    onChangeHandler && onChangeHandler(pValue);
    onChange && onChange(pValue);
  };

  const sizedIcon = () => /*#__PURE__*/_react.default.cloneElement(icon, {
    size,
    color: icon.props.color ? icon.props.color : iconColor
  }, icon.props.children);

  return /*#__PURE__*/_react.default.createElement(_reactNative.TouchableOpacity, {
    activeOpacity: 1,
    disabled: isDisabled,
    onPress: () => pressHandler(),
    accessible: true,
    accessibilityLabel: ariaLabel,
    accessibilityRole: "checkbox"
  }, /*#__PURE__*/_react.default.createElement(_v.Box, _extends({}, newProps, {
    flexDirection: "row",
    justifyContent: "center",
    alignItems: "center"
  }), /*#__PURE__*/_react.default.createElement(_v.Box, {
    backgroundColor: radioState ? activeColor : 'transparent',
    borderColor: radioState ? activeColor : borderColor,
    borderWidth: 2,
    display: "flex",
    justifyContent: "center",
    alignItems: "center",
    borderRadius: 999
  }, icon && radioState ? sizedIcon() : /*#__PURE__*/_react.default.createElement(_v.Icon, {
    name: "circle-medium",
    type: "MaterialCommunityIcons",
    size: size,
    color: iconColor,
    opacity: radioState ? 1 : 0
  })), children));
};

var _default = Radio;
exports.default = _default;
//# sourceMappingURL=Radio.js.map