window.registerViewportChangeCallback = function (dotNetObjectRef) {
    let isDisposed = false;

    const resizeHandler = () => {
        if (!isDisposed) {
            dotNetObjectRef.invokeMethodAsync('OnResize')
                .catch(error => {
                    console.error('Error invoking OnResize:', error);
                    if (error.message.includes('disposed')) {
                        isDisposed = true;
                    }
                });
        }
    };

    window.addEventListener('resize', resizeHandler);

    return {
        dispose: () => {
            isDisposed = true;
            window.removeEventListener('resize', resizeHandler);
        }
    };
};

window.getDimensions = function () {
    return {
        width: window.innerWidth,
        height: window.innerHeight
    };
};