"use strict";

exports.__esModule = true;
exports.default = UserNotificationPrivateMessageToast;

var _react = _interopRequireDefault(require("react"));

var _styles = require("@mui/material/styles");

var _material = require("@mui/material");

var _core = require("@selfcommunity/core");

var _reactIntl = require("react-intl");

var _DateTimeAgo = _interopRequireDefault(require("../../../../shared/DateTimeAgo"));

const _excluded = ["notificationObject", "id", "className"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

const PREFIX = 'SCUserNotificationPrivateMessage';
const classes = {
  content: `${PREFIX}-content`
};
const Root = (0, _styles.styled)(_material.Box, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => styles.root
})(({
  theme
}) => ({
  [`& .${PREFIX}-content`]: {
    padding: '8px 0px 10px 0px'
  }
}));

/**
 * This component render the content of the
 * toast notification of type private message
 * @param props
 * @constructor
 */
function UserNotificationPrivateMessageToast(props) {
  // PROPS
  const {
    notificationObject = null,
    id = `tn_${props.notificationObject['feed_serialization_id']}`,
    className
  } = props,
        rest = _objectWithoutPropertiesLoose(props, _excluded); // CONTEXT


  const scRoutingContext = (0, _core.useSCRouting)();
  /**
   * Renders root object
   */

  return /*#__PURE__*/_react.default.createElement(Root, _extends({
    id: id,
    className: className
  }, rest), /*#__PURE__*/_react.default.createElement(_material.ListItem, {
    alignItems: 'flex-start',
    component: 'div',
    className: classes.content
  }, /*#__PURE__*/_react.default.createElement(_material.ListItemAvatar, null, /*#__PURE__*/_react.default.createElement(_core.Link, {
    to: scRoutingContext.url(_core.SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.private_message.sender)
  }, /*#__PURE__*/_react.default.createElement(_material.Avatar, {
    alt: notificationObject.private_message.sender.username,
    variant: "circular",
    src: notificationObject.private_message.sender.avatar
  }))), /*#__PURE__*/_react.default.createElement(_material.ListItemText, {
    disableTypography: true,
    primary: /*#__PURE__*/_react.default.createElement(_material.Typography, null, /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url(_core.SCRoutes.USER_PROFILE_ROUTE_NAME, notificationObject.private_message.sender)
    }, notificationObject.private_message.sender.username), ' ', /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: 'ui.userToastNotifications.privateMessage.sentMessage',
      defaultMessage: 'ui.userToastNotifications.privateMessage.sentMessage'
    }), ":"),
    secondary: /*#__PURE__*/_react.default.createElement(_material.Typography, {
      color: "primary",
      gutterBottom: true,
      dangerouslySetInnerHTML: {
        __html: notificationObject.private_message.html
      }
    })
  })), /*#__PURE__*/_react.default.createElement(_material.Stack, {
    direction: "row",
    justifyContent: "space-between",
    alignItems: "center",
    spacing: 2
  }, /*#__PURE__*/_react.default.createElement(_DateTimeAgo.default, {
    date: notificationObject.active_at
  }), /*#__PURE__*/_react.default.createElement(_material.Typography, {
    color: "primary"
  }, /*#__PURE__*/_react.default.createElement(_core.Link, {
    to: scRoutingContext.url('messages', {
      id: notificationObject.private_message.id
    })
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
    id: "ui.userToastNotifications.replyMessage",
    defaultMessage: 'ui.userToastNotifications.replyMessage'
  })))));
}