"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _keyboardShortcuts = require("@wordpress/keyboard-shortcuts");
var _data = require("@wordpress/data");
var _coreData = require("@wordpress/core-data");
var _editor = require("@wordpress/editor");
var _store = require("../../store");
var _lockUnlock = require("../../lock-unlock");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function KeyboardShortcutsGlobal() {
  const {
    __experimentalGetDirtyEntityRecords,
    isSavingEntityRecord
  } = (0, _data.useSelect)(_coreData.store);
  const {
    hasNonPostEntityChanges
  } = (0, _data.useSelect)(_editor.store);
  const {
    getCanvasMode
  } = (0, _lockUnlock.unlock)((0, _data.useSelect)(_store.store));
  const {
    setIsSaveViewOpened
  } = (0, _data.useDispatch)(_store.store);
  (0, _keyboardShortcuts.useShortcut)('core/edit-site/save', event => {
    event.preventDefault();
    const dirtyEntityRecords = __experimentalGetDirtyEntityRecords();
    const hasDirtyEntities = !!dirtyEntityRecords.length;
    const isSaving = dirtyEntityRecords.some(record => isSavingEntityRecord(record.kind, record.name, record.key));
    const _hasNonPostEntityChanges = hasNonPostEntityChanges();
    const isViewMode = getCanvasMode() === 'view';
    if ((!hasDirtyEntities || !_hasNonPostEntityChanges || isSaving) && !isViewMode) {
      return;
    }
    // At this point, we know that there are dirty entities, other than
    // the edited post, and we're not in the process of saving, so open
    // save view.
    setIsSaveViewOpened(true);
  });
  return null;
}
var _default = exports.default = KeyboardShortcutsGlobal;
//# sourceMappingURL=global.js.map