import { jsxs as N, jsx as n } from "react/jsx-runtime";
import { useRef as O } from "react";
import { noop as g } from "es-toolkit/compat";
import x from "../../utils/classNames.js";
const S = (s) => {
  const { icon: o, iconSize: e, iconLabelPosition: a, text: i } = s, l = {
    width: `${e}px`,
    height: `${e}px`,
    fontSize: `${e}px`,
    lineHeight: `${e}px`
  };
  return /* @__PURE__ */ N("span", { className: `radio-icon label-${a}`, children: [
    /* @__PURE__ */ n("span", { className: `rioglyph ${o}`, style: l }),
    /* @__PURE__ */ n("span", { className: "radio-label", children: i })
  ] });
}, k = (s) => {
  const {
    icon: o = "",
    iconLabelPosition: e = "vertical",
    iconSize: a = 16,
    label: i,
    onClick: l = g,
    onChange: m = g,
    checked: c,
    defaultChecked: I,
    disabled: u = !1,
    className: h,
    inline: L = !1,
    right: y = !1,
    custom: f = !1,
    name: R,
    value: $,
    tabIndex: D = 0,
    inputRef: v,
    children: r,
    ...w
  } = s, p = c != null, d = O(null), z = (t) => {
    switch (t.key) {
      case " ":
      // toggle on space
      case "Enter":
        A(t);
        break;
    }
  }, A = (t) => {
    if (t.preventDefault(), !u) {
      if (p) {
        m(t);
        return;
      }
      if (d.current) {
        const b = d.current.firstChild;
        b.checked = !b.checked;
      }
    }
  }, C = i || r, B = x("radio", L && "radio-inline", h), E = x(y && "icon-right", h);
  return /* @__PURE__ */ N(
    "label",
    {
      ...w,
      className: B,
      tabIndex: D,
      onKeyDown: z,
      ref: d,
      children: [
        /* @__PURE__ */ n(
          "input",
          {
            type: "radio",
            defaultChecked: I,
            checked: c,
            disabled: u,
            className: E,
            ref: v,
            onClick: l,
            onChange: p ? m : void 0,
            name: R,
            value: $
          }
        ),
        !!o && /* @__PURE__ */ n(S, { icon: o, iconSize: a, iconLabelPosition: e, text: C }),
        !o && !f && /* @__PURE__ */ n("span", { className: "radio-text", children: /* @__PURE__ */ n("span", { children: C }) }),
        f && r && r
      ]
    }
  );
};
k.ICON_LABEL_VERTICAL = "vertical";
k.ICON_LABEL_HORIZONTAL = "horizontal";
export {
  k as default
};
//# sourceMappingURL=RadioButton.js.map
