// packages/block-library/src/template-part/edit/title-modal.js
import { useState } from "@wordpress/element";
import { __, sprintf } from "@wordpress/i18n";
import {
  TextControl,
  Button,
  Modal,
  __experimentalHStack as HStack,
  __experimentalVStack as VStack
} from "@wordpress/components";
import { jsx, jsxs } from "react/jsx-runtime";
function TitleModal({ areaLabel, onClose, onSubmit }) {
  const [title, setTitle] = useState("");
  const submitForCreation = (event) => {
    event.preventDefault();
    onSubmit(title);
  };
  return /* @__PURE__ */ jsx(
    Modal,
    {
      title: sprintf(
        // Translators: %s as template part area title ("Header", "Footer", etc.).
        __("Create new %s"),
        areaLabel.toLowerCase()
      ),
      onRequestClose: onClose,
      focusOnMount: "firstContentElement",
      size: "small",
      children: /* @__PURE__ */ jsx("form", { onSubmit: submitForCreation, children: /* @__PURE__ */ jsxs(VStack, { spacing: "5", children: [
        /* @__PURE__ */ jsx(
          TextControl,
          {
            label: __("Name"),
            value: title,
            onChange: setTitle,
            placeholder: __("Custom Template Part")
          }
        ),
        /* @__PURE__ */ jsxs(HStack, { justify: "right", children: [
          /* @__PURE__ */ jsx(
            Button,
            {
              __next40pxDefaultSize: true,
              variant: "tertiary",
              onClick: () => {
                onClose();
                setTitle("");
              },
              children: __("Cancel")
            }
          ),
          /* @__PURE__ */ jsx(
            Button,
            {
              variant: "primary",
              type: "submit",
              accessibleWhenDisabled: true,
              disabled: !title.length,
              __next40pxDefaultSize: true,
              children: __("Create")
            }
          )
        ] })
      ] }) })
    }
  );
}
export {
  TitleModal as default
};
//# sourceMappingURL=title-modal.mjs.map
