import { a as D, p as d, v as u } from "./vendor-preact-DThS2ZQ_.js";
import { n as cn } from "./loadingIcon-B0ysgiNq.js";
import { t as ErrorIcon } from "./errorIcon-BA4T6iy-.js";
import { d as CheckmarkIcon } from "./icons-CJJbIpBq.js";
//#region src/shared/checkbox/checkbox.tsx
var Checkbox = D(({ id, label, labelHint, size = "m", checked, defaultChecked, disabled = false, required = false, name, value, onChange, error, helper, showErrorIcon = true, class: className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, ...restProps }, ref) => {
	const [internalChecked, setInternalChecked] = d(!!defaultChecked);
	const isControlled = checked !== void 0;
	const isChecked = isControlled ? !!checked : internalChecked;
	const isDisabled = !!disabled;
	const isRequired = !!required;
	const classStr = typeof className === "string" ? className : void 0;
	const handleChange = (event) => {
		if (!isControlled) setInternalChecked(event.target.checked);
		onChange?.(event);
	};
	const helperTextId = helper ? `${id}-helper` : void 0;
	const errorTextId = error ? `${id}-error` : void 0;
	const describedBy = [
		ariaDescribedBy,
		errorTextId,
		helperTextId
	].filter(Boolean).join(" ") || void 0;
	return /* @__PURE__ */ u("div", {
		class: cn("IncodeCheckbox", classStr),
		children: [
			/* @__PURE__ */ u("label", {
				class: cn("IncodeCheckboxLabel", { IncodeCheckboxLabelDisabled: isDisabled }),
				htmlFor: id,
				children: [/* @__PURE__ */ u("div", {
					class: "relative inline-flex",
					children: [/* @__PURE__ */ u("input", {
						ref,
						type: "checkbox",
						class: "IncodeCheckboxInput",
						id,
						name,
						value,
						...isControlled ? { checked } : { defaultChecked },
						disabled,
						required,
						onChange: handleChange,
						"aria-label": ariaLabel,
						"aria-labelledby": ariaLabelledBy,
						"aria-describedby": describedBy,
						"aria-invalid": ariaInvalid || !!error,
						"aria-required": isRequired,
						...restProps
					}), /* @__PURE__ */ u("div", {
						class: cn("IncodeCheckboxVisual", {
							IncodeCheckboxVisualChecked: isChecked,
							IncodeCheckboxVisualDisabled: isDisabled,
							IncodeCheckboxVisualError: !!error
						}),
						children: isChecked && /* @__PURE__ */ u(CheckmarkIcon, { size: 28 })
					})]
				}), label && /* @__PURE__ */ u("span", {
					class: cn("IncodeCheckboxText", {
						IncodeCheckboxTextS: size === "s",
						IncodeCheckboxTextM: size === "m",
						IncodeCheckboxTextDisabled: isDisabled
					}),
					"aria-hidden": ariaLabelledBy ? "true" : void 0,
					children: [label, labelHint && /* @__PURE__ */ u("span", {
						class: "IncodeCheckboxLabelHint",
						"data-testid": `${id}-label-hint`,
						children: labelHint
					})]
				})]
			}),
			error && /* @__PURE__ */ u("div", {
				class: "IncodeCheckboxMessageWrapper",
				"data-testid": `${id}-error-wrapper`,
				children: [showErrorIcon && /* @__PURE__ */ u("div", {
					class: "IncodeCheckboxIconWrapper",
					children: /* @__PURE__ */ u(ErrorIcon, { size: 17 })
				}), /* @__PURE__ */ u("p", {
					id: errorTextId,
					class: "IncodeCheckboxErrorText",
					children: error
				})]
			}),
			helper && !error && /* @__PURE__ */ u("div", {
				class: "IncodeCheckboxMessageWrapper",
				"data-testid": `${id}-helper-wrapper`,
				children: /* @__PURE__ */ u("p", {
					id: helperTextId,
					class: "IncodeCheckboxHelperText",
					children: helper
				})
			})
		]
	});
});
//#endregion
export { Checkbox as t };
