import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import { useState, useEffect } from 'react';
export var MEDIA_QUERY = '(prefers-reduced-motion: reduce)';
export default function useReducedMotion() {
  var supportsMatchMedia = typeof window !== 'undefined' && 'matchMedia' in window;

  var _useState = useState(function () {
    return supportsMatchMedia ? window.matchMedia(MEDIA_QUERY).matches : false;
  }),
      _useState2 = _slicedToArray(_useState, 2),
      matches = _useState2[0],
      setMatch = _useState2[1];

  useEffect(function () {
    if (!supportsMatchMedia) return;
    var mediaQuery = window.matchMedia(MEDIA_QUERY);

    var listener = function listener(mqlEvent) {
      setMatch(mqlEvent.matches);
    };

    if (typeof mediaQuery.addEventListener === 'function') {
      mediaQuery.addEventListener('change', listener);
    } else {
      mediaQuery.addListener(listener);
    }

    return function () {
      if (typeof mediaQuery.removeEventListener === 'function') {
        mediaQuery.removeEventListener('change', listener);
      } else {
        mediaQuery.removeListener(listener);
      }
    };
  }, [supportsMatchMedia]);
  return matches;
}