/**
 * useMediaQuery - CSS 미디어 쿼리 상태 감지 훅
 *
 * 사용처:
 * - cow/[cowNo]/page.tsx: 반응형 레이아웃 처리
 * - category-evaluation-card.tsx: 반응형 UI 처리
 */

import * as React from "react"

export function useMediaQuery(query: string) {
  const [matches, setMatches] = React.useState<boolean>(false)

  React.useEffect(() => {
    const mql = window.matchMedia(query)
    const onChange = () => {
      setMatches(mql.matches)
    }
    mql.addEventListener("change", onChange)
    setMatches(mql.matches)
    return () => mql.removeEventListener("change", onChange)
  }, [query])

  return matches
}
