"use strict";

exports.__esModule = true;
exports.default = CommentRelevantActivity;

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"));

var _classnames = _interopRequireDefault(require("classnames"));

var _useThemeProps = _interopRequireDefault(require("@mui/material/styles/useThemeProps"));

var _BaseItem = _interopRequireDefault(require("../../../../../shared/BaseItem"));

const _excluded = ["className", "activityObject"];

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 messages = (0, _reactIntl.defineMessages)({
  comment: {
    id: 'ui.feedObject.relevantActivities.comment',
    defaultMessage: 'ui.feedObject.relevantActivities.comment'
  }
});
const PREFIX = 'SCCommentRelevantActivity';
const classes = {
  root: `${PREFIX}-root`,
  avatar: `${PREFIX}-avatar`,
  username: `${PREFIX}-username`
};
const Root = (0, _styles.styled)(_BaseItem.default, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => styles.root
})(({
  theme
}) => ({
  [`& .${classes.username}`]: {
    color: 'inherit'
  },
  '& .SCBaseItem-secondary': {
    display: 'flex',
    flexDirection: 'row',
    alignItems: 'center'
  }
}));

function CommentRelevantActivity(inProps) {
  // PROPS
  const props = (0, _useThemeProps.default)({
    props: inProps,
    name: PREFIX
  });

  const {
    className = null,
    activityObject = null
  } = props,
        rest = _objectWithoutPropertiesLoose(props, _excluded); // CONTEXT


  const scRoutingContext = (0, _core.useSCRouting)(); // INTL

  const intl = (0, _reactIntl.useIntl)(); // RENDER

  return /*#__PURE__*/_react.default.createElement(Root, _extends({}, rest, {
    className: (0, _classnames.default)(classes.root, className),
    image: /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url(_core.SCRoutes.USER_PROFILE_ROUTE_NAME, activityObject.author)
    }, /*#__PURE__*/_react.default.createElement(_material.Avatar, {
      alt: activityObject.author.username,
      variant: "circular",
      src: activityObject.author.avatar,
      className: classes.avatar
    })),
    primary: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, intl.formatMessage(messages.comment, {
      username: /*#__PURE__*/_react.default.createElement(_core.Link, {
        to: scRoutingContext.url(_core.SCRoutes.USER_PROFILE_ROUTE_NAME, activityObject.author),
        className: classes.username
      }, activityObject.author.username),
      comment: activityObject.comment.summary
    })),
    secondary: /*#__PURE__*/_react.default.createElement(_DateTimeAgo.default, {
      date: activityObject.active_at
    })
  }));
}