var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
import { jsx, jsxs } from "react/jsx-runtime";
import React, { useContext, useState } from "react";
import styled from "styled-components";
import { string, oneOfType, number, bool } from "prop-types";
import { TouchableWithoutFeedback } from "react-native";
import { hexToRgb } from "@gympass/yoga-common";
import RadioGroupContext from "../../RadioGroupContext";
const RadioMark = styled.View(
  ({
    theme: {
      yoga: {
        colors: { white },
        components: { radiogroup }
      }
    },
    checked,
    disabled,
    pressed
  }) => `
  justify-content: center;
  align-items: center;
  
  height: ${radiogroup.radio.size}px;
  width: ${radiogroup.radio.size}px;

  background-color: ${pressed ? hexToRgb(radiogroup.hover.backgroundColor, 0.75) : white};

  border-width: ${radiogroup.radio.size * 0.1}px;
  border-style: solid;
  border-color: ${radiogroup.radio.backgroundColor};
  border-radius: ${radiogroup.radio.border.radius}px;

  ${checked ? `
          border-color: ${radiogroup.checked.backgroundColor};
          background-color: ${pressed ? hexToRgb(radiogroup.checked.hover.backgroundColor, 0.75) : white}
        ` : ``}

  ${disabled ? `
          border-color: ${radiogroup.disabled.backgroundColor};
        ` : ``}
`
);
const Dot = styled.View(
  ({
    theme: {
      yoga: {
        components: { radiogroup }
      }
    },
    checked,
    disabled
  }) => `
  height: ${radiogroup.radio.size * 0.5}px;
  width: ${radiogroup.radio.size * 0.5}px;

  background-color: ${radiogroup.radio.backgroundColor};
  border-radius: ${radiogroup.radio.border.radius}px;

  ${checked ? `
          background-color: ${radiogroup.checked.backgroundColor};
        ` : ``}

  ${disabled ? `
          background-color: ${radiogroup.disabled.backgroundColor};
        ` : ``}
`
);
const Shadow = styled.View(
  ({
    checked,
    theme: {
      yoga: {
        components: { radiogroup }
      }
    }
  }) => `
  position: absolute;
  height: ${radiogroup.radio.size + radiogroup.radio.size * 0.4 * 2}px;
  width: ${radiogroup.radio.size + radiogroup.radio.size * 0.4 * 2}px;

  border-width: ${radiogroup.radio.size * 0.4}px;
  border-style: solid;
  border-color: ${checked ? hexToRgb(radiogroup.checked.hover.backgroundColor, 0.75) : hexToRgb(radiogroup.hover.backgroundColor, 0.75)};
  border-radius: ${radiogroup.radio.border.radius}px;

  opacity: 0.75;
`
);
const RadioGroupRadio = React.forwardRef(
  (_a, ref) => {
    var _b = _a, { value = "", disabled = false } = _b, rest = __objRest(_b, ["value", "disabled"]);
    const _a2 = useContext(RadioGroupContext), { onChange, small, selectedValue } = _a2, context = __objRest(_a2, ["onChange", "small", "selectedValue"]);
    const [pressing, togglePressing] = useState(false);
    const inputValue = value;
    const checked = inputValue === selectedValue;
    return /* @__PURE__ */ jsx(
      TouchableWithoutFeedback,
      __spreadProps(__spreadValues({
        onPressIn: () => {
          togglePressing(true);
        },
        onPress: () => {
          onChange({ value: inputValue });
        },
        onPressOut: () => {
          togglePressing(false);
        },
        disabled
      }, context), {
        children: /* @__PURE__ */ jsxs(
          RadioMark,
          __spreadProps(__spreadValues({
            checked,
            disabled,
            pressed: pressing,
            ref
          }, rest), {
            children: [
              checked && /* @__PURE__ */ jsx(Dot, { checked, disabled }),
              pressing && /* @__PURE__ */ jsx(Shadow, { checked })
            ]
          })
        )
      })
    );
  }
);
RadioGroupRadio.displayName = "RadioGroup.Radio";
RadioGroupRadio.propTypes = {
  disabled: bool,
  value: oneOfType([string, number])
};
var Radio_default = RadioGroupRadio;
export {
  Radio_default as default
};
