"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useWindowWidth = exports.WindowWidthProvider = exports.WindowWidthContext = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const throttle_1 = tslib_1.__importDefault(require("lodash/throttle.js"));
const constants_1 = require("../../../constants.js");
const DEFAULT_WIDTH = constants_1.BREAKPOINTS.xl;
const UPDATE_FREQUENCY_MS = 100;
exports.WindowWidthContext = React.createContext(DEFAULT_WIDTH);
const WindowWidthProvider = ({ children }) => {
    const [windowWidth, setWindowWidth] = React.useState(DEFAULT_WIDTH);
    React.useEffect(() => {
        const handleResize = (0, throttle_1.default)(() => {
            setWindowWidth(window.innerWidth);
        }, UPDATE_FREQUENCY_MS, { leading: true });
        handleResize();
        window.addEventListener('resize', handleResize, { passive: true });
        // eslint-disable-next-line consistent-return
        return () => window.removeEventListener('resize', handleResize);
    }, []);
    return ((0, jsx_runtime_1.jsx)(exports.WindowWidthContext.Provider, { value: windowWidth, children: children }));
};
exports.WindowWidthProvider = WindowWidthProvider;
const useWindowWidth = () => React.useContext(exports.WindowWidthContext);
exports.useWindowWidth = useWindowWidth;
//# sourceMappingURL=WindowWidthContext.js.map
