const openPopovers: symbol[] = [];

export const registerOpenPopover = (id: symbol): void => {
    const currentIndex = openPopovers.indexOf(id);

    if (currentIndex >= 0) {
        openPopovers.splice(currentIndex, 1);
    }

    openPopovers.push(id);
};

export const unregisterOpenPopover = (id: symbol): void => {
    const currentIndex = openPopovers.indexOf(id);

    if (currentIndex >= 0) {
        openPopovers.splice(currentIndex, 1);
    }
};

export const isTopmostPopover = (id: symbol): boolean => openPopovers.at(-1) === id;
