function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import { createContext, useContext } from 'react';
import { View, Pressable } from 'react-native';
import { SvgXml } from 'react-native-svg';
import { radioChecked, radioUnchecked, radioCheckedDisabled, radioUncheckedDisabled } from '../../assets/icons';
import { useStyles } from './styles';
const RadioContext = /*#__PURE__*/createContext(null);
const useRadioContext = () => {
  const context = useContext(RadioContext);
  return context;
};
function Group({
  value,
  onChange,
  children,
  disabled,
  ...props
}) {
  return /*#__PURE__*/React.createElement(RadioContext.Provider, {
    value: {
      value,
      onChange,
      disabled
    }
  }, /*#__PURE__*/React.createElement(View, _extends({}, props, {
    accessibilityRole: "radiogroup"
  }), children));
}
const OptionContext = /*#__PURE__*/createContext(null);
const useOptionContext = () => {
  const context = useContext(OptionContext);
  return context;
};
function Option({
  style,
  value,
  children,
  disabled,
  accessibilityHint,
  accessibilityLabel,
  ...props
}) {
  const {
    select,
    onChange,
    value: selectedValue,
    disabled: groupDisabled
  } = useRadioContext();
  const {
    styles
  } = useStyles();
  const selected = select ? select(selectedValue, value) : selectedValue === value;
  const isDisabled = disabled || groupDisabled;
  return /*#__PURE__*/React.createElement(OptionContext.Provider, {
    value: {
      value,
      disabled: isDisabled
    }
  }, /*#__PURE__*/React.createElement(Pressable, _extends({}, props, {
    disabled: isDisabled,
    accessibilityRole: "radio",
    onPress: () => !isDisabled && onChange(value),
    accessibilityLabel: accessibilityLabel || `Option ${value}`,
    accessibilityState: {
      checked: selected,
      disabled: isDisabled
    },
    accessibilityHint: accessibilityHint || `${selected ? 'Selected' : 'Not selected'}.`,
    style: ({
      pressed
    }) => [styles.option, pressed && styles.optionPressed, style && style({
      pressed,
      selected,
      disabled: isDisabled
    })]
  }), children));
}
const Icon = ({
  width = 24,
  height = 24,
  style,
  ...props
}) => {
  const {
    theme
  } = useStyles();
  const option = useOptionContext();
  const {
    value,
    select
  } = useRadioContext();
  const isSelected = select ? select(value, option.value) : value === (option === null || option === void 0 ? void 0 : option.value);
  const color = isSelected ? option !== null && option !== void 0 && option.disabled ? theme.colors.primaryShade3 : theme.colors.primary : option !== null && option !== void 0 && option.disabled ? theme.colors.baseShade4 : theme.colors.baseShade3;
  const icon = isSelected ? option !== null && option !== void 0 && option.disabled ? radioCheckedDisabled() : radioChecked() : option !== null && option !== void 0 && option.disabled ? radioUncheckedDisabled() : radioUnchecked();
  return /*#__PURE__*/React.createElement(View, {
    style: style
  }, /*#__PURE__*/React.createElement(SvgXml, _extends({}, props, {
    xml: icon,
    color: color,
    width: width,
    height: height
  })));
};
const Label = ({
  children,
  ...props
}) => {
  return /*#__PURE__*/React.createElement(View, props, children);
};
export const Radio = {
  Group,
  Option,
  Icon,
  Label
};
//# sourceMappingURL=index.js.map