import { t as e } from "./ui.module-DHVTOqZ0.js";
import { createContext as t, useCallback as n, useContext as r, useId as i, useLayoutEffect as a, useMemo as o, useState as s } from "react";
import { cn as c, getRovingFocusTargetIndex as l, handleKeyboardActivation as u } from "@ryuzaki13/react-foundation-lib/utils";
import { jsx as d, jsxs as f } from "react/jsx-runtime";
import { CheckCircleIcon as p } from "lucide-react";
var m = {
	radioGroup: "nINbA6",
	noWrap: "GL-UWx",
	horizontal: "_6PeF-i",
	vertical: "_5wP4aR",
	radioItem: "S3MnZI",
	checked: "KHJ0ja",
	radioItemContent: "oGmcQH",
	radioItemIcon: "k2z8AN"
}, h = t(null);
function g({ value: t, onChange: r, label: a, description: l, disabled: u, className: p, noWrap: g, orientation: _ = "horizontal", "aria-label": v, children: y }) {
	let b = i(), x = a ? `${b}-label` : void 0, S = l ? `${b}-description` : void 0, [C, w] = s([]), T = n((e) => r?.(e), [r]), E = n((e) => (w((t) => t.includes(e) ? t : [...t, e]), () => {
		w((t) => t.filter((t) => t !== e));
	}), []), D = o(() => ({
		value: t,
		onChange: T,
		disabled: u,
		orientation: _,
		groupId: b,
		labelId: x,
		descriptionId: S,
		firstOptionId: C[0],
		registerOption: E
	}), [
		S,
		u,
		b,
		T,
		x,
		_,
		E,
		C,
		t
	]);
	return /* @__PURE__ */ f("div", {
		className: c(e.uiElement, u && e.disabled, p),
		children: [
			a && /* @__PURE__ */ d("div", {
				id: x,
				className: e.uiLabel,
				children: a
			}),
			l && /* @__PURE__ */ d("div", {
				id: S,
				className: e.uiDescription,
				children: l
			}),
			/* @__PURE__ */ d(h.Provider, {
				value: D,
				children: /* @__PURE__ */ d("div", {
					role: "radiogroup",
					"aria-labelledby": x,
					"aria-label": x ? void 0 : v,
					"aria-describedby": S,
					"aria-disabled": u || void 0,
					"data-disabled": u || void 0,
					className: c(e.uiInputControl, m.radioGroup, g && m.noWrap, m[_]),
					children: y
				})
			})
		]
	});
}
function _({ value: e, label: t, description: n, className: o }) {
	let s = r(h), g = i(), _ = s?.registerOption;
	if (a(() => {
		if (_) return _(g);
	}, [_, g]), !s) return /* @__PURE__ */ f("div", {
		className: c(m.radioItem, o),
		children: [/* @__PURE__ */ d("p", {
			className: "textNoWrap",
			children: t
		}), n && /* @__PURE__ */ d("div", {
			className: "fontSizeSm content2",
			children: n
		})]
	});
	let v = Object.is(s.value, e), y = s.disabled === !0, b = s.value === void 0 && s.firstOptionId === g, x = () => {
		y || v || s.onChange?.(e);
	};
	return /* @__PURE__ */ f("button", {
		id: `${s.groupId}-option-${g}`,
		type: "button",
		role: "radio",
		"aria-checked": v,
		disabled: y,
		tabIndex: v || b ? 0 : -1,
		className: c(m.radioItem, v && m.checked, o),
		"data-ui": "radio-option",
		"data-action": "select-radio-option",
		onClick: x,
		onKeyDown: (e) => {
			if (y || u(e, x)) return;
			let t = e.currentTarget, n = t.closest("[role=\"radiogroup\"]"), r = Array.from(n?.querySelectorAll("[role=\"radio\"]:not([disabled])") ?? []);
			if (!r.length) return;
			let i = r.indexOf(t);
			if (i === -1) return;
			let a = l({
				currentIndex: i,
				itemCount: r.length,
				key: e.key,
				orientation: s.orientation
			});
			a !== null && (e.preventDefault(), r[a]?.focus(), r[a]?.click());
		},
		children: [/* @__PURE__ */ f("span", {
			className: m.radioItemContent,
			children: [/* @__PURE__ */ d("span", {
				className: "textNoWrap",
				children: t
			}), n && /* @__PURE__ */ d("span", {
				className: "fontSizeSm",
				children: n
			})]
		}), /* @__PURE__ */ d("span", {
			className: m.radioItemIcon,
			children: /* @__PURE__ */ d(p, { style: {
				display: "block",
				visibility: v ? "visible" : "hidden"
			} })
		})]
	});
}
g.Option = _;
//#endregion
export { g as n, _ as t };

//# sourceMappingURL=radio-group-BAeJjyZ5.js.map