"use client";
/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
const require_utils_createSlot = require('../../../utils/createSlot.cjs');
const require_components_client_Radio_RadioGroupStore = require('./RadioGroupStore.cjs');
const require_components_client_Radio_useRadioGroup = require('./useRadioGroup.cjs');
let react = require("react");
react = require_runtime.__toESM(react);
let react_jsx_runtime = require("react/jsx-runtime");

//#region src/components/client/Radio/RadioGroupProvider.tsx
const Slot = require_utils_createSlot.createSlot();
/**
* A custom RadioGroupStore that extends the default RadioGroupStore to allow for controlled RadioGroups.
*/
var RadioGroupProviderStore = class extends require_components_client_Radio_RadioGroupStore.RadioGroupStore {
	onChangeCb;
	isControlled;
	constructor(name, isControlled) {
		super(name);
		this.isControlled = isControlled;
	}
	setValue(value, force = false) {
		if (!this.isControlled || force) {
			super.setValue(value);
			return;
		}
		this.onChangeCb?.(value);
	}
};
/**
* **⚙️️ A RadioGroup that improves accessibility and provides a central component for state manangement.
*
* @componentType Client component
*
* @description
* Provides a radio group
*
* @see
* Check out the {@link https://uds.build/docs/components/radio Radio Docs} for more info
*
* @usage
* - Forms: RadioGroup
*
* @example
* ```tsx
* 'use client';
* import { RadioGroup } from "@yahoo/uds";
*
* <RadioGroup name="items" value="1">
*   <Radio value="1" label="One" />
*   <Radio value="2" label="Two" />
* </RadioGroup>
*```
*
* @related [Radio](https://uds.build/docs/components/radio).
**/
const RadioGroupProvider = (0, react.forwardRef)(function RadioGroupProvider({ asChild, name, value: valueProp, defaultValue, onChange, ...props }, ref) {
	const isControlled = valueProp !== void 0;
	const localName = require_components_client_Radio_useRadioGroup.useRadioGroupName(name);
	const store = (0, react.useMemo)(() => {
		const s = new RadioGroupProviderStore(localName, isControlled);
		s.value = isControlled ? valueProp : defaultValue;
		return s;
	}, [
		defaultValue,
		isControlled,
		localName,
		valueProp
	]);
	(0, react.useEffect)(() => {
		store.onChangeCb = onChange;
	}, [onChange, store]);
	(0, react.useEffect)(() => {
		if (!isControlled) return;
		store.setValue(valueProp, true);
	}, [
		isControlled,
		store,
		valueProp
	]);
	(0, react.useEffect)(() => {
		return store.onChange((value) => onChange?.(value));
	}, [onChange, store]);
	const Comp = asChild ? Slot : "div";
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_Radio_RadioGroupStore.RadioGroupContext.Provider, {
		value: store,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Comp, {
			role: "radiogroup",
			ref,
			...props
		})
	});
});
RadioGroupProvider.displayName = "RadioGroupProvider";

//#endregion
exports.RadioGroupProvider = RadioGroupProvider;