import { cs } from "../utils/styles.js";
import "../utils/index.js";
import { omitThemingProps } from "../core/theme.js";
import { vui } from "../core/vui.js";
import box_default from "../box/box.js";
import "../box/index.js";
import icon_default from "../icon/icon.js";
import "../icon/index.js";
import t_default from "../t/t.js";
import "../t/index.js";
import button_default from "../button/button.js";
import "../button/index.js";
import "../core/index.js";
import Popover from "../popover/popover.js";
import "../popover/index.js";
import { collapsedWidth, expandedWidth } from "./consts.js";
import useSidemenuItem_default from "./useSidemenuItem.js";
import { useEffect } from "react";
import { jsx, jsxs } from "react/jsx-runtime";

//#region src/sidemenu/sidemenuItem.tsx
/** A menu item. */
const SidemenuItem = vui((props, ref) => {
	const { className, children, icon, iconSize = "md", isActive, isExpanded = true, pl = 0, py = 0, onClick, onCollapse, onExpand, title, ...rest } = omitThemingProps(props);
	const { isExpandedVertically, setIsExpandedVertically, isDark, size, isExpandedHorizontally, styles } = useSidemenuItem_default(isExpanded);
	useEffect(() => {
		if (isExpandedVertically) onExpand?.();
		if (!isExpandedVertically) onCollapse?.();
	}, [isExpandedVertically]);
	const hasChildrenExpanded = !!children && isExpandedHorizontally;
	const InnerContent = () => /* @__PURE__ */ jsxs(box_default, {
		centerV: true,
		px: 1.5,
		py: 1,
		w: "100%",
		whiteSpace: "pre",
		children: [/* @__PURE__ */ jsx(icon_default, {
			ml: iconSize === "sm" ? "4px" : 0,
			name: icon,
			size: iconSize
		}), /* @__PURE__ */ jsx(t_default, {
			isTruncated: true,
			ml: 2,
			children: title
		})]
	});
	const toggle = (e) => {
		e.preventDefault();
		e.stopPropagation();
		setIsExpandedVertically(!isExpandedVertically);
	};
	const buttonStyles = {
		alignItems: "center",
		border: "none",
		borderRadius: 0,
		borderLeft: !hasChildrenExpanded && children ? "none" : "3px solid transparent",
		borderLeftColor: isActive ? isDark ? "digiGreen.main" : "seaBlue.main" : void 0,
		bg: isDark ? "darkBlue.main" : isActive ? "skyBlue.95" : "white",
		color: hasChildrenExpanded ? "seaBlue.main" : isDark ? "digiGreen.main" : "sandstone.10",
		h: "auto",
		justifyContent: "space-between",
		onClick: () => onClick?.(),
		pl,
		py,
		size: "md",
		variant: isDark ? "tertiaryLight" : "tertiaryDark",
		w: "100%",
		...styles.item,
		minH: size === "lg" ? "56px" : "40px",
		hoverBg: isDark ? "seaBlue.main" : "skyBlue.90",
		...rest
	};
	return /* @__PURE__ */ jsxs(box_default, {
		flexDirection: "column",
		ref,
		w: "100%",
		children: [!hasChildrenExpanded && children ? /* @__PURE__ */ jsxs(Popover, {
			offset: [0, collapsedWidth - expandedWidth - 2],
			placement: "right-start",
			trigger: "mouseenter",
			children: [/* @__PURE__ */ jsx(Popover.Trigger, {
				as: box_default,
				className: cs("vui-sidemenu-item-popover", className),
				children: /* @__PURE__ */ jsx(box_default, {
					...buttonStyles,
					borderLeft: `3px solid ${isDark ? "digiGreen.main" : "seaBlue.main"}`,
					children: /* @__PURE__ */ jsx(InnerContent, {})
				})
			}), /* @__PURE__ */ jsx(Popover.Content, {
				elevation: "none",
				children: /* @__PURE__ */ jsx(box_default, {
					flexDirection: "column",
					justifyContent: "start",
					w: "100%",
					children
				})
			})]
		}) : /* @__PURE__ */ jsxs(button_default, {
			className: cs("vui-sidemenu-item", className),
			...buttonStyles,
			children: [/* @__PURE__ */ jsx(InnerContent, {}), hasChildrenExpanded && /* @__PURE__ */ jsx(button_default, {
				"aria-label": isExpandedVertically ? "Collapse" : "Expand",
				className: "vui-sidemenu-item-expand",
				icon: isExpandedVertically ? "falChevronUp" : "falChevronDown",
				onClick: toggle,
				size: "sm",
				variant: isDark ? "tertiaryLight" : "tertiaryDark"
			})]
		}), !!children && hasChildrenExpanded && isExpandedVertically && /* @__PURE__ */ jsx(box_default, {
			flexDirection: "column",
			justifyContent: "start",
			w: "100%",
			children
		})]
	});
});
SidemenuItem.displayName = "SidemenuItem";
var sidemenuItem_default = SidemenuItem;

//#endregion
export { SidemenuItem, sidemenuItem_default as default };
globalThis.__vuiVersion__ = "4.0.0-beta.1"
//# sourceMappingURL=sidemenuItem.js.map