function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import React from 'react';

/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */

/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */

/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */

// TODO this is kind of hacky and just to satisfy gatsby. There are other usages of
// window in the library which don't trigger this error, so we should probably figure
// out what's going on here
function getWindow() {
  if (typeof window !== 'undefined') {
    return window;
  }
}

/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */
export function useLayoutEventListener(_ref) {
  var _ref$dependencies = _ref.dependencies,
    dependencies = _ref$dependencies === void 0 ? [] : _ref$dependencies,
    event = _ref.event,
    handler = _ref.handler,
    _ref$options = _ref.options,
    options = _ref$options === void 0 ? {} : _ref$options,
    scope = _ref.scope,
    _ref$noopHandler = _ref.noopHandler,
    noopHandler = _ref$noopHandler === void 0 ? false : _ref$noopHandler;
  if (!event) {
    console.warn("\"event\" option missing, no listeners added");
  } else if (!handler) {
    console.warn("\"handler\" option missing, no listeners added");
  }
  var actualScope = scope === getWindow() || !scope ? {
    current: getWindow()
  } : scope || {};
  var listener = useEventCallback({
    handler: handler,
    dependencies: dependencies
  });
  React.useLayoutEffect(function () {
    if (noopHandler) {
      return;
    }
    var current = actualScope.current;
    if (current) {
      current.addEventListener(event, listener, options);
      return function () {
        return current.removeEventListener(event, listener, options);
      };
    }
  }, [noopHandler, event, listener, actualScope.current]);
}

/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */
export function useEventListener(_ref2) {
  var _ref2$dependencies = _ref2.dependencies,
    dependencies = _ref2$dependencies === void 0 ? [] : _ref2$dependencies,
    event = _ref2.event,
    handler = _ref2.handler,
    _ref2$options = _ref2.options,
    options = _ref2$options === void 0 ? {} : _ref2$options,
    scope = _ref2.scope,
    _ref2$noopHandler = _ref2.noopHandler,
    noopHandler = _ref2$noopHandler === void 0 ? false : _ref2$noopHandler;
  if (!event) {
    console.warn("\"event\" option missing, no listeners added");
  } else if (!handler) {
    console.warn("\"handler\" option missing, no listeners added");
  }
  var actualScope;
  if (scope && !('current' in scope) && !Array.isArray(scope)) {
    actualScope = {
      current: scope
    };
  } else if (!scope) {
    actualScope = {
      current: getWindow()
    };
  } else {
    actualScope = scope || {};
  }
  var listener = useEventCallback({
    handler: handler,
    dependencies: dependencies
  });
  React.useEffect(function () {
    if (noopHandler) {
      return;
    }
    var _actualScope = actualScope,
      current = _actualScope.current;
    if (current) {
      current.addEventListener(event, listener, options);
      return function () {
        return current.removeEventListener(event, listener, options);
      };
    }
  }, [noopHandler, event, listener, actualScope.current]);
}

/**
 * @deprecatedSince 9
 * @deprecated Never officially documented/supported
 */
export function useEventCallback(_ref3) {
  var handler = _ref3.handler,
    _ref3$dependencies = _ref3.dependencies,
    dependencies = _ref3$dependencies === void 0 ? [] : _ref3$dependencies;
  var ref = React.useRef(handler);
  React.useLayoutEffect(function () {
    ref.current = handler;
  }, [handler].concat(_toConsumableArray(dependencies)));
  return React.useCallback(function (event) {
    return ref.current(event);
  }, []);
}
//# sourceMappingURL=EventListener.js.map