"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getCanUserCreateMedia = exports.__experimentalGetPreviewDeviceType = exports.__experimentalGetInsertionPoint = void 0;
exports.getCurrentTemplateNavigationPanelSubMenu = getCurrentTemplateNavigationPanelSubMenu;
exports.getCurrentTemplateTemplateParts = void 0;
exports.getEditedPostContext = getEditedPostContext;
exports.getEditedPostId = getEditedPostId;
exports.getEditedPostType = getEditedPostType;
exports.getEditorMode = void 0;
exports.getHomeTemplateId = getHomeTemplateId;
exports.getNavigationPanelActiveMenu = getNavigationPanelActiveMenu;
exports.getPage = getPage;
exports.getReusableBlocks = void 0;
exports.getSettings = getSettings;
exports.hasPageContentFocus = hasPageContentFocus;
exports.isListViewOpened = exports.isInserterOpened = exports.isFeatureActive = void 0;
exports.isNavigationOpened = isNavigationOpened;
exports.isPage = isPage;
exports.isSaveViewOpened = isSaveViewOpened;
var _coreData = require("@wordpress/core-data");
var _data = require("@wordpress/data");
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
var _element = require("@wordpress/element");
var _preferences = require("@wordpress/preferences");
var _editor = require("@wordpress/editor");
var _blockEditor = require("@wordpress/block-editor");
var _lockUnlock = require("../lock-unlock");
var _constants = require("../utils/constants");
var _getFilteredTemplateParts = _interopRequireDefault(require("../utils/get-filtered-template-parts"));
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

/**
 * @typedef {'template'|'template_type'} TemplateType Template type.
 */

/**
 * Returns whether the given feature is enabled or not.
 *
 * @deprecated
 * @param {Object} state       Global application state.
 * @param {string} featureName Feature slug.
 *
 * @return {boolean} Is active.
 */
const isFeatureActive = exports.isFeatureActive = (0, _data.createRegistrySelector)(select => (_, featureName) => {
  (0, _deprecated.default)(`select( 'core/edit-site' ).isFeatureActive`, {
    since: '6.0',
    alternative: `select( 'core/preferences' ).get`
  });
  return !!select(_preferences.store).get('core/edit-site', featureName);
});

/**
 * Returns the current editing canvas device type.
 *
 * @deprecated
 *
 * @param {Object} state Global application state.
 *
 * @return {string} Device type.
 */
const __experimentalGetPreviewDeviceType = exports.__experimentalGetPreviewDeviceType = (0, _data.createRegistrySelector)(select => () => {
  (0, _deprecated.default)(`select( 'core/edit-site' ).__experimentalGetPreviewDeviceType`, {
    since: '6.5',
    version: '6.7',
    alternative: `select( 'core/editor' ).getDeviceType`
  });
  return select(_editor.store).getDeviceType();
});

/**
 * Returns whether the current user can create media or not.
 *
 * @param {Object} state Global application state.
 *
 * @return {Object} Whether the current user can create media or not.
 */
const getCanUserCreateMedia = exports.getCanUserCreateMedia = (0, _data.createRegistrySelector)(select => () => {
  (0, _deprecated.default)(`wp.data.select( 'core/edit-site' ).getCanUserCreateMedia()`, {
    since: '6.7',
    alternative: `wp.data.select( 'core' ).canUser( 'create', { kind: 'root', type: 'media' } )`
  });
  return select(_coreData.store).canUser('create', 'media');
});

/**
 * Returns any available Reusable blocks.
 *
 * @param {Object} state Global application state.
 *
 * @return {Array} The available reusable blocks.
 */
const getReusableBlocks = exports.getReusableBlocks = (0, _data.createRegistrySelector)(select => () => {
  (0, _deprecated.default)(`select( 'core/edit-site' ).getReusableBlocks()`, {
    since: '6.5',
    version: '6.8',
    alternative: `select( 'core/core' ).getEntityRecords( 'postType', 'wp_block' )`
  });
  const isWeb = _element.Platform.OS === 'web';
  return isWeb ? select(_coreData.store).getEntityRecords('postType', 'wp_block', {
    per_page: -1
  }) : [];
});

/**
 * Returns the site editor settings.
 *
 * @param {Object} state Global application state.
 *
 * @return {Object} Settings.
 */
function getSettings(state) {
  // It is important that we don't inject anything into these settings locally.
  // The reason for this is that we have an effect in place that calls setSettings based on the previous value of getSettings.
  // If we add computed settings here, we'll be adding these computed settings to the state which is very unexpected.
  return state.settings;
}

/**
 * @deprecated
 */
function getHomeTemplateId() {
  (0, _deprecated.default)("select( 'core/edit-site' ).getHomeTemplateId", {
    since: '6.2',
    version: '6.4'
  });
}

/**
 * Returns the current edited post type (wp_template or wp_template_part).
 *
 * @deprecated
 * @param {Object} state Global application state.
 *
 * @return {?TemplateType} Template type.
 */
function getEditedPostType(state) {
  (0, _deprecated.default)("select( 'core/edit-site' ).getEditedPostType", {
    since: '6.8',
    alternative: "select( 'core/editor' ).getCurrentPostType"
  });
  return state.editedPost.postType;
}

/**
 * Returns the ID of the currently edited template or template part.
 *
 * @deprecated
 * @param {Object} state Global application state.
 *
 * @return {?string} Post ID.
 */
function getEditedPostId(state) {
  (0, _deprecated.default)("select( 'core/edit-site' ).getEditedPostId", {
    since: '6.8',
    alternative: "select( 'core/editor' ).getCurrentPostId"
  });
  return state.editedPost.id;
}

/**
 * Returns the edited post's context object.
 *
 * @deprecated
 * @param {Object} state Global application state.
 *
 * @return {Object} Page.
 */
function getEditedPostContext(state) {
  (0, _deprecated.default)("select( 'core/edit-site' ).getEditedPostContext", {
    since: '6.8'
  });
  return state.editedPost.context;
}

/**
 * Returns the current page object.
 *
 * @deprecated
 * @param {Object} state Global application state.
 *
 * @return {Object} Page.
 */
function getPage(state) {
  (0, _deprecated.default)("select( 'core/edit-site' ).getPage", {
    since: '6.8'
  });
  return {
    context: state.editedPost.context
  };
}

/**
 * Returns true if the inserter is opened.
 *
 * @deprecated
 *
 * @param {Object} state Global application state.
 *
 * @return {boolean} Whether the inserter is opened.
 */
const isInserterOpened = exports.isInserterOpened = (0, _data.createRegistrySelector)(select => () => {
  (0, _deprecated.default)(`select( 'core/edit-site' ).isInserterOpened`, {
    since: '6.5',
    alternative: `select( 'core/editor' ).isInserterOpened`
  });
  return select(_editor.store).isInserterOpened();
});

/**
 * Get the insertion point for the inserter.
 *
 * @deprecated
 *
 * @param {Object} state Global application state.
 *
 * @return {Object} The root client ID, index to insert at and starting filter value.
 */
const __experimentalGetInsertionPoint = exports.__experimentalGetInsertionPoint = (0, _data.createRegistrySelector)(select => () => {
  (0, _deprecated.default)(`select( 'core/edit-site' ).__experimentalGetInsertionPoint`, {
    since: '6.5',
    version: '6.7'
  });
  return (0, _lockUnlock.unlock)(select(_editor.store)).getInserter();
});

/**
 * Returns true if the list view is opened.
 *
 * @param {Object} state Global application state.
 *
 * @return {boolean} Whether the list view is opened.
 */
const isListViewOpened = exports.isListViewOpened = (0, _data.createRegistrySelector)(select => () => {
  (0, _deprecated.default)(`select( 'core/edit-site' ).isListViewOpened`, {
    since: '6.5',
    alternative: `select( 'core/editor' ).isListViewOpened`
  });
  return select(_editor.store).isListViewOpened();
});

/**
 * Returns the current opened/closed state of the save panel.
 *
 * @param {Object} state Global application state.
 *
 * @return {boolean} True if the save panel should be open; false if closed.
 */
function isSaveViewOpened(state) {
  return state.saveViewPanel;
}
function getBlocksAndTemplateParts(select) {
  const templateParts = select(_coreData.store).getEntityRecords('postType', _constants.TEMPLATE_PART_POST_TYPE, {
    per_page: -1
  });
  const {
    getBlocksByName,
    getBlocksByClientId
  } = select(_blockEditor.store);
  const clientIds = getBlocksByName('core/template-part');
  const blocks = getBlocksByClientId(clientIds);
  return [blocks, templateParts];
}

/**
 * Returns the template parts and their blocks for the current edited template.
 *
 * @deprecated
 * @param {Object} state Global application state.
 * @return {Array} Template parts and their blocks in an array.
 */
const getCurrentTemplateTemplateParts = exports.getCurrentTemplateTemplateParts = (0, _data.createRegistrySelector)(select => (0, _data.createSelector)(() => {
  (0, _deprecated.default)(`select( 'core/edit-site' ).getCurrentTemplateTemplateParts()`, {
    since: '6.7',
    version: '6.9',
    alternative: `select( 'core/block-editor' ).getBlocksByName( 'core/template-part' )`
  });
  return (0, _getFilteredTemplateParts.default)(...getBlocksAndTemplateParts(select));
}, () => getBlocksAndTemplateParts(select)));

/**
 * Returns the current editing mode.
 *
 * @param {Object} state Global application state.
 *
 * @return {string} Editing mode.
 */
const getEditorMode = exports.getEditorMode = (0, _data.createRegistrySelector)(select => () => {
  return select(_preferences.store).get('core', 'editorMode');
});

/**
 * @deprecated
 */
function getCurrentTemplateNavigationPanelSubMenu() {
  (0, _deprecated.default)("dispatch( 'core/edit-site' ).getCurrentTemplateNavigationPanelSubMenu", {
    since: '6.2',
    version: '6.4'
  });
}

/**
 * @deprecated
 */
function getNavigationPanelActiveMenu() {
  (0, _deprecated.default)("dispatch( 'core/edit-site' ).getNavigationPanelActiveMenu", {
    since: '6.2',
    version: '6.4'
  });
}

/**
 * @deprecated
 */
function isNavigationOpened() {
  (0, _deprecated.default)("dispatch( 'core/edit-site' ).isNavigationOpened", {
    since: '6.2',
    version: '6.4'
  });
}

/**
 * Whether or not the editor has a page loaded into it.
 *
 * @see setPage
 * @deprecated
 * @param {Object} state Global application state.
 *
 * @return {boolean} Whether or not the editor has a page loaded into it.
 */
function isPage(state) {
  (0, _deprecated.default)("select( 'core/edit-site' ).isPage", {
    since: '6.8',
    alternative: "select( 'core/editor' ).getCurrentPostType"
  });
  return !!state.editedPost.context?.postId;
}

/**
 * Whether or not the editor allows only page content to be edited.
 *
 * @deprecated
 *
 * @return {boolean} Whether or not focus is on editing page content.
 */
function hasPageContentFocus() {
  (0, _deprecated.default)(`select( 'core/edit-site' ).hasPageContentFocus`, {
    since: '6.5'
  });
  return false;
}
//# sourceMappingURL=selectors.js.map