'use strict';

var slicedToArray = require('../../slicedToArray-BcL7fKuL.js');
var React = require('react');
var reactUtils_usePrefersReducedMotion_constants = require('./constants.js');
require('../../unsupportedIterableToArray-BoHMiKNA.js');

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(reactUtils_usePrefersReducedMotion_constants.QUERY).matches
  );
};
var usePrefersReducedMotion = function usePrefersReducedMotion() {
  var _useState = React.useState(getInitialState),
    _useState2 = slicedToArray._slicedToArray(_useState, 2),
    prefersReducedMotion = _useState2[0],
    setPrefersReducedMotion = _useState2[1];
  React.useEffect(function () {
    if (isRenderingOnServer) return undefined;
    var mediaQueryList = window.matchMedia(reactUtils_usePrefersReducedMotion_constants.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;
};

module.exports = usePrefersReducedMotion;
//# sourceMappingURL=usePrefersReducedMotion.js.map
