import { a as IconSize, n as AnalyticsId } from "../../constants2.js";
import { t as usePseudoClasses } from "../../usePseudoClasses.js";
import { t as Icon_default } from "../../Icon.js";
import { t as isComponent } from "../../component.js";
import { t as ChevronDown_default } from "../../ChevronDown.js";
import { t as ChevronUp_default } from "../../ChevronUp.js";
import { t as useExpand } from "../../useExpand.js";
import classNames from "classnames";
import React from "react";
import { jsx, jsxs } from "react/jsx-runtime";
import styles from "./expander.module.scss";
import styles$1 from "./styles.module.scss";
var ExpanderButton = ({ htmlMarkup = "h2", level = 1, print, expanded, onExpand, children, testId }) => {
	const { refObject, isHovered } = usePseudoClasses();
	const [isExpanded, setIsExpanded] = useExpand(expanded, onExpand);
	const handleClick = () => {
		setIsExpanded(!isExpanded);
	};
	const CustomTag = htmlMarkup;
	const buttonClasses = classNames(styles.expander__button, level > 1 && styles[`expander__button--2-and-lower`], print && styles["expander__button--print"]);
	const titleClasses = classNames(styles.expander__title, (level === 1 || level === 2 || level === 3) && styles[`expander__title--${level}`], level > 3 && styles[`expander__title--4-and-lower`], isExpanded && styles["expander__title--expanded"], print && styles["expander__title--print"]);
	const iconClasses = classNames(styles.expander__icon, level > 1 && styles[`expander__icon--2-and-lower`], level > 2 && styles[`expander__icon--3-and-lower`]);
	return /* @__PURE__ */ jsx(CustomTag, {
		className: titleClasses,
		children: /* @__PURE__ */ jsxs("button", {
			type: "button",
			onClick: handleClick,
			className: buttonClasses,
			"aria-expanded": isExpanded,
			ref: refObject,
			"data-testid": testId,
			"data-analyticsid": AnalyticsId.ExpanderHierarchyExpander,
			children: [children, /* @__PURE__ */ jsx(Icon_default, {
				svgIcon: isExpanded ? ChevronUp_default : ChevronDown_default,
				isHovered,
				className: iconClasses,
				size: IconSize.XSmall
			})]
		})
	});
};
var ExpanderButton_default = ExpanderButton;
const getHeadingTag = (htmlMarkup) => {
	switch (htmlMarkup) {
		case "h2": return "h3";
		case "h3": return "h4";
		case "h4": return "h5";
		case "h5": return "h6";
		case "h6": return "h6";
		default: return "h2";
	}
};
var Expander = ({ title, htmlMarkup = "h2", level = 1, print, expanded = false, onExpand, children, testId, className, ref }) => {
	const contentClasses = classNames(styles.expander__content, (level === 1 || level === 2) && styles[`expander__content--${level}`], level > 2 && styles[`expander__content--3-and-lower`]);
	return /* @__PURE__ */ jsxs("li", {
		className: classNames(styles.expander, className),
		ref,
		children: [/* @__PURE__ */ jsx(ExpanderButton_default, {
			htmlMarkup,
			level,
			print,
			expanded,
			onExpand,
			testId,
			children: title
		}), /* @__PURE__ */ jsx("div", {
			className: contentClasses,
			children: React.Children.map(children, (child) => isComponent(child, ExpanderHierarchy_default$1) ? React.cloneElement(child, {
				htmlMarkup: getHeadingTag(htmlMarkup),
				level: level + 1,
				print
			}) : child)
		})]
	});
};
var Expander_default = Expander;
var ExpanderHierarchy = ({ htmlMarkup = "h2", level = 1, print, children, testId }) => {
	return /* @__PURE__ */ jsx("ul", {
		className: classNames(styles$1.expanderhierarchy, level === 2 && styles$1[`expanderhierarchy--${level}`], level > 2 && styles$1[`expanderhierarchy--3-and-lower`]),
		"data-testid": testId,
		"data-analyticsid": AnalyticsId.ExpanderHierarchy,
		children: React.Children.map(children, (child) => isComponent(child, Expander_default) ? React.cloneElement(child, {
			htmlMarkup,
			level,
			print
		}) : child)
	});
};
ExpanderHierarchy.Expander = Expander_default;
var ExpanderHierarchy_default$1 = ExpanderHierarchy;
var ExpanderHierarchy_default = ExpanderHierarchy_default$1;
export { ExpanderHierarchy_default as default, getHeadingTag };

//# sourceMappingURL=index.js.map