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); }

import React from 'react';
import { TouchableOpacity } from 'react-native';
import { Icon, Box, usePropsConfig } from '@native-base/v3';
import { RadioContext } from './RadioGroup';

const Radio = ({
  children,
  ...props
}) => {
  const {
    onChangeHandler,
    value: cValue,
    ...context
  } = React.useContext(RadioContext);
  const {
    activeColor,
    borderColor,
    iconColor,
    onChange,
    isDisabled,
    value: pValue,
    ariaLabel,
    icon,
    size,
    newProps
  } = usePropsConfig('Radio', { ...context,
    ...props
  });
  const radioState = cValue ? cValue === pValue : false;

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

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

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

export default Radio;
//# sourceMappingURL=Radio.js.map