"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Radio = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _reactNativeSvg = require("react-native-svg");
var _icons = require("../../assets/icons");
var _styles = require("./styles");
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); }
const RadioContext = /*#__PURE__*/(0, _react.createContext)(null);
const useRadioContext = () => {
  const context = (0, _react.useContext)(RadioContext);
  return context;
};
function Group({
  value,
  onChange,
  children,
  disabled,
  ...props
}) {
  return /*#__PURE__*/React.createElement(RadioContext.Provider, {
    value: {
      value,
      onChange,
      disabled
    }
  }, /*#__PURE__*/React.createElement(_reactNative.View, _extends({}, props, {
    accessibilityRole: "radiogroup"
  }), children));
}
const OptionContext = /*#__PURE__*/(0, _react.createContext)(null);
const useOptionContext = () => {
  const context = (0, _react.useContext)(OptionContext);
  return context;
};
function Option({
  style,
  value,
  children,
  disabled,
  accessibilityHint,
  accessibilityLabel,
  ...props
}) {
  const {
    select,
    onChange,
    value: selectedValue,
    disabled: groupDisabled
  } = useRadioContext();
  const {
    styles
  } = (0, _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(_reactNative.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
  } = (0, _styles.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 ? (0, _icons.radioCheckedDisabled)() : (0, _icons.radioChecked)() : option !== null && option !== void 0 && option.disabled ? (0, _icons.radioUncheckedDisabled)() : (0, _icons.radioUnchecked)();
  return /*#__PURE__*/React.createElement(_reactNative.View, {
    style: style
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, _extends({}, props, {
    xml: icon,
    color: color,
    width: width,
    height: height
  })));
};
const Label = ({
  children,
  ...props
}) => {
  return /*#__PURE__*/React.createElement(_reactNative.View, props, children);
};
const Radio = exports.Radio = {
  Group,
  Option,
  Icon,
  Label
};
//# sourceMappingURL=index.js.map