"use strict";

exports.__esModule = true;
exports.default = void 0;
var _identity2 = _interopRequireDefault(require("lodash/fp/identity"));
var _get2 = _interopRequireDefault(require("lodash/fp/get"));
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _proptypes = require("../../../util/proptypes");
var _provider = _interopRequireDefault(require("../../../atom/provider"));
var _picture = _interopRequireDefault(require("../../../atom/picture"));
var _forumComment = _interopRequireDefault(require("../forum-comment"));
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const ForumPost = (props, context) => {
  const {
    translate,
    skin
  } = context;
  const {
    id,
    author,
    avatar,
    avatarAlt,
    profileAvatarAlt,
    date,
    message,
    answer,
    answerPostDisabled = false,
    answerTextareaDisabled = false,
    answerAvatar,
    answerable = true,
    editable = false,
    rejectable = false,
    mainPost = false,
    rejected = false,
    deleted = false,
    edition,
    editionPostDisabled = false,
    editionTextareaDisabled = false,
    showAnswerBox = false,
    showEditBox = false,
    onAnswer = _identity2.default,
    onEdit = _identity2.default,
    onPostAnswer = _identity2.default,
    onPostEdition = _identity2.default,
    onChangeAnswer = _identity2.default,
    onChangeEdition = _identity2.default,
    onModerate,
    onDelete
  } = props;
  const color = (0, _get2.default)('common.primary', skin);
  const infoDeleted = translate('This message has been removed by its author');
  const answerLabel = translate('Answer');
  const editLabel = translate('Edit');
  const deleteLabel = translate('Delete');
  const rejectLabel = translate('Reject');
  const putBackLabel = translate('Put back');
  let messageClassName = _style.default.message;
  if (deleted) {
    messageClassName = _style.default.deletedMessage;
  } else if (showEditBox) {
    messageClassName = _style.default.hiddenMessage;
  }
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "forumPost",
    id: `forum-post-${id || 'to-be-posted'}`,
    className: (0, _classnames.default)(mainPost ? _style.default.mainPost : null, rejected ? _style.default.rejected : _style.default.post)
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.avatarWrapper
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.image
  }, /*#__PURE__*/_react.default.createElement(_picture.default, {
    src: avatar,
    className: _style.default.avatar,
    alt: avatarAlt
  })), /*#__PURE__*/_react.default.createElement("span", {
    "data-name": "author",
    className: _style.default.author
  }, author)), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.content
  }, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("span", {
    className: _style.default.date
  }, date)), /*#__PURE__*/_react.default.createElement("div", {
    className: _style.default.body
  }, /*#__PURE__*/_react.default.createElement("span", {
    className: _style.default.action,
    onClick: onAnswer,
    style: {
      color,
      display: answerable && !deleted && !rejected ? 'block' : 'none'
    }
  }, answerLabel), /*#__PURE__*/_react.default.createElement("span", {
    className: _style.default.action,
    onClick: onEdit,
    style: {
      color,
      display: editable ? 'block' : 'none'
    }
  }, editLabel), /*#__PURE__*/_react.default.createElement("span", {
    className: _style.default.action,
    onClick: onDelete,
    style: {
      color,
      display: editable ? 'block' : 'none'
    }
  }, deleteLabel), /*#__PURE__*/_react.default.createElement("span", {
    className: _style.default.action,
    onClick: onModerate,
    style: {
      color,
      display: rejectable ? 'block' : 'none'
    }
  }, rejected ? putBackLabel : rejectLabel), deleted ? /*#__PURE__*/_react.default.createElement("div", {
    className: messageClassName,
    role: "status"
  }, infoDeleted) : /*#__PURE__*/_react.default.createElement("div", {
    className: messageClassName
  }, message), /*#__PURE__*/_react.default.createElement("div", {
    className: `${_style.default.edition} ${showEditBox ? _style.default.visible : ''}`
  }, /*#__PURE__*/_react.default.createElement(_forumComment.default, {
    avatar: null,
    profileAvatarAlt: profileAvatarAlt,
    value: edition,
    textareaDisabled: editionTextareaDisabled,
    postDisabled: editionPostDisabled,
    onPost: onPostEdition,
    onChange: onChangeEdition
  })), /*#__PURE__*/_react.default.createElement("div", {
    className: `${_style.default.answer} ${showAnswerBox ? _style.default.visible : ''}`
  }, /*#__PURE__*/_react.default.createElement(_forumComment.default, {
    avatar: answerAvatar,
    profileAvatarAlt: profileAvatarAlt,
    textareaDisabled: answerTextareaDisabled,
    postDisabled: answerPostDisabled,
    value: answer,
    onPost: onPostAnswer,
    onChange: onChangeAnswer
  })))));
};
ForumPost.contextTypes = {
  translate: _provider.default.childContextTypes.translate,
  skin: _provider.default.childContextTypes.skin
};
ForumPost.propTypes = process.env.NODE_ENV !== "production" ? {
  id: _propTypes.default.string,
  author: _propTypes.default.string,
  avatarAlt: _propTypes.default.string,
  profileAvatarAlt: _propTypes.default.string,
  date: _propTypes.default.string,
  message: _propTypes.default.string,
  avatar: _proptypes.SrcPropType,
  answerAvatar: _proptypes.SrcPropType,
  answer: _propTypes.default.string,
  edition: _propTypes.default.string,
  showAnswerBox: _propTypes.default.bool,
  showEditBox: _propTypes.default.bool,
  mainPost: _propTypes.default.bool,
  onAnswer: _propTypes.default.func,
  onEdit: _propTypes.default.func,
  onPostAnswer: _propTypes.default.func,
  onPostEdition: _propTypes.default.func,
  onChangeAnswer: _propTypes.default.func,
  onChangeEdition: _propTypes.default.func,
  onModerate: _propTypes.default.func,
  onDelete: _propTypes.default.func,
  answerPostDisabled: _propTypes.default.bool,
  answerTextareaDisabled: _propTypes.default.bool,
  answerable: _propTypes.default.bool,
  editable: _propTypes.default.bool,
  rejectable: _propTypes.default.bool,
  rejected: _propTypes.default.bool,
  deleted: _propTypes.default.bool,
  editionPostDisabled: _propTypes.default.bool,
  editionTextareaDisabled: _propTypes.default.bool
} : {};
var _default = exports.default = ForumPost;
//# sourceMappingURL=index.js.map