import _identity from "lodash/fp/identity";
import _get from "lodash/fp/get";
import React from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { SrcPropType } from '../../../util/proptypes';
import Provider from '../../../atom/provider';
import Picture from '../../../atom/picture';
import ForumComment from '../forum-comment';
import style from './style.css';
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 = _identity,
    onEdit = _identity,
    onPostAnswer = _identity,
    onPostEdition = _identity,
    onChangeAnswer = _identity,
    onChangeEdition = _identity,
    onModerate,
    onDelete
  } = props;
  const color = _get('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.message;
  if (deleted) {
    messageClassName = style.deletedMessage;
  } else if (showEditBox) {
    messageClassName = style.hiddenMessage;
  }
  return /*#__PURE__*/React.createElement("div", {
    "data-name": "forumPost",
    id: `forum-post-${id || 'to-be-posted'}`,
    className: classnames(mainPost ? style.mainPost : null, rejected ? style.rejected : style.post)
  }, /*#__PURE__*/React.createElement("div", {
    className: style.avatarWrapper
  }, /*#__PURE__*/React.createElement("div", {
    className: style.image
  }, /*#__PURE__*/React.createElement(Picture, {
    src: avatar,
    className: style.avatar,
    alt: avatarAlt
  })), /*#__PURE__*/React.createElement("span", {
    "data-name": "author",
    className: style.author
  }, author)), /*#__PURE__*/React.createElement("div", {
    className: style.content
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", {
    className: style.date
  }, date)), /*#__PURE__*/React.createElement("div", {
    className: style.body
  }, /*#__PURE__*/React.createElement("span", {
    className: style.action,
    onClick: onAnswer,
    style: {
      color,
      display: answerable && !deleted && !rejected ? 'block' : 'none'
    }
  }, answerLabel), /*#__PURE__*/React.createElement("span", {
    className: style.action,
    onClick: onEdit,
    style: {
      color,
      display: editable ? 'block' : 'none'
    }
  }, editLabel), /*#__PURE__*/React.createElement("span", {
    className: style.action,
    onClick: onDelete,
    style: {
      color,
      display: editable ? 'block' : 'none'
    }
  }, deleteLabel), /*#__PURE__*/React.createElement("span", {
    className: style.action,
    onClick: onModerate,
    style: {
      color,
      display: rejectable ? 'block' : 'none'
    }
  }, rejected ? putBackLabel : rejectLabel), deleted ? /*#__PURE__*/React.createElement("div", {
    className: messageClassName,
    role: "status"
  }, infoDeleted) : /*#__PURE__*/React.createElement("div", {
    className: messageClassName
  }, message), /*#__PURE__*/React.createElement("div", {
    className: `${style.edition} ${showEditBox ? style.visible : ''}`
  }, /*#__PURE__*/React.createElement(ForumComment, {
    avatar: null,
    profileAvatarAlt: profileAvatarAlt,
    value: edition,
    textareaDisabled: editionTextareaDisabled,
    postDisabled: editionPostDisabled,
    onPost: onPostEdition,
    onChange: onChangeEdition
  })), /*#__PURE__*/React.createElement("div", {
    className: `${style.answer} ${showAnswerBox ? style.visible : ''}`
  }, /*#__PURE__*/React.createElement(ForumComment, {
    avatar: answerAvatar,
    profileAvatarAlt: profileAvatarAlt,
    textareaDisabled: answerTextareaDisabled,
    postDisabled: answerPostDisabled,
    value: answer,
    onPost: onPostAnswer,
    onChange: onChangeAnswer
  })))));
};
ForumPost.contextTypes = {
  translate: Provider.childContextTypes.translate,
  skin: Provider.childContextTypes.skin
};
ForumPost.propTypes = process.env.NODE_ENV !== "production" ? {
  id: PropTypes.string,
  author: PropTypes.string,
  avatarAlt: PropTypes.string,
  profileAvatarAlt: PropTypes.string,
  date: PropTypes.string,
  message: PropTypes.string,
  avatar: SrcPropType,
  answerAvatar: SrcPropType,
  answer: PropTypes.string,
  edition: PropTypes.string,
  showAnswerBox: PropTypes.bool,
  showEditBox: PropTypes.bool,
  mainPost: PropTypes.bool,
  onAnswer: PropTypes.func,
  onEdit: PropTypes.func,
  onPostAnswer: PropTypes.func,
  onPostEdition: PropTypes.func,
  onChangeAnswer: PropTypes.func,
  onChangeEdition: PropTypes.func,
  onModerate: PropTypes.func,
  onDelete: PropTypes.func,
  answerPostDisabled: PropTypes.bool,
  answerTextareaDisabled: PropTypes.bool,
  answerable: PropTypes.bool,
  editable: PropTypes.bool,
  rejectable: PropTypes.bool,
  rejected: PropTypes.bool,
  deleted: PropTypes.bool,
  editionPostDisabled: PropTypes.bool,
  editionTextareaDisabled: PropTypes.bool
} : {};
export default ForumPost;
//# sourceMappingURL=index.js.map