import { n as AnalyticsId, r as FormOnColor } from "./constants2.js";
import { t as isComponent } from "./component.js";
import { t as Spacer_default } from "./Spacer.js";
import { t as FormFieldTag_default } from "./FormFieldTag.js";
import { t as StatusDot_default } from "./StatusDot.js";
import React from "react";
import classNames from "classnames";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import styles from "./components/Label/styles.module.scss";
const Sublabel = ({ children, className, id, onColor, sublabelTexts, testId }) => {
	const mapSublabels = (hideFromScreenReader) => {
		return sublabelTexts && sublabelTexts.map((sublabelText, index) => {
			const labelClasses = classNames(styles.label, styles["sublabel"], {
				[styles["sublabel--subdued"]]: sublabelText.type === "subdued",
				[styles["sublabel--on-dark"]]: onColor === FormOnColor.ondark
			});
			return hideFromScreenReader === sublabelText.hideFromScreenReader && /* @__PURE__ */ jsx("span", {
				className: labelClasses,
				children: sublabelText.text
			}, index);
		});
	};
	const subLabels = mapSublabels();
	const ariaHiddenSublabels = mapSublabels(true);
	return /* @__PURE__ */ jsxs(Fragment, { children: [
		/* @__PURE__ */ jsx(Spacer_default, { size: "3xs" }),
		(subLabels || children) && /* @__PURE__ */ jsxs("div", {
			className,
			id,
			"data-testid": testId,
			"data-analyticsid": AnalyticsId.Sublabel,
			children: [subLabels, children]
		}),
		ariaHiddenSublabels && /* @__PURE__ */ jsx("div", {
			className,
			"data-testid": testId,
			children: ariaHiddenSublabels
		})
	] });
};
const getLabelText = (label) => {
	let allLabelText = "";
	if (isComponent(label, Label)) label.props.labelTexts?.forEach((labelText) => {
		allLabelText += !labelText.hideFromScreenReader ? labelText.text : "";
	});
	return allLabelText;
};
const renderLabel = (label, inputId, onColor, markup) => {
	return /* @__PURE__ */ jsx(Fragment, { children: label && isComponent(label, Label) ? React.cloneElement(label, {
		htmlFor: inputId,
		htmlMarkup: markup || "label",
		onColor
	}) : typeof label === "string" && /* @__PURE__ */ jsx(Label, {
		labelTexts: [{
			text: label,
			type: "normal"
		}],
		htmlFor: inputId,
		onColor
	}) });
};
const renderLabelAsParent = (label, children, inputId, onColor, labelClassName, labelTextClassName, sublabelWrapperClassName, large, markup) => {
	return /* @__PURE__ */ jsx(Fragment, { children: label && isComponent(label, Label) ? React.cloneElement(label, {
		htmlFor: inputId,
		onColor,
		children,
		labelClassName: classNames(labelClassName, label.props.labelClassName),
		labelTextClassName,
		htmlMarkup: markup || "label",
		sublabelWrapperClassName,
		sublabel: large ? void 0 : label.props.sublabel,
		statusDot: large ? void 0 : label.props.statusDot
	}) : typeof label === "string" && /* @__PURE__ */ jsx(Label, {
		labelTexts: [{
			text: label,
			type: "subdued"
		}],
		htmlFor: inputId,
		onColor,
		htmlMarkup: markup || "label",
		labelClassName,
		labelTextClassName,
		sublabelWrapperClassName,
		children
	}) });
};
var Label = ({ afterLabelChildren, children, className, formFieldTag, htmlFor, htmlMarkup = "label", labelClassName, labelTextClassName, labelId, labelTexts, onColor = FormOnColor.onwhite, statusDot, sublabel, sublabelWrapperClassName, testId }) => {
	const hasChildren = children && typeof children !== "undefined";
	const labelWrapperClasses = classNames(styles["label-wrapper"], {
		[styles["label-wrapper--no-bottom-margin"]]: hasChildren,
		[styles["label-wrapper--after-label-children"]]: afterLabelChildren
	}, className);
	const mapLabels = () => {
		if (typeof labelTexts === "undefined") return null;
		return labelTexts.map((labelText, index) => {
			const labelClasses = classNames(styles.label, {
				[styles["label--subdued"]]: labelText.type === "subdued",
				[styles["label--on-dark"]]: onColor === FormOnColor.ondark
			}, labelTextClassName);
			return /* @__PURE__ */ jsx("span", {
				"aria-hidden": labelText.hideFromScreenReader,
				className: labelClasses,
				children: labelText.text
			}, index);
		});
	};
	return /* @__PURE__ */ jsxs("div", {
		className: labelWrapperClasses,
		children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(htmlMarkup, {
			className: labelClassName,
			id: labelId,
			htmlFor,
			"data-testid": testId,
			"data-analyticsid": AnalyticsId.Label,
			children: /* @__PURE__ */ jsxs("span", {
				className: styles["label-content-wrapper"],
				children: [children, /* @__PURE__ */ jsx("span", {
					className: styles.label__texts,
					children: mapLabels()
				})]
			})
		}), (sublabel || statusDot || formFieldTag) && /* @__PURE__ */ jsxs("div", {
			className: sublabelWrapperClassName,
			children: [
				formFieldTag && isComponent(formFieldTag, FormFieldTag_default) && React.cloneElement(formFieldTag),
				sublabel && isComponent(sublabel, Sublabel) && React.cloneElement(sublabel, { onColor }),
				statusDot && isComponent(statusDot, StatusDot_default) && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Spacer_default, { size: "3xs" }), React.cloneElement(statusDot, { onColor: onColor === FormOnColor.ondark ? "ondark" : "onwhite" })] })
			]
		})] }), afterLabelChildren && /* @__PURE__ */ jsx("div", {
			className: styles["after-label-children"],
			children: afterLabelChildren
		})]
	});
};
var Label_default$1 = Label;
export { Sublabel as a, renderLabelAsParent as i, getLabelText as n, renderLabel as r, Label_default$1 as t };

//# sourceMappingURL=Label.js.map