"use strict";
/**
 * useMediaQuery hook
 *
 * Custom hook to check if a media query matches
 * @param {string} query - The media query to check
 * @returns {boolean} Whether the media query matches
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMediaQuery = useMediaQuery;
const react_1 = require("react");
/**
 * Custom hook to check if a media query matches
 * @param {string} query - The media query to check
 * @returns {boolean} Whether the media query matches
 *
 * @example
 * const isDesktop = useMediaQuery('(min-width: 1024px)');
 * if (isDesktop) {
 *   // Run desktop-specific code
 * }
 */
function useMediaQuery(query) {
    // Initialize with the current match state
    const getMatches = (query) => {
        // Check if window is defined (for SSR)
        if (typeof window !== 'undefined') {
            return window.matchMedia(query).matches;
        }
        return false;
    };
    const [matches, setMatches] = (0, react_1.useState)(getMatches(query));
    // Update the state based on media query changes
    (0, react_1.useEffect)(() => {
        if (typeof window !== 'undefined') {
            const mediaQuery = window.matchMedia(query);
            const updateMatches = () => setMatches(mediaQuery.matches);
            // Add event listener for changes
            mediaQuery.addEventListener('change', updateMatches);
            // Set initial value
            updateMatches();
            // Clean up event listener
            return () => mediaQuery.removeEventListener('change', updateMatches);
        }
        return undefined;
    }, [query]);
    return matches;
}
exports.default = useMediaQuery;
//# sourceMappingURL=useMediaQuery.js.map