'use strict';

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var React = require('react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);

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 = React.useState(getInitialState),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    prefersReducedMotion = _useState2[0],
    setPrefersReducedMotion = _useState2[1];
  React.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;
};

exports.usePrefersReducedMotion = usePrefersReducedMotion;
//# sourceMappingURL=usePrefersReducedMotion-D2Ck84HM.js.map
