import { t as e } from "./ui.module-BisoTevy.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";
var p = {
	radioGroup: "nINbA6",
	noWrap: "GL-UWx",
	horizontal: "_6PeF-i",
	vertical: "_5wP4aR",
	radioItem: "S3MnZI",
	checked: "KHJ0ja"
}, m = t(null);
function h({ value: t, onChange: r, label: a, description: l, disabled: u, className: h, 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, h),
		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(m.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, p.radioGroup, g && p.noWrap, p[_]),
					children: y
				})
			})
		]
	});
}
function g({ value: e, label: t, description: n, className: o }) {
	let s = r(m), h = i(), g = s?.registerOption;
	if (a(() => {
		if (g) return g(h);
	}, [g, h]), !s) return /* @__PURE__ */ f("div", {
		className: c(p.radioItem, o),
		children: [/* @__PURE__ */ d("p", {
			className: "textNoWrap",
			children: t
		}), n && /* @__PURE__ */ d("div", {
			className: "fontSizeSm content2",
			children: n
		})]
	});
	let _ = Object.is(s.value, e), v = s.disabled === !0, y = s.value === void 0 && s.firstOptionId === h, b = () => {
		v || _ || s.onChange?.(e);
	};
	return /* @__PURE__ */ f("button", {
		id: `${s.groupId}-option-${h}`,
		type: "button",
		role: "radio",
		"aria-checked": _,
		disabled: v,
		tabIndex: _ || y ? 0 : -1,
		className: c(p.radioItem, _ && p.checked, o),
		"data-ui": "radio-option",
		"data-action": "select-radio-option",
		onClick: b,
		onKeyDown: (e) => {
			if (v || u(e, b)) 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__ */ d("p", {
			className: "textNoWrap",
			children: t
		}), n && /* @__PURE__ */ d("div", {
			className: "fontSizeSm content2",
			children: n
		})]
	});
}
h.Option = g;
//#endregion
export { h as n, g as t };

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