"use strict";

exports.__esModule = true;
exports.default = IncubatorApprovedNotification;

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 _NewChip = _interopRequireDefault(require("../../../shared/NewChip/NewChip"));

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", "template", "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)({
  incubatorApproved: {
    id: 'ui.notification.incubatorApproved.approved',
    defaultMessage: 'ui.notification.incubatorApproved.approved'
  }
});
const PREFIX = 'SCIncubatorApprovedNotification';
const classes = {
  root: `${PREFIX}-root`,
  categoryIcon: `${PREFIX}-category-icon`,
  categoryApprovedText: `${PREFIX}-category-approved-text`,
  activeAt: `${PREFIX}-active-at`,
  viewIncubatorButton: `${PREFIX}-view-incubator-button`
};
const Root = (0, _styles.styled)(_material.Box, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => styles.root
})(({
  theme
}) => ({
  [`& .${classes.categoryIcon}`]: {
    borderRadius: 3
  },
  [`& .${classes.viewIncubatorButton}`]: {
    padding: theme.spacing(),
    paddingBottom: 0,
    textTransform: 'initial',
    marginLeft: -8
  }
}));

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

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


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

  const isSnippetTemplate = template === _types.SCNotificationObjectTemplateType.SNIPPET; //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(_NotificationItem.default, {
    template: template,
    isNew: notificationObject.is_new,
    image: /*#__PURE__*/_react.default.createElement(_material.Avatar, {
      alt: notificationObject.incubator.approved_category.name,
      src: notificationObject.incubator.approved_category.image_medium,
      variant: "square",
      classes: {
        root: classes.categoryIcon
      }
    }),
    primary: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isSnippetTemplate ? /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url(_core.SCRoutes.CATEGORY_ROUTE_NAME, notificationObject.incubator.approved_category)
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      component: "div",
      className: classes.categoryApprovedText,
      color: "inherit"
    }, intl.formatMessage(messages.incubatorApproved, {
      name: notificationObject.incubator.name,
      b: (...chunks) => /*#__PURE__*/_react.default.createElement("strong", null, chunks)
    }))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, template === _types.SCNotificationObjectTemplateType.DETAIL && notificationObject.is_new && /*#__PURE__*/_react.default.createElement(_NewChip.default, null), /*#__PURE__*/_react.default.createElement(_material.Typography, {
      component: "div",
      className: classes.categoryApprovedText,
      color: "inherit"
    }, intl.formatMessage(messages.incubatorApproved, {
      name: notificationObject.incubator.name,
      b: (...chunks) => /*#__PURE__*/_react.default.createElement("strong", null, chunks)
    })))),
    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, template === _types.SCNotificationObjectTemplateType.DETAIL && /*#__PURE__*/_react.default.createElement(_material.Button, {
      component: _core.Link,
      to: scRoutingContext.url(_core.SCRoutes.CATEGORY_ROUTE_NAME, notificationObject.incubator.approved_category),
      className: classes.viewIncubatorButton
    }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: 'ui.notification.incubatorApproved.viewIncubator',
      defaultMessage: 'ui.notification.incubatorApproved.viewIncubator'
    })), 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.CATEGORY_ROUTE_NAME, notificationObject.incubator)
    }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
      id: "ui.userToastNotifications.incubatorApproved.viewIncubator",
      defaultMessage: 'ui.userToastNotifications.incubatorApproved.viewIncubator'
    })))))
  }));
}