"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getExamples = getExamples;
var _i18n = require("@wordpress/i18n");
var _blocks = require("@wordpress/blocks");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

/**
 * Returns a list of examples for registered block types.
 *
 * @return {BlockExample[]} An array of block examples.
 */
function getExamples() {
  const nonHeadingBlockExamples = (0, _blocks.getBlockTypes)().filter(blockType => {
    const {
      name,
      example,
      supports
    } = blockType;
    return name !== 'core/heading' && !!example && supports.inserter !== false;
  }).map(blockType => ({
    name: blockType.name,
    title: blockType.title,
    category: blockType.category,
    blocks: (0, _blocks.getBlockFromExample)(blockType.name, blockType.example)
  }));
  const isHeadingBlockRegistered = !!(0, _blocks.getBlockType)('core/heading');
  if (!isHeadingBlockRegistered) {
    return nonHeadingBlockExamples;
  }

  // Use our own example for the Heading block so that we can show multiple
  // heading levels.
  const headingsExample = {
    name: 'core/heading',
    title: (0, _i18n.__)('Headings'),
    category: 'text',
    blocks: [1, 2, 3, 4, 5, 6].map(level => {
      return (0, _blocks.createBlock)('core/heading', {
        content: (0, _i18n.sprintf)(
        // translators: %d: heading level e.g: "1", "2", "3"
        (0, _i18n.__)('Heading %d'), level),
        level
      });
    })
  };
  return [headingsExample, ...nonHeadingBlockExamples];
}
//# sourceMappingURL=examples.js.map