function scrollTableToTop(containerId) {
    const container = document.getElementById(containerId);
    if (container && container.firstElementChild) {
        container.firstElementChild.scrollTop = 0;
    }
}

function scrollTableToBottom(containerId) {
    const container = document.getElementById(containerId);
    if (container && container.firstElementChild) {
        container.firstElementChild.scrollTop = container.firstElementChild.scrollHeight;
    }
}

function debounce(func, timeout = 200) {
    let timer;
    return (...args) => {
        clearTimeout(timer);
        timer = setTimeout(() => func.apply(this, args), timeout);
    };
}

window.animationHandler = {
    setupAnimationEndHandler: function (element, dotNetObject, animationId) {
        if (!element || !dotNetObject) return;
        
        this.removeAnimationEndHandler(element);
        
        const handler = function (event) {
            if (event.target === element) {
                dotNetObject.invokeMethodAsync('OnAnimationEndFromJS', animationId);
            }
        };
        
        element._animationEndHandler = handler;
        element.addEventListener('animationend', handler);
    },
    
    removeAnimationEndHandler: function (element) {
        if (!element) return;
        
        if (element._animationEndHandler) {
            element.removeEventListener('animationend', element._animationEndHandler);
            delete element._animationEndHandler;
        }
    }
};
