"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sidemenu = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const box_1 = __importDefault(require("../box"));
const button_1 = __importDefault(require("../button"));
const core_1 = require("../core");
const icon_1 = __importDefault(require("../icon"));
const utils_1 = require("../utils");
const consts_1 = require("./consts");
const context_1 = require("./context");
const sidemenuItem_1 = __importDefault(require("./sidemenuItem"));
const sidemenuTop_1 = __importDefault(require("./sidemenuTop"));
/** A collapsible side menu for navigation. */
exports.Sidemenu = (0, core_1.vui)((props, ref) => {
    var _a;
    const { children, className, items, isExpanded = false, isSticky = false, size, variant, width = consts_1.expandedWidth, onNavigate } = props, rest = __rest(props, ["children", "className", "items", "isExpanded", "isSticky", "size", "variant", "width", "onNavigate"]);
    const [isExpandedHorizontally, setIsExpandedHorizontally] = (0, react_1.useState)(isExpanded);
    const context = (0, react_1.useMemo)(() => (0, utils_1.filterUndefined)({ size, variant, isExpandedHorizontally }), [size, variant, isExpandedHorizontally]);
    const styles = (0, core_1.useStyleConfig)('Sidemenu', props);
    const isDark = variant === 'dark';
    (0, react_1.useEffect)(() => {
        setIsExpandedHorizontally(isExpanded);
    }, [isExpanded]);
    const onToggle = () => setIsExpandedHorizontally(!isExpandedHorizontally);
    const w = isExpandedHorizontally ? width : consts_1.collapsedWidth;
    const icon = `falArrow${isExpandedHorizontally ? 'Left' : 'Right'}`;
    const justifyContent = isExpandedHorizontally ? 'flex-end' : 'center';
    function onItemClick(item) {
        var _a;
        (_a = item === null || item === void 0 ? void 0 : item.onClick) === null || _a === void 0 ? void 0 : _a.call(item);
        if (item === null || item === void 0 ? void 0 : item.path)
            onNavigate === null || onNavigate === void 0 ? void 0 : onNavigate(item.path);
    }
    return ((0, jsx_runtime_1.jsx)(context_1.SidemenuProvider, { value: context, children: (0, jsx_runtime_1.jsxs)(box_1.default, Object.assign({ className: (0, utils_1.cs)('vui-sidemenu', className), elevation: "3", flexDirection: "column", minWidth: 0, overflowX: "hidden", position: isSticky ? 'sticky' : 'static', ref: ref, top: isSticky ? (top ? top : 0) : 'auto', transitionDuration: "normal", w: w }, styles.container, rest, { children: [(0, jsx_runtime_1.jsx)(box_1.default, { flexDirection: "column", flexGrow: 1, justifyContent: "flex-start", minW: consts_1.expandedWidth, overflowX: "hidden", overflowY: "auto", w: "100%", children: items
                        ? (_a = items === null || items === void 0 ? void 0 : items.map) === null || _a === void 0 ? void 0 : _a.call(items, (item, key) => ((0, jsx_runtime_1.jsx)(sidemenuItem_1.default, Object.assign({ isActive: (0, utils_1.isActivePath)(item === null || item === void 0 ? void 0 : item.path) }, item, { onClick: () => onItemClick(item) }), key)))
                        : children }), (0, jsx_runtime_1.jsx)(box_1.default, Object.assign({ className: "vui-sidemenu-bottom", w: "100%" }, styles.bottom, { children: (0, jsx_runtime_1.jsx)(button_1.default, { "aria-label": isExpandedHorizontally ? 'Collapse' : 'Expand', borderRadius: 0, justifyContent: justifyContent, minH: size === 'lg' ? '56px' : '40px', onClick: onToggle, pl: 0, size: "md", variant: isDark ? 'tertiaryLight' : 'tertiaryDark', w: "100%", children: (0, jsx_runtime_1.jsx)(icon_1.default, { name: icon }) }) }))] })) }));
});
exports.Sidemenu.Top = sidemenuTop_1.default;
exports.Sidemenu.Item = sidemenuItem_1.default;
exports.Sidemenu.displayName = 'Sidemenu';
exports.default = exports.Sidemenu;
//# sourceMappingURL=sidemenu.js.map