/*! © 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_Checkbox_checkboxConstants = require("./checkboxConstants.cjs");
let react = require("react");
react = require_runtime.__toESM(react);
let react_jsx_runtime = require("react/jsx-runtime");
//#region src/components/client/Checkbox/CheckboxBase.tsx
const CheckboxBase = (0, react.forwardRef)(function CheckboxBase({ id, checked: checkedProp, defaultChecked, onChange, label, labelPosition = "start", variant: variantProp = "primary", size = "md", reduceMotion: _reduceMotion, disabled, required, hasError, className, style, slotProps, cssAnimationDuration, enableInteractionTracking = false, renderRoot, renderIndicator, ...checkboxProps }, parentRef) {
	const generatedId = (0, react.useId)();
	const uid = id ?? `uds-input-${generatedId}`;
	const rootSlotProps = slotProps?.root ?? {};
	const checkboxSlotProps = slotProps?.checkbox ?? {};
	const iconSlotProps = slotProps?.icon ?? {};
	const labelSlotProps = slotProps?.label ?? {};
	const innerRef = (0, react.useRef)(null);
	/**
	* State
	*/
	const isControlled = checkedProp !== void 0;
	const [checked, setChecked] = (0, react.useState)(isControlled ? 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_Checkbox_checkboxConstants.VARIANT_ERROR_MAP[variantProp] : variantProp, [hasError, variantProp]);
	const showHoverEffect = enableInteractionTracking && !disabled && isHovered;
	const showPressedEffect = enableInteractionTracking && !disabled && isPressed;
	/**
	* Handlers
	*/
	const handleChange = (0, react.useCallback)((e) => {
		onChange?.(e);
		if (!isControlled) setChecked(e.target.checked);
	}, [isControlled, onChange]);
	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]);
	/**
	* Helpers
	*/
	const setDOMIndeterminate = (checked_) => {
		if (!innerRef.current) return;
		innerRef.current.indeterminate = require_components_client_Checkbox_checkboxConstants.isIndeterminate(checked_);
	};
	/**
	* Effects
	*/
	(0, react.useEffect)(() => {
		if (isControlled) setChecked(checkedProp);
	}, [checkedProp, isControlled]);
	(0, react.useEffect)(() => {
		setDOMIndeterminate(checked);
	}, [checked]);
	const valueState = require_components_client_Checkbox_checkboxConstants.isIndeterminate(checked) ? "indeterminate" : checked ? "checked" : "unchecked";
	const classNames = {
		root: require_styles_styler.getStyles({
			checkboxSizeRoot: size,
			checkboxVariantRoot: variant,
			checkboxVariantValueRoot: valueState,
			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)
		}),
		htmlCheckbox: 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: "checkbox",
		tabIndex: 0,
		...checkboxProps,
		ref: (ref) => {
			innerRef.current = ref;
			setDOMIndeterminate(checked);
			if (typeof parentRef === "function") parentRef(ref);
			else if (parentRef !== null) parentRef.current = ref;
		},
		id: uid,
		disabled,
		required,
		"aria-invalid": hasError,
		checked: isControlled ? require_components_client_Checkbox_checkboxConstants.isIndeterminate(checked) ? false : checked : void 0,
		defaultChecked: isControlled ? void 0 : defaultChecked,
		onChange: handleChange,
		className: classNames.htmlCheckbox
	});
	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,
			valueState,
			checked,
			disabled,
			showHoverEffect,
			showPressedEffect,
			cssAnimationDuration,
			checkIcon: require_components_client_Checkbox_checkboxConstants.getIcon(checked),
			checkboxSlotProps,
			iconSlotProps,
			children: input
		}), label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_FormLabel.FormLabel, {
			as: "div",
			variant: "inherit",
			color: "inherit",
			required,
			label,
			className: classNames.label,
			...labelSlotProps
		})] })
	});
});
CheckboxBase.displayName = "CheckboxBase";
//#endregion
exports.CheckboxBase = CheckboxBase;
