"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = PatternsHeader;
var _components = require("@wordpress/components");
var _coreData = require("@wordpress/core-data");
var _data = require("@wordpress/data");
var _i18n = require("@wordpress/i18n");
var _icons = require("@wordpress/icons");
var _addNewPattern = _interopRequireDefault(require("../add-new-pattern"));
var _renameCategoryMenuItem = _interopRequireDefault(require("./rename-category-menu-item"));
var _deleteCategoryMenuItem = _interopRequireDefault(require("./delete-category-menu-item"));
var _usePatternCategories = _interopRequireDefault(require("../sidebar-navigation-screen-patterns/use-pattern-categories"));
var _constants = require("../../utils/constants");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

function PatternsHeader({
  categoryId,
  type,
  titleId,
  descriptionId
}) {
  const {
    patternCategories
  } = (0, _usePatternCategories.default)();
  const templatePartAreas = (0, _data.useSelect)(select => select(_coreData.store).getCurrentTheme()?.default_template_part_areas || [], []);
  let title, description, patternCategory;
  if (type === _constants.TEMPLATE_PART_POST_TYPE) {
    const templatePartArea = templatePartAreas.find(area => area.area === categoryId);
    title = templatePartArea?.label || (0, _i18n.__)('All Template Parts');
    description = templatePartArea?.description || (0, _i18n.__)('Includes every template part defined for any area.');
  } else if (type === _constants.PATTERN_TYPES.user && !!categoryId) {
    patternCategory = patternCategories.find(category => category.name === categoryId);
    title = patternCategory?.label;
    description = patternCategory?.description;
  }
  if (!title) {
    return null;
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
    className: "edit-site-patterns__section-header",
    spacing: 1,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
      justify: "space-between",
      className: "edit-site-patterns__title",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalHeading, {
        as: "h2",
        level: 3,
        id: titleId,
        weight: 500,
        truncate: true,
        children: title
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
        expanded: false,
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_addNewPattern.default, {}), !!patternCategory?.id && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.DropdownMenu, {
          icon: _icons.moreVertical,
          label: (0, _i18n.__)('Actions'),
          toggleProps: {
            className: 'edit-site-patterns__button',
            description: (0, _i18n.sprintf)(/* translators: %s: pattern category name */
            (0, _i18n.__)('Action menu for %s pattern category'), title),
            size: 'compact'
          },
          children: ({
            onClose
          }) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.MenuGroup, {
            children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_renameCategoryMenuItem.default, {
              category: patternCategory,
              onClose: onClose
            }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_deleteCategoryMenuItem.default, {
              category: patternCategory,
              onClose: onClose
            })]
          })
        })]
      })]
    }), description ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalText, {
      variant: "muted",
      as: "p",
      id: descriptionId,
      className: "edit-site-patterns__sub-title",
      children: description
    }) : null]
  });
}
//# sourceMappingURL=header.js.map