"use strict";

exports.__esModule = true;
exports.default = KindlyNoticeFlagNotification;

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 _core = require("@selfcommunity/core");

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

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

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

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

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

var _types = require("../../../types");

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

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)({
  kindlyNoticeFlag: {
    id: 'ui.notification.kindlyNoticeFlag.kindlyNoticeFlag',
    defaultMessage: 'ui.notification.kindlyNoticeFlag.kindlyNoticeFlag'
  }
});
const PREFIX = 'SCKindlyNoticeFlagNotification';
const classes = {
  root: `${PREFIX}-root`,
  listItemSnippet: `${PREFIX}-list-item-snippet`,
  listItemSnippetNew: `${PREFIX}-list-item-snippet-new`,
  flagIconWrap: `${PREFIX}-flag-icon-wrap`,
  flagIcon: `${PREFIX}-flag-icon`,
  flagIconSnippet: `${PREFIX}-flag-icon-snippet`,
  flagText: `${PREFIX}-flag-text`,
  activeAt: `${PREFIX}-active-at`,
  contributionWrap: `${PREFIX}-contribution-wrap`,
  contributionYouWroteLabel: `${PREFIX}-contribution-you-wrote-label`,
  contributionText: `${PREFIX}-contribution-text`
};
const Root = (0, _styles.styled)(_material.Box, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => styles.root
})(({
  theme
}) => ({
  [`& .${classes.listItemSnippet}`]: {
    padding: '0px 5px',
    alignItems: 'center'
  },
  [`& .${classes.listItemSnippetNew}`]: {
    borderLeft: '2px solid red'
  },
  [`& .${classes.flagIconWrap}`]: {
    minWidth: 'auto',
    paddingRight: 10
  },
  [`& .${classes.flagIcon}`]: {
    backgroundColor: _colors.red[500],
    color: '#FFF'
  },
  [`& .${classes.flagIconSnippet}`]: {
    width: 30,
    height: 30
  },
  [`& .${classes.flagText}`]: {
    display: 'inline',
    color: theme.palette.text.primary
  },
  [`& .${classes.contributionWrap}`]: {
    marginBottom: theme.spacing(1),
    padding: theme.spacing(2)
  },
  [`& .${classes.contributionText}`]: {
    textDecoration: 'underline'
  }
}));

/**
 * This component render the content of the notification of type kindly notice flag
 * @param props
 * @constructor
 */
function KindlyNoticeFlagNotification(props) {
  // PROPS
  const {
    notificationObject,
    id = `n_${props.notificationObject['sid']}`,
    className,
    template = _types.NotificationObjectTemplateType.DETAIL
  } = props,
        rest = _objectWithoutPropertiesLoose(props, _excluded); // ROUTING


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

  const isSnippetTemplate = template === _types.NotificationObjectTemplateType.SNIPPET;
  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: (0, _classnames.default)(classes.root, className, `${PREFIX}-${template}`)
  }, rest), /*#__PURE__*/_react.default.createElement(_material.ListItem, {
    alignItems: isSnippetTemplate ? 'center' : 'flex-start',
    component: 'div',
    classes: {
      root: (0, _classnames.default)({
        [classes.listItemSnippet]: isSnippetTemplate,
        [classes.listItemSnippetNew]: notificationObject.is_new
      })
    }
  }, /*#__PURE__*/_react.default.createElement(_material.ListItemAvatar, {
    classes: {
      root: classes.flagIconWrap
    }
  }, /*#__PURE__*/_react.default.createElement(_material.Avatar, {
    variant: "circular",
    classes: {
      root: (0, _classnames.default)(classes.flagIcon, {
        [classes.flagIconSnippet]: isSnippetTemplate
      })
    }
  }, /*#__PURE__*/_react.default.createElement(_EmojiFlags.default, null))), /*#__PURE__*/_react.default.createElement(_material.ListItemText, {
    disableTypography: true,
    primary: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isSnippetTemplate ? /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url(_core.SCRoutes[`${contributionType.toUpperCase()}_ROUTE_NAME`], (0, _contribute.getRouteData)(notificationObject[contributionType]))
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      component: "span",
      color: "inherit",
      className: classes.flagText
    }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: `ui.notification.kindlyNoticeFlag.kindlyNoticeFlagSnippet`,
      defaultMessage: `ui.notification.kindlyNoticeFlag.kindlyNoticeFlagSnippet`
    }))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, !isSnippetTemplate && notificationObject.is_new && /*#__PURE__*/_react.default.createElement(_NewChip.default, null), /*#__PURE__*/_react.default.createElement(_material.Typography, {
      component: "span",
      color: "inherit",
      className: classes.flagText
    }, intl.formatMessage(messages[_core.StringUtils.camelCase(notificationObject.type)], {
      b: (...chunks) => /*#__PURE__*/_react.default.createElement("strong", null, chunks)
    })))),
    secondary: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, " ", !isSnippetTemplate && /*#__PURE__*/_react.default.createElement(_DateTimeAgo.default, {
      date: notificationObject.active_at,
      className: classes.activeAt
    }))
  })), !isSnippetTemplate && /*#__PURE__*/_react.default.createElement(_material.Box, {
    className: classes.contributionWrap
  }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
    variant: 'body2',
    color: 'inherit',
    component: 'span',
    classes: {
      root: classes.contributionYouWroteLabel
    }
  }, /*#__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(_core.SCRoutes[`${contributionType.toUpperCase()}_ROUTE_NAME`], (0, _contribute.getRouteData)(notificationObject[contributionType])),
    className: classes.contributionText
  }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
    component: 'span',
    variant: "body2",
    gutterBottom: true
  }, (0, _contribute.getContributionSnippet)(notificationObject[contributionType])))));
}