import { setContext } from 'svelte';
export function getSidebarState({ setExpanded, }) {
    return () => {
        const sidebar = document.querySelector('m-sidebar');
        setExpanded(sidebar?.hasAttribute('expanded') ?? false);
        const updateExpanded = (e) => {
            setExpanded(e.detail);
        };
        document.addEventListener('update:expanded', updateExpanded);
        return () => document.removeEventListener('update:expanded', updateExpanded);
    };
}
export function getShortcutsState({ setState, }) {
    return () => {
        const shortcuts = document.querySelector('m-sortcuts');
        setState(shortcuts?.hasAttribute('stacked') ?? false);
        const updateState = (e) => {
            setState(e.detail);
        };
        document.addEventListener('update:stacked', updateState);
        return () => document.removeEventListener('update:stacked', updateState);
    };
}
export function setSubItems(tagName) {
    return () => {
        // Works only for Svelte components
        setContext('SUB_ITEM', true);
        // Works only for custom-elements
        const children = document.querySelectorAll('m-sidebar-nav-item');
        children.forEach((el) => {
            if (el.parentNode?.nodeName === tagName) {
                el.sub = true;
            }
        });
    };
}
