"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _keycodes = require("@wordpress/keycodes");
var _store = require("../../../store");
/**
 * WordPress dependencies
 */
/**
 * Internal dependencies
 */
var _default = props => element => {
  function onKeyDown(event) {
    const {
      keyCode
    } = event;
    if (event.defaultPrevented) {
      return;
    }
    if (keyCode !== _keycodes.BACKSPACE && keyCode !== _keycodes.ESCAPE) {
      return;
    }
    const {
      registry
    } = props.current;
    const {
      didAutomaticChange,
      getSettings
    } = registry.select(_store.store);
    const {
      __experimentalUndo
    } = getSettings();
    if (!__experimentalUndo) {
      return;
    }
    if (!didAutomaticChange()) {
      return;
    }
    event.preventDefault();
    __experimentalUndo();
  }
  element.addEventListener('keydown', onKeyDown);
  return () => {
    element.removeEventListener('keydown', onKeyDown);
  };
};
exports.default = _default;
//# sourceMappingURL=undo-automatic-change.js.map