import { useMemo } from 'react';
import warning from 'warning';
import { useGlobal } from '../renderEnvironment/index.js';
var scrollbarWidth = null;
export function getScrollWidth(globalObject) {
    if (!globalObject.document) {
        return 0;
    }
    var body = globalObject.document.body;
    if (!body) {
        warning(false, 'There is no "body" element in "document"');
        return 0;
    }
    if (scrollbarWidth !== null) {
        return scrollbarWidth;
    }
    var div = globalObject.document.createElement('div');
    div.innerHTML = 'a'; // In IE clientWidth is 0 if this div is empty.
    div.style.overflowY = 'scroll';
    body.appendChild(div);
    // At least in jest it's NaN.
    scrollbarWidth = div.offsetWidth - div.clientWidth || 0;
    body.removeChild(div);
    return scrollbarWidth;
}
export function useGetScrollWidth() {
    var globalObject = useGlobal();
    return useMemo(function () { return getScrollWidth(globalObject); }, [globalObject]);
}
//# sourceMappingURL=getScrollWidth.js.map