"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
const core_1 = require("../core");
const context_1 = require("./context");
const useSidemenuItem = (itemId) => {
    var _a, _b;
    const sidemenuContext = (0, context_1.useSidemenuContext)();
    const styles = (0, core_1.useStyleConfig)('SidemenuV2', sidemenuContext);
    const isSubmenuOpen = (0, react_1.useMemo)(() => {
        var _a, _b;
        return itemId ? ((_b = (_a = sidemenuContext === null || sidemenuContext === void 0 ? void 0 : sidemenuContext.submenuStates) === null || _a === void 0 ? void 0 : _a[itemId]) !== null && _b !== void 0 ? _b : false) : false;
    }, [itemId, sidemenuContext === null || sidemenuContext === void 0 ? void 0 : sidemenuContext.submenuStates]);
    const handleToggleSubmenu = (0, react_1.useCallback)(() => {
        if (itemId && (sidemenuContext === null || sidemenuContext === void 0 ? void 0 : sidemenuContext.toggleSubmenu)) {
            sidemenuContext.toggleSubmenu(itemId);
        }
    }, [itemId, sidemenuContext === null || sidemenuContext === void 0 ? void 0 : sidemenuContext.toggleSubmenu]);
    // Fallback values if context is missing
    const isDark = (sidemenuContext === null || sidemenuContext === void 0 ? void 0 : sidemenuContext.variant) === 'dark';
    const size = (_a = sidemenuContext === null || sidemenuContext === void 0 ? void 0 : sidemenuContext.size) !== null && _a !== void 0 ? _a : 'lg';
    const isMenuExpanded = (_b = sidemenuContext === null || sidemenuContext === void 0 ? void 0 : sidemenuContext.isMenuExpanded) !== null && _b !== void 0 ? _b : true;
    // Memoize the entire return object to prevent unnecessary re-renders
    return (0, react_1.useMemo)(() => ({
        isDark,
        size,
        styles,
        isMenuExpanded,
        isSubmenuOpen,
        toggleSubmenu: handleToggleSubmenu,
    }), [isDark, size, styles, isMenuExpanded, isSubmenuOpen, handleToggleSubmenu]);
};
exports.default = useSidemenuItem;
//# sourceMappingURL=useSidemenuItem.js.map