/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
"use client";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
const require_styles_styler = require("../../../styles/styler.cjs");
const require_components_FormLabel = require("../../FormLabel.cjs");
const require_components_client_Radio_radioConstants = require("./radioConstants.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/RadioBase.tsx
const RadioBase = (0, react.forwardRef)(function RadioBase({ id, name: nameProp, label, labelPosition = "start", variant: variantProp = "primary", size = "md", reduceMotion: _reduceMotion, value: valueProp = "", checked: checkedProp, defaultChecked, disabled, hasError, onChange, onFocus, onBlur, className, style, slotProps, cssAnimationDuration, enableInteractionTracking = false, renderRoot, renderIndicator, ...radioProps }, parentRef) {
	const generatedId = (0, react.useId)();
	const uid = id ?? `uds-radio-${generatedId}`;
	const rootSlotProps = slotProps?.root ?? {};
	const radioSlotProps = slotProps?.radio ?? {};
	const radioIconSlotProps = slotProps?.radioIcon ?? {};
	const labelSlotProps = slotProps?.label ?? {};
	const innerRef = (0, react.useRef)(null);
	/**
	* State
	*/
	const { name, isControlled, checked, setGroupValue } = require_components_client_Radio_useRadioGroup.useRadioGroup({
		name: nameProp,
		value: valueProp,
		checked: checkedProp,
		defaultChecked
	});
	const [isHovered, setIsHovered] = (0, react.useState)(false);
	const [isPressed, setIsPressed] = (0, react.useState)(false);
	/**
	* Derived values
	*/
	const variant = (0, react.useMemo)(() => hasError ? require_components_client_Radio_radioConstants.VARIANT_ERROR_MAP[variantProp] : variantProp, [hasError, variantProp]);
	const showHoverEffect = enableInteractionTracking && !disabled && isHovered;
	const showPressedEffect = enableInteractionTracking && !disabled && !checked && isPressed;
	/**
	* Handlers
	*/
	const handleOnChange = (0, react.useCallback)((e) => {
		setGroupValue(e.target.value);
		onChange?.(e);
	}, [onChange, setGroupValue]);
	const handleFocus = (0, react.useCallback)((e) => {
		onFocus?.(e);
	}, [onFocus]);
	const handleBlur = (0, react.useCallback)((e) => {
		onBlur?.(e);
	}, [onBlur]);
	const handleHoverStart = (0, react.useCallback)(() => {
		if (enableInteractionTracking) setIsHovered(true);
	}, [enableInteractionTracking]);
	const handleHoverEnd = (0, react.useCallback)(() => {
		if (enableInteractionTracking) setIsHovered(false);
	}, [enableInteractionTracking]);
	const handleTapStart = (0, react.useCallback)(() => {
		if (enableInteractionTracking) setIsPressed(true);
	}, [enableInteractionTracking]);
	const handleTapEnd = (0, react.useCallback)(() => {
		if (enableInteractionTracking) setIsPressed(false);
	}, [enableInteractionTracking]);
	const classNames = {
		root: require_styles_styler.getStyles({
			radioSizeRoot: size,
			radioVariantValueRoot: checked ? "checked" : "unchecked",
			radioVariantRoot: variant,
			display: "flex",
			flexDirection: labelPosition === "start" ? "row" : "row-reverse",
			alignItems: "center",
			className: require_styles_styler.cx([{
				"cursor-pointer": !disabled,
				"cursor-default": disabled,
				"opacity-50": disabled
			}, className])
		}),
		htmlRadio: require_styles_styler.cx("cursor-[inherit]", "absolute", "opacity-0", "top-1/2", "left-1/2", "w-[calc(100%+2px)]", "h-[calc(100%+2px)]", "transform", "translate-x-[-50%]", "translate-y-[-50%]"),
		label: require_styles_styler.cx(labelPosition === "start" ? "text-start" : "text-end")
	};
	const input = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
		type: "radio",
		tabIndex: 0,
		...radioProps,
		ref: (ref) => {
			innerRef.current = ref;
			if (typeof parentRef === "function") parentRef(ref);
			else if (parentRef !== null) parentRef.current = ref;
		},
		onFocus: handleFocus,
		onBlur: handleBlur,
		id: uid,
		name,
		value: valueProp,
		disabled,
		"aria-invalid": hasError,
		onChange: handleOnChange,
		...isControlled ? { checked } : { defaultChecked },
		className: classNames.htmlRadio
	});
	return renderRoot({
		className: classNames.root,
		style,
		rootSlotProps,
		hasLabel: Boolean(label),
		isPressed,
		onHoverStart: handleHoverStart,
		onHoverEnd: handleHoverEnd,
		onTapStart: handleTapStart,
		onTapEnd: handleTapEnd,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [renderIndicator({
			size,
			variant,
			checked: Boolean(checked),
			disabled,
			showHoverEffect,
			showPressedEffect,
			cssAnimationDuration,
			radioSlotProps,
			radioIconSlotProps,
			children: input
		}), label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_FormLabel.FormLabel, {
			as: "div",
			variant: "inherit",
			color: "inherit",
			label,
			className: classNames.label,
			...labelSlotProps
		})] })
	});
});
RadioBase.displayName = "RadioBase";
//#endregion
exports.RadioBase = RadioBase;
