"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMedia = exports.noMatchMedia = void 0;
const react_1 = require("react");
exports.noMatchMedia = typeof window !== "undefined" && window.matchMedia === undefined;
/**
 * @example useMedia("screen and (min-width: 1024px)")
 * @param media string
 * @param fallback boolean
 * @returns boolean | undefined
 */
const useMedia = (media, fallback) => {
    const [matches, setMatches] = (0, react_1.useState)(fallback);
    (0, react_1.useEffect)(() => {
        if (exports.noMatchMedia) {
            return;
        }
        const mediaQueryList = window.matchMedia(media);
        setMatches(mediaQueryList.matches); // eslint-disable-line react-hooks/set-state-in-effect
        const listener = (evt) => {
            setMatches(evt.matches);
        };
        mediaQueryList.addEventListener("change", listener);
        return () => {
            mediaQueryList.removeEventListener("change", listener);
        };
    }, [media]);
    return matches;
};
exports.useMedia = useMedia;
//# sourceMappingURL=useMedia.js.map