import { getLibraryTable } from "./neo-library--globals.js";



let lastHoveredRow = null;
function setBelowLastHoveredOnRowNode(row) {
    row.addEventListener('mouseenter', () => {
        if (row.isEqualNode(lastHoveredRow)) { return; }
        lastHoveredRow = row;
        document.querySelectorAll('.neo-library--row.neo-library--row-is-below-last-hovered').forEach(row => row.classList.remove('neo-library--row-is-below-last-hovered'));

        let rowBelow = row;
        for (let i = 0; i < 3; i++) {
            rowBelow = rowBelow.nextElementSibling;
            if (!rowBelow) { break; }
            rowBelow.classList.add('neo-library--row-is-below-last-hovered');
        }
    });
}

const rowsObserver = new MutationObserver((mutations) => {
    for (const mutation of mutations) {
        for (const node of mutation.addedNodes) {
            if (node.classList?.contains("neo-library--row")) { setBelowLastHoveredOnRowNode(node); }
        }
    }
});
rowsObserver.observe(getLibraryTable(), { childList: true });
for (const row of getLibraryTable().getElementsByClassName("neo-library--row")) { setBelowLastHoveredOnRowNode(row); }


export function animateRowShine(row) {
    row.classList.add("neo-library--animate-new");
    setTimeout(() => row.classList.remove("neo-library--animate-new"), 3000);
}
