import { jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
import throttle from "lodash/throttle.js";
import { BREAKPOINTS } from "../../../constants.js";
const DEFAULT_WIDTH = BREAKPOINTS.xl;
const UPDATE_FREQUENCY_MS = 100;
export const WindowWidthContext = React.createContext(DEFAULT_WIDTH);
export const WindowWidthProvider = ({ children }) => {
    const [windowWidth, setWindowWidth] = React.useState(DEFAULT_WIDTH);
    React.useEffect(() => {
        const handleResize = throttle(() => {
            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 (_jsx(WindowWidthContext.Provider, { value: windowWidth, children: children }));
};
export const useWindowWidth = () => React.useContext(WindowWidthContext);
//# sourceMappingURL=WindowWidthContext.js.map
