import { useMemo, useCallback } from 'react';
import { useStyleConfig } from '../core';
import { useSidemenuContext } from './context';
const useSidemenuItem = (itemId) => {
    const sidemenuContext = useSidemenuContext();
    const styles = useStyleConfig('SidemenuV2', sidemenuContext);
    const isSubmenuOpen = useMemo(() => {
        return itemId ? (sidemenuContext?.submenuStates?.[itemId] ?? false) : false;
    }, [itemId, sidemenuContext?.submenuStates]);
    const handleToggleSubmenu = useCallback(() => {
        if (itemId && sidemenuContext?.toggleSubmenu) {
            sidemenuContext.toggleSubmenu(itemId);
        }
    }, [itemId, sidemenuContext?.toggleSubmenu]);
    // Fallback values if context is missing
    const isDark = sidemenuContext?.variant === 'dark';
    const size = sidemenuContext?.size ?? 'lg';
    const isMenuExpanded = sidemenuContext?.isMenuExpanded ?? true;
    // Memoize the entire return object to prevent unnecessary re-renders
    return useMemo(() => ({
        isDark,
        size,
        styles,
        isMenuExpanded,
        isSubmenuOpen,
        toggleSubmenu: handleToggleSubmenu,
    }), [isDark, size, styles, isMenuExpanded, isSubmenuOpen, handleToggleSubmenu]);
};
export default useSidemenuItem;
//# sourceMappingURL=useSidemenuItem.js.map