"use strict";

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

/**
 * WordPress dependencies
 */

function AddCustomGenericTemplateModalContent({
  onClose,
  createTemplate
}) {
  const [title, setTitle] = (0, _element.useState)('');
  const defaultTitle = (0, _i18n.__)('Custom Template');
  const [isBusy, setIsBusy] = (0, _element.useState)(false);
  async function onCreateTemplate(event) {
    event.preventDefault();
    if (isBusy) {
      return;
    }
    setIsBusy(true);
    try {
      await createTemplate({
        slug: 'wp-custom-template-' + (0, _changeCase.paramCase)(title || defaultTitle),
        title: title || defaultTitle
      }, false);
    } finally {
      setIsBusy(false);
    }
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("form", {
    onSubmit: onCreateTemplate,
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalVStack, {
      spacing: 6,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.TextControl, {
        __next40pxDefaultSize: true,
        __nextHasNoMarginBottom: true,
        label: (0, _i18n.__)('Name'),
        value: title,
        onChange: setTitle,
        placeholder: defaultTitle,
        disabled: isBusy,
        help: (0, _i18n.__)('Describe the template, e.g. "Post with sidebar". A custom template can be manually applied to any post or page.')
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
        className: "edit-site-custom-generic-template__modal-actions",
        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,
          variant: "primary",
          type: "submit",
          isBusy: isBusy,
          "aria-disabled": isBusy,
          children: (0, _i18n.__)('Create')
        })]
      })]
    })
  });
}
var _default = exports.default = AddCustomGenericTemplateModalContent;
//# sourceMappingURL=add-custom-generic-template-modal-content.js.map