"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = RenameModal;
var _components = require("@wordpress/components");
var _i18n = require("@wordpress/i18n");
var _element = require("@wordpress/element");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

const notEmptyString = testString => testString?.trim()?.length > 0;
function RenameModal({
  menuTitle,
  onClose,
  onSave
}) {
  const [editedMenuTitle, setEditedMenuTitle] = (0, _element.useState)(menuTitle);
  const titleHasChanged = editedMenuTitle !== menuTitle;
  const isEditedMenuTitleValid = titleHasChanged && notEmptyString(editedMenuTitle);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Modal, {
    title: (0, _i18n.__)('Rename'),
    onRequestClose: onClose,
    focusOnMount: "firstContentElement",
    size: "small",
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
      className: "sidebar-navigation__rename-modal-form",
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
        spacing: "3",
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
          __nextHasNoMarginBottom: true,
          __next40pxDefaultSize: true,
          value: editedMenuTitle,
          placeholder: (0, _i18n.__)('Navigation title'),
          onChange: setEditedMenuTitle,
          label: (0, _i18n.__)('Name')
        }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
          justify: "right",
          children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
            __next40pxDefaultSize: true,
            variant: "tertiary",
            onClick: onClose,
            children: (0, _i18n.__)('Cancel')
          }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
            __next40pxDefaultSize: true,
            accessibleWhenDisabled: true,
            disabled: !isEditedMenuTitleValid,
            variant: "primary",
            type: "submit",
            onClick: e => {
              e.preventDefault();
              if (!isEditedMenuTitleValid) {
                return;
              }
              onSave({
                title: editedMenuTitle
              });

              // Immediate close avoids ability to hit save multiple times.
              onClose();
            },
            children: (0, _i18n.__)('Save')
          })]
        })]
      })
    })
  });
}
//# sourceMappingURL=rename-modal.js.map