"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = StartPageOptions;
var _element = require("@wordpress/element");
var _data = require("@wordpress/data");
var _preferences = require("@wordpress/preferences");
var _interface = require("@wordpress/interface");
var _store = require("../../store");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function StartPageOptions() {
  const {
    postId,
    enabled
  } = (0, _data.useSelect)(select => {
    const {
      getCurrentPostId,
      getCurrentPostType
    } = select(_store.store);
    const preferencesModalActive = select(_interface.store).isModalActive('editor/preferences');
    const choosePatternModalEnabled = select(_preferences.store).get('core', 'enableChoosePatternModal');
    return {
      postId: getCurrentPostId(),
      enabled: choosePatternModalEnabled && !preferencesModalActive && 'page' === getCurrentPostType()
    };
  }, []);
  const {
    isEditedPostDirty,
    isEditedPostEmpty
  } = (0, _data.useSelect)(_store.store);
  const {
    setIsInserterOpened
  } = (0, _data.useDispatch)(_store.store);
  (0, _element.useEffect)(() => {
    if (!enabled) {
      return;
    }
    const isFreshPage = !isEditedPostDirty() && isEditedPostEmpty();
    if (isFreshPage) {
      setIsInserterOpened({
        tab: 'patterns',
        category: 'core/starter-content'
      });
    }

    // Note: The `postId` ensures the effect re-runs when pages are switched without remounting the component.
    // Examples: changing pages in the List View, creating a new page via Command Palette.
  }, [postId, enabled, setIsInserterOpened, isEditedPostDirty, isEditedPostEmpty]);
  return null;
}
//# sourceMappingURL=index.js.map