"use strict";

exports.__esModule = true;
exports.default = CollapsedForNotificationToast;

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

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

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

var _EmojiFlags = _interopRequireDefault(require("@mui/icons-material/EmojiFlags"));

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

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

var _contribute = require("../../../../utils/contribute");

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

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

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 messages = (0, _reactIntl.defineMessages)({
  collapsedForAdvertising: {
    id: 'ui.notification.collapsedFor.collapsedForAdvertising',
    defaultMessage: 'ui.notification.collapsedFor.collapsedForAdvertising'
  },
  collapsedForAggressive: {
    id: 'ui.notification.collapsedFor.collapsedForAggressive',
    defaultMessage: 'ui.notification.collapsedFor.collapsedForAggressive'
  },
  collapsedForVulgar: {
    id: 'ui.notification.collapsedFor.collapsedForVulgar',
    defaultMessage: 'ui.notification.collapsedFor.collapsedForVulgar'
  },
  collapsedForPoor: {
    id: 'ui.notification.collapsedFor.collapsedForPoor',
    defaultMessage: 'ui.notification.collapsedFor.collapsedForPoor'
  },
  collapsedForOfftopic: {
    id: 'ui.notification.collapsedFor.collapsedForOfftopic',
    defaultMessage: 'ui.notification.collapsedFor.collapsedForOfftopic'
  }
});
const PREFIX = 'SCCollapsedForNotificationToast';
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 15px 0px'
  }
}));

/**
 * !IMPORTANT: this component is not used yet because the notification via ws is not launched
 * This component render the content of the
 * toast notification of type collapsed notice (contribution)
 * @param props
 * @constructor
 */
function CollapsedForNotificationToast(props) {
  // PROPS
  const {
    notificationObject = null,
    id = `tn_${props.notificationObject['feed_serialization_id']}`,
    className
  } = props,
        rest = _objectWithoutPropertiesLoose(props, _excluded); // ROUTING


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

  const contributionType = (0, _contribute.getContributeType)(notificationObject); //INTL

  const intl = (0, _reactIntl.useIntl)();
  /**
   * Renders root object
   */

  return /*#__PURE__*/_react.default.createElement(Root, _extends({
    id: id,
    className: className
  }, rest), /*#__PURE__*/_react.default.createElement(_material.ListItem, {
    component: 'div',
    className: classes.content
  }, /*#__PURE__*/_react.default.createElement(_material.ListItemAvatar, null, /*#__PURE__*/_react.default.createElement(_material.Avatar, {
    variant: "circular",
    sx: {
      backgroundColor: _colors.red[500]
    }
  }, /*#__PURE__*/_react.default.createElement(_EmojiFlags.default, null))), /*#__PURE__*/_react.default.createElement(_material.ListItemText, {
    disableTypography: true,
    primary: /*#__PURE__*/_react.default.createElement(_material.Typography, {
      component: "span",
      sx: {
        display: 'inline'
      },
      color: "primary"
    }, /*#__PURE__*/_react.default.createElement("b", null, intl.formatMessage(messages[_core.StringUtils.camelCase(notificationObject.type)], {
      b: (...chunks) => /*#__PURE__*/_react.default.createElement("strong", null, chunks)
    }), " (", /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "ui.notification.viewRules",
      defaultMessage: "ui.notification.viewRules"
    }), ")."))
  })), /*#__PURE__*/_react.default.createElement(_material.Box, {
    sx: {
      mb: 1
    }
  }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
    variant: 'body2',
    color: 'primary',
    sx: {
      p: 1
    }
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
    id: "ui.notification.undeletedFor.youWrote",
    defaultMessage: "ui.notification.undeletedFor.youWrote"
  })), /*#__PURE__*/_react.default.createElement(_core.Link, {
    to: scRoutingContext.url(contributionType, {
      id: notificationObject[contributionType].id
    })
  }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
    component: 'span',
    variant: "body2",
    sx: {
      textDecoration: 'underline'
    },
    gutterBottom: true,
    dangerouslySetInnerHTML: {
      __html: notificationObject[contributionType].summary
    }
  }))), /*#__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(_core.SCRoutes[`${notificationObject[contributionType].type.toUpperCase()}_ROUTE_NAME`], (0, _contribute.getRouteData)(notificationObject[contributionType]))
  }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
    id: "ui.userToastNotifications.viewContribution",
    defaultMessage: 'ui.userToastNotifications.viewContribution'
  })))));
}