"use strict";

exports.__esModule = true;
exports.default = UserNotificationPrivateMessage;

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

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

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

var _Send = _interopRequireDefault(require("@mui/icons-material/Send"));

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

var _colors = require("@mui/material/colors");

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

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

var _NewChip = _interopRequireDefault(require("../NewChip"));

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 Root = (0, _styles.styled)(_material.Box, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => styles.root
})(({
  theme
}) => ({
  '& .MuiSvgIcon-root': {
    width: '0.7em',
    marginBottom: '0.5px',
    float: 'left'
  },
  '& .MuiListItemText-root': {
    color: _colors.grey[600],
    maxWidth: '60%'
  },
  '& .MuiListItemSecondaryAction-root': {
    color: _colors.grey[600],
    fontSize: '13px',
    maxWidth: '40%'
  },
  '& .MuiButton-root': {
    paddingTop: 1,
    paddingBottom: 1
  }
}));

/**
 * This component render the content of the notification of type private message
 * @param props
 * @constructor
 */
function UserNotificationPrivateMessage(props) {
  // PROPS
  const {
    notificationObject,
    id = `n_${props.notificationObject['sid']}`,
    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, {
    component: 'div',
    secondaryAction: /*#__PURE__*/_react.default.createElement(_material.Box, null, /*#__PURE__*/_react.default.createElement(_material.Box, {
      component: 'span',
      sx: {
        display: {
          xs: 'none',
          md: 'inline-block'
        },
        marginRight: '5px',
        paddingTop: '5px',
        float: 'left'
      }
    }, /*#__PURE__*/_react.default.createElement(_DateTimeAgo.default, {
      date: notificationObject.active_at
    })), /*#__PURE__*/_react.default.createElement(_material.Button, {
      variant: "outlined",
      size: "small",
      sx: {
        minWidth: 30
      },
      component: _core.Link,
      to: scRoutingContext.url(_core.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message)
    }, /*#__PURE__*/_react.default.createElement(_material.Box, {
      component: 'span',
      sx: {
        display: {
          xs: 'none',
          md: 'block'
        },
        marginRight: '2px'
      }
    }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "ui.notification.privateMessage.btnReplyLabel",
      defaultMessage: "ui.notification.privateMessage.btnReplyLabel"
    })), /*#__PURE__*/_react.default.createElement(_Send.default, null)))
  }, /*#__PURE__*/_react.default.createElement(_material.ListItemText, {
    disableTypography: true,
    primary: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, notificationObject.is_new && /*#__PURE__*/_react.default.createElement(_NewChip.default, null), /*#__PURE__*/_react.default.createElement(_material.Box, {
      sx: {
        display: 'inline-block'
      }
    }, /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url(_core.SCRoutes.USER_PRIVATE_MESSAGES_ROUTE_NAME, notificationObject.message)
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      variant: "body2",
      gutterBottom: true,
      dangerouslySetInnerHTML: {
        __html: notificationObject.message.html
      }
    }))))
  })));
}