"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _clsx = _interopRequireDefault(require("clsx"));
var _i18n = require("@wordpress/i18n");
var _blockEditor = require("@wordpress/block-editor");
var _components = require("@wordpress/components");
var _compose = require("@wordpress/compose");
var _coreData = require("@wordpress/core-data");
var _data = require("@wordpress/data");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * External dependencies
 */

/**
 * WordPress dependencies
 */

const CommentsFormPlaceholder = () => {
  const instanceId = (0, _compose.useInstanceId)(CommentsFormPlaceholder);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: "comment-respond",
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("h3", {
      className: "comment-reply-title",
      children: (0, _i18n.__)('Leave a Reply')
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("form", {
      noValidate: true,
      className: "comment-form",
      onSubmit: event => event.preventDefault(),
      children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("label", {
          htmlFor: `comment-${instanceId}`,
          children: (0, _i18n.__)('Comment')
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)("textarea", {
          id: `comment-${instanceId}`,
          name: "comment",
          cols: "45",
          rows: "8",
          readOnly: true
        })]
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
        className: "form-submit wp-block-button",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
          name: "submit",
          type: "submit",
          className: (0, _clsx.default)('wp-block-button__link', (0, _blockEditor.__experimentalGetElementClassName)('button')),
          label: (0, _i18n.__)('Post Comment'),
          value: (0, _i18n.__)('Post Comment'),
          "aria-disabled": "true"
        })
      })]
    })]
  });
};
const CommentsForm = ({
  postId,
  postType
}) => {
  const [commentStatus, setCommentStatus] = (0, _coreData.useEntityProp)('postType', postType, 'comment_status', postId);
  const isSiteEditor = postType === undefined || postId === undefined;
  const {
    defaultCommentStatus
  } = (0, _data.useSelect)(select => select(_blockEditor.store).getSettings().__experimentalDiscussionSettings);
  const postTypeSupportsComments = (0, _data.useSelect)(select => postType ? !!select(_coreData.store).getPostType(postType)?.supports.comments : false);
  if (!isSiteEditor && 'open' !== commentStatus) {
    if ('closed' === commentStatus) {
      const actions = [/*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
        __next40pxDefaultSize: true,
        onClick: () => setCommentStatus('open'),
        variant: "primary",
        children: (0, _i18n._x)('Enable comments', 'action that affects the current post')
      }, "enableComments")];
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.Warning, {
        actions: actions,
        children: (0, _i18n.__)('Post Comments Form block: Comments are not enabled for this item.')
      });
    } else if (!postTypeSupportsComments) {
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.Warning, {
        children: (0, _i18n.sprintf)( /* translators: 1: Post type (i.e. "post", "page") */
        (0, _i18n.__)('Post Comments Form block: Comments are not enabled for this post type (%s).'), postType)
      });
    } else if ('open' !== defaultCommentStatus) {
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockEditor.Warning, {
        children: (0, _i18n.__)('Post Comments Form block: Comments are not enabled.')
      });
    }
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(CommentsFormPlaceholder, {});
};
var _default = exports.default = CommentsForm;
//# sourceMappingURL=form.js.map