"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = RenameCategoryMenuItem;
var _components = require("@wordpress/components");
var _element = require("@wordpress/element");
var _i18n = require("@wordpress/i18n");
var _patterns = require("@wordpress/patterns");
var _usePatternCategories = _interopRequireDefault(require("../sidebar-navigation-screen-patterns/use-pattern-categories"));
var _lockUnlock = require("../../lock-unlock");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

/**
 * Internal dependencies
 */

const {
  RenamePatternCategoryModal
} = (0, _lockUnlock.unlock)(_patterns.privateApis);
function RenameCategoryMenuItem({
  category,
  onClose
}) {
  const [isModalOpen, setIsModalOpen] = (0, _element.useState)(false);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.MenuItem, {
      onClick: () => setIsModalOpen(true),
      children: (0, _i18n.__)('Rename')
    }), isModalOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(RenameModal, {
      category: category,
      onClose: () => {
        setIsModalOpen(false);
        onClose();
      }
    })]
  });
}
function RenameModal({
  category,
  onClose
}) {
  // User created pattern categories have their properties updated when
  // retrieved via `getUserPatternCategories`. The rename modal expects an
  // object that will match the pattern category entity.
  const normalizedCategory = {
    id: category.id,
    slug: category.slug,
    name: category.label
  };

  // Optimization - only use pattern categories when the modal is open.
  const existingCategories = (0, _usePatternCategories.default)();
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(RenamePatternCategoryModal, {
    category: normalizedCategory,
    existingCategories: existingCategories,
    onClose: onClose,
    overlayClassName: "edit-site-list__rename-modal",
    focusOnMount: "firstContentElement",
    size: "small"
  });
}
//# sourceMappingURL=rename-category-menu-item.js.map