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 classNames from "classnames";
import React from "react";
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
		})
	] });
};
var Label = ({ afterLabelChildren, children, className, formFieldTag, htmlFor, htmlMarkup = "label", labelClassName, labelTextClassName, labelId, labelTexts, onColor = FormOnColor.onwhite, statusDot, sublabel, sublabelWrapperClassName, testId, afterLabelChildrenClassName }) => {
	const hasChildren = children && typeof children !== "undefined";
	const labelWrapperClasses = classNames(styles["label-wrapper"], { [styles["label-wrapper--no-bottom-margin"]]: hasChildren }, className);
	const mainLabelWrapperClasses = classNames({ [styles["label-wrapper--after-label-children"]]: afterLabelChildren });
	const afterLabelChildrenClasses = classNames(styles["after-label-children"], afterLabelChildrenClassName);
	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", {
			className: mainLabelWrapperClasses,
			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()
					})]
				})
			}), afterLabelChildren && /* @__PURE__ */ jsx("div", {
				className: afterLabelChildrenClasses,
				children: afterLabelChildren
			})]
		}), (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" })] })
			]
		})]
	});
};
var Label_default = Label;
const getLabelText = (label) => {
	let allLabelText = "";
	if (isComponent(label, Label_default)) label.props.labelTexts?.forEach((labelText) => {
		allLabelText += !labelText.hideFromScreenReader ? labelText.text : "";
	});
	return allLabelText;
};
const renderLabel = (props) => {
	return /* @__PURE__ */ jsx(Fragment, { children: props.label && isComponent(props.label, Label_default) ? React.cloneElement(props.label, {
		htmlFor: props.inputId,
		htmlMarkup: props.markup || "label",
		onColor: props.onColor
	}) : typeof props.label === "string" && /* @__PURE__ */ jsx(Label_default, {
		labelTexts: [{
			text: props.label,
			type: "normal"
		}],
		htmlFor: props.inputId,
		onColor: props.onColor
	}) });
};
const renderLabelAsParent = (props) => {
	return /* @__PURE__ */ jsx(Fragment, { children: props.label && isComponent(props.label, Label_default) ? React.cloneElement(props.label, {
		htmlFor: props.inputId,
		onColor: props.onColor,
		children: props.children,
		labelClassName: classNames(props.labelClassName, props.label.props.labelClassName),
		labelTextClassName: props.labelTextClassName,
		htmlMarkup: props.markup || "label",
		sublabelWrapperClassName: props.sublabelWrapperClassName,
		sublabel: props.large ? void 0 : props.label.props.sublabel,
		statusDot: props.large ? void 0 : props.label.props.statusDot,
		afterLabelChildrenClassName: props.afterLabelChildrenClassName
	}) : typeof props.label === "string" && /* @__PURE__ */ jsx(Label_default, {
		labelTexts: [{
			text: props.label,
			type: "subdued"
		}],
		htmlFor: props.inputId,
		onColor: props.onColor,
		htmlMarkup: props.markup || "label",
		labelClassName: props.labelClassName,
		labelTextClassName: props.labelTextClassName,
		sublabelWrapperClassName: props.sublabelWrapperClassName,
		afterLabelChildrenClassName: props.afterLabelChildrenClassName,
		children: props.children
	}) });
};
export { Sublabel as a, Label_default as i, renderLabel as n, renderLabelAsParent as r, getLabelText as t };

//# sourceMappingURL=utils2.js.map