import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { useState, useEffect } from 'react';

var QUERY = "(prefers-reduced-motion: no-preference)";
var isRenderingOnServer = typeof window === "undefined";
var getInitialState = function getInitialState() {
  return (
    // For our initial server render, we won't know if the user
    // prefers reduced motion, but it doesn't matter. This value
    // will be overwritten on the client, before any animations
    // occur.
    isRenderingOnServer ? true : !window.matchMedia(QUERY).matches
  );
};
var usePrefersReducedMotion = function usePrefersReducedMotion() {
  var _useState = useState(getInitialState),
    _useState2 = _slicedToArray(_useState, 2),
    prefersReducedMotion = _useState2[0],
    setPrefersReducedMotion = _useState2[1];
  useEffect(function () {
    if (isRenderingOnServer) return undefined;
    var mediaQueryList = window.matchMedia(QUERY);
    var listener = function listener(event) {
      setPrefersReducedMotion(!event.matches);
    };
    if (mediaQueryList.addEventListener) {
      mediaQueryList.addEventListener("change", listener);
    } else {
      mediaQueryList.addListener(listener);
    }
    return function () {
      if (mediaQueryList.removeEventListener) {
        mediaQueryList.removeEventListener("change", listener);
      } else {
        mediaQueryList.removeListener(listener);
      }
    };
  }, []);
  return prefersReducedMotion;
};

export { usePrefersReducedMotion as u };
//# sourceMappingURL=usePrefersReducedMotion-n4ZJtExQ.js.map
