"use strict";
const React = require("react");
const classNames = require("../_util/classNames.js");
const group = require("./group.js");
const index = require("../ConfigProvider/index.js");
const omit = require("../_util/omit.js");
const useMergeValue = require("../_util/hooks/useMergeValue.js");
const iconHover = require("../_class/icon-hover.js");
const useMergeProps = require("../_util/hooks/useMergeProps.js");
const is = require("../_util/is.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const React__default = /* @__PURE__ */ _interopDefaultLegacy(React);
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __rest = globalThis && globalThis.__rest || function(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
function Radio(baseProps) {
  var _a;
  var inputRef = React.useRef(null);
  var _b = React.useContext(index.ConfigContext), getPrefixCls = _b.getPrefixCls, componentConfig = _b.componentConfig, rtl = _b.rtl;
  var props = useMergeProps(baseProps, {}, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Radio);
  var context = React.useContext(group.RadioGroupContext);
  var prefixCls = getPrefixCls("radio");
  var mergeProps = __assign({}, props);
  if (context.group) {
    mergeProps.checked = context.value === props.value;
    mergeProps.disabled = !!(context.disabled || props.disabled);
  }
  var disabled = mergeProps.disabled, children = mergeProps.children, value = mergeProps.value, style = mergeProps.style, className = mergeProps.className, rest = __rest(mergeProps, ["disabled", "children", "value", "style", "className"]);
  var _c = __read(useMergeValue(false, {
    value: mergeProps.checked,
    defaultValue: mergeProps.defaultChecked
  }), 2), checked = _c[0], setChecked = _c[1];
  var classNames$1 = classNames("" + prefixCls + (context.type === "button" ? "-button" : ""), (_a = {}, _a[prefixCls + "-checked"] = checked, _a[prefixCls + "-disabled"] = disabled, _a[prefixCls + "-rtl"] = rtl, _a), className);
  var onChange = function(event) {
    var onChange2 = mergeProps.onChange, value2 = mergeProps.value;
    if (disabled) {
      return;
    }
    if (context.group) {
      context.onChangeValue && context.onChangeValue(value2, event);
    } else if (!("checked" in props) && !checked) {
      setChecked(true);
    }
    !checked && onChange2 && onChange2(true, event);
  };
  var onLabelClick = React__default.default.useCallback(function(e) {
    if (is.isFunction(props.children)) {
      e.preventDefault();
      inputRef.current && inputRef.current.click();
    }
    rest.onClick && rest.onClick(e);
  }, [props.children, rest.onClick]);
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs("label", {
    ...__assign({}, omit(rest, ["checked", "onChange"]), {
      onClick: onLabelClick,
      style,
      className: classNames$1
    }),
    children: [/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("input", {
      ...__assign({
        ref: inputRef,
        disabled,
        value: value || "",
        type: "radio"
      }, context.name ? {
        name: context.name
      } : {}, {
        checked,
        onChange: function(event) {
          event.persist();
          onChange(event);
        },
        onClick: function(e) {
          e.stopPropagation();
        }
      })
    }), is.isFunction(children) ? children({
      checked
    }) : context.type === "radio" ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsxs(emotionReactJsxRuntime_browser_esm.Fragment, {
      children: [/* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(iconHover, {
        prefix: prefixCls,
        className: prefixCls + "-mask-wrapper",
        disabled: checked || disabled,
        children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("div", {
          className: prefixCls + "-mask"
        })
      }), children && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
        className: prefixCls + "-text",
        children
      })]
    }) : context.type === "button" && /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
      className: prefixCls + "-button-inner",
      children
    })]
  });
}
Radio.__BYTE_RADIO = true;
Radio.displayName = "Radio";
Radio.Group = group.default;
Radio.GroupContext = group.RadioGroupContext;
module.exports = Radio;
//# sourceMappingURL=radio.js.map
