import { filterUndefined } from "../utils/object.js";
import { cs } from "../utils/styles.js";
import { isActivePath } from "../utils/window.js";
import "../utils/index.js";
import { useStyleConfig } 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 button_default from "../button/button.js";
import "../button/index.js";
import "../core/index.js";
import { collapsedWidth, expandedWidth } from "./consts.js";
import { SidemenuProvider } from "./context.js";
import sidemenuItem_default from "./sidemenuItem.js";
import sidemenuTop_default from "./sidemenuTop.js";
import { useEffect, useMemo, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";

//#region src/sidemenu/sidemenu.tsx
/** A collapsible side menu for navigation. */
const Sidemenu = vui((props, ref) => {
	const { children, className, items, isExpanded = false, isSticky = false, size, variant, width = expandedWidth, onNavigate, ...rest } = props;
	const [isExpandedHorizontally, setIsExpandedHorizontally] = useState(isExpanded);
	const context = useMemo(() => filterUndefined({
		size,
		variant,
		isExpandedHorizontally
	}), [
		size,
		variant,
		isExpandedHorizontally
	]);
	const styles = useStyleConfig("Sidemenu", props);
	const isDark = variant === "dark";
	useEffect(() => {
		setIsExpandedHorizontally(isExpanded);
	}, [isExpanded]);
	const onToggle = () => setIsExpandedHorizontally(!isExpandedHorizontally);
	const w = isExpandedHorizontally ? width : collapsedWidth;
	const icon = `falArrow${isExpandedHorizontally ? "Left" : "Right"}`;
	const justifyContent = isExpandedHorizontally ? "flex-end" : "center";
	function onItemClick(item) {
		item?.onClick?.();
		if (item?.path) onNavigate?.(item.path);
	}
	return /* @__PURE__ */ jsx(SidemenuProvider, {
		value: context,
		children: /* @__PURE__ */ jsxs(box_default, {
			className: cs("vui-sidemenu", className),
			elevation: "3",
			flexDirection: "column",
			minWidth: 0,
			overflowX: "hidden",
			position: isSticky ? "sticky" : "static",
			ref,
			top: isSticky ? top ? top : 0 : "auto",
			transitionDuration: "normal",
			w,
			...styles.container,
			...rest,
			children: [/* @__PURE__ */ jsx(box_default, {
				flexDirection: "column",
				flexGrow: 1,
				justifyContent: "flex-start",
				minW: expandedWidth,
				overflowX: "hidden",
				overflowY: "auto",
				w: "100%",
				children: items ? items?.map?.((item, key) => /* @__PURE__ */ jsx(sidemenuItem_default, {
					isActive: isActivePath(item?.path),
					...item,
					onClick: () => onItemClick(item)
				}, key)) : children
			}), /* @__PURE__ */ jsx(box_default, {
				className: "vui-sidemenu-bottom",
				w: "100%",
				...styles.bottom,
				children: /* @__PURE__ */ jsx(button_default, {
					"aria-label": isExpandedHorizontally ? "Collapse" : "Expand",
					borderRadius: 0,
					justifyContent,
					minH: size === "lg" ? "56px" : "40px",
					onClick: onToggle,
					pl: 0,
					size: "md",
					variant: isDark ? "tertiaryLight" : "tertiaryDark",
					w: "100%",
					children: /* @__PURE__ */ jsx(icon_default, { name: icon })
				})
			})]
		})
	});
});
Sidemenu.Top = sidemenuTop_default;
Sidemenu.Item = sidemenuItem_default;
Sidemenu.displayName = "Sidemenu";

//#endregion
export { Sidemenu };
globalThis.__vuiVersion__ = "4.0.0-beta.1"
//# sourceMappingURL=sidemenu.js.map