"use strict";

exports.__esModule = true;
exports.default = UndeletedForNotification;

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

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

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

var _Icon = _interopRequireDefault(require("@mui/material/Icon"));

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

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

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

var _contribution = require("../../../utils/contribution");

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

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

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

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

var _NotificationItem = _interopRequireDefault(require("../../../shared/NotificationItem"));

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 PREFIX = 'SCUndeletedForNotification';
const classes = {
  root: `${PREFIX}-root`,
  undeletedIcon: `${PREFIX}-undeleted-icon`,
  undeletedText: `${PREFIX}-undeleted-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.undeletedIcon}`]: {
    backgroundColor: _colors.red[500],
    color: '#FFF'
  },
  [`& .${classes.undeletedText}`]: {
    color: theme.palette.text.primary
  },
  [`& .${classes.contributionWrap}`]: {
    marginBottom: theme.spacing(1),
    padding: theme.spacing(2),
    textOverflow: 'ellipsis',
    display: 'inline',
    overflow: 'hidden'
  },
  [`& .${classes.contributionText}`]: {
    '&:hover': {
      textDecoration: 'underline'
    }
  }
}));

/**
 * This component render the content of the notification of type undeleted for
 * @param inProps
 * @constructor
 */
function UndeletedForNotification(inProps) {
  // PROPS
  const props = (0, _useThemeProps.default)({
    props: inProps,
    name: PREFIX
  });

  const {
    notificationObject,
    id = `n_${props.notificationObject['sid']}`,
    className,
    template = _types.SCNotificationObjectTemplateType.DETAIL
  } = props,
        rest = _objectWithoutPropertiesLoose(props, _excluded); // CONTEXT


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

  const isSnippetTemplate = template === _types.SCNotificationObjectTemplateType.SNIPPET;
  const contributionType = (0, _contribution.getContributionType)(notificationObject);
  /**
   * 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(_NotificationItem.default, {
    template: template,
    isNew: notificationObject.is_new,
    disableTypography: true,
    image: /*#__PURE__*/_react.default.createElement(_material.Avatar, {
      variant: "circular",
      classes: {
        root: classes.undeletedIcon
      }
    }, /*#__PURE__*/_react.default.createElement(_Icon.default, null, "outlined_flag")),
    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, _contribution.getRouteData)(notificationObject[contributionType]))
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      component: "div",
      color: "inherit",
      className: classes.undeletedText
    }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "ui.notification.undeletedFor.restoredContentSnippet",
      defaultMessage: "ui.notification.undeletedFor.restoredContentSnippet"
    }))) : /*#__PURE__*/_react.default.createElement(_material.Typography, {
      component: "div",
      color: "inherit",
      className: classes.undeletedText
    }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "ui.notification.undeletedFor.restoredContent",
      defaultMessage: "ui.notification.undeletedFor.restoredContent"
    }))),
    secondary: template === _types.SCNotificationObjectTemplateType.DETAIL && /*#__PURE__*/_react.default.createElement(_DateTimeAgo.default, {
      date: notificationObject.active_at,
      className: classes.activeAt
    }),
    footer: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, !isSnippetTemplate && /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: classes.contributionWrap
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      variant: 'body2',
      color: 'inherit',
      component: 'div',
      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, _contribution.getRouteData)(notificationObject[contributionType])),
      className: classes.contributionText
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      component: 'span',
      variant: "body2",
      gutterBottom: true
    }, (0, _contribution.getContributionSnippet)(notificationObject[contributionType])))), template === _types.SCNotificationObjectTemplateType.TOAST && /*#__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",
      component: 'div'
    }, /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url(_core.SCRoutes[`${notificationObject[contributionType]['type'].toUpperCase()}_ROUTE_NAME`], (0, _contribution.getRouteData)(notificationObject[contributionType]))
    }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "ui.userToastNotifications.viewContribution",
      defaultMessage: 'ui.userToastNotifications.viewContribution'
    })))))
  }));
}