"use strict";

exports.__esModule = true;
exports.default = FeedObject;

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

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

var _CardContent = _interopRequireDefault(require("@mui/material/CardContent"));

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

var _Skeleton = _interopRequireDefault(require("./Skeleton"));

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

var _Bullet = _interopRequireDefault(require("../../shared/Bullet"));

var _Tags = _interopRequireDefault(require("../../shared/Tags"));

var _MediasPreview = _interopRequireDefault(require("../../shared/MediasPreview"));

var _Actions = _interopRequireDefault(require("./Actions"));

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

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

var _Poll = _interopRequireDefault(require("./Poll"));

var _Contributors = _interopRequireDefault(require("./Contributors"));

var _reactLazyload = _interopRequireDefault(require("react-lazyload"));

var _Composer = _interopRequireDefault(require("../Composer"));

var _feedObject = require("../../types/feedObject");

var _MarkRead = _interopRequireDefault(require("../../shared/MarkRead"));

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

var _ContributionActionsMenu = _interopRequireDefault(require("../../shared/ContributionActionsMenu"));

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

var _Follow = _interopRequireDefault(require("./Actions/Follow"));

var _Widget = _interopRequireDefault(require("../Widget"));

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

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

var _Activities = _interopRequireDefault(require("./Activities"));

var _ReplyComment = _interopRequireDefault(require("../CommentObject/ReplyComment"));

var _Errors = require("../../constants/Errors");

var _notistack = require("notistack");

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

const _excluded = ["id", "className", "feedObjectId", "feedObject", "feedObjectType", "feedObjectActivities", "markRead", "template", "hideFollowAction", "hideParticipantsPreview", "FollowButtonProps", "FeedObjectSkeletonProps", "ActionsProps", "ReplyCommentComponent", "ReplyCommentComponentProps", "CommentComponentProps", "CommentObjectSkeletonProps", "ContributionActionsMenuProps", "MediasPreviewProps", "PollObjectProps", "ContributorsFeedObjectProps", "onReply"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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)({
  visibleToAll: {
    id: 'ui.feedObject.visibleToAll',
    defaultMessage: 'ui.feedObject.visibleToAll'
  }
});
const PREFIX = 'SCFeedObject';
const classes = {
  root: `${PREFIX}-root`,
  deleted: `${PREFIX}-deleted`,
  header: `${PREFIX}-header`,
  category: `${PREFIX}-category`,
  username: `${PREFIX}-username`,
  activityAt: `${PREFIX}-activity-at`,
  tag: `${PREFIX}-tag`,
  content: `${PREFIX}-content`,
  titleSection: `${PREFIX}-title-section`,
  title: `${PREFIX}-title`,
  textSection: `${PREFIX}-text-section`,
  text: `${PREFIX}-text`,
  snippetContent: `${PREFIX}-snippet-content`,
  mediasSection: `${PREFIX}-medias-section`,
  pollsSection: `${PREFIX}-polls-section`,
  infoSection: `${PREFIX}-info-section`,
  actionsSection: `${PREFIX}-actions-section`,
  replyContent: `${PREFIX}-reply-content`,
  activitiesSection: `${PREFIX}-activities-section`,
  activitiesContent: `${PREFIX}-activities-content`,
  followButton: `${PREFIX}-follow-button`
};
const Root = (0, _styles.styled)(_Widget.default, {
  name: PREFIX,
  slot: 'Root',
  overridesResolver: (props, styles) => styles.root
})(({
  theme
}) => ({
  marginBottom: theme.spacing(2),
  [`&.${classes.root}`]: {
    width: '100%'
  },
  [`& .${classes.header}`]: {
    paddingBottom: 0
  },
  [`& .${classes.titleSection}`]: {
    '& a': {
      textDecoration: 'none'
    },
    '& a:hover': {
      textDecoration: 'underline'
    }
  },
  [`& .${classes.title}`]: {
    fontWeight: 600,
    color: '#3e3e3e',
    padding: `0px ${theme.spacing(2)}`
  },
  [`& .${classes.username}`]: {
    color: '#000',
    fontWeight: 600,
    fontSize: '15px',
    textDecoration: 'none'
  },
  [`& .${classes.header}`]: {
    '& .MuiCardHeader-subheader': {
      display: 'flex',
      alignItems: 'center'
    }
  },
  [`& .${classes.category}`]: {
    textAlign: 'center',
    color: '#939598',
    borderBottom: '1px solid rgba(0, 0, 0, 0.12)',
    '& a': {
      textDecoration: 'none',
      color: '#3e3e3e'
    },
    '& a::after': {
      content: '"\\2022"',
      padding: theme.spacing()
    },
    '& a:last-child::after': {
      display: 'none'
    },
    '& span': {
      textTransform: 'initial'
    }
  },
  [`& .${classes.content}`]: {
    padding: `${theme.spacing()} 0px`
  },
  [`& .${classes.textSection}`]: {
    '& a': {
      color: theme.palette.text.primary,
      textDecoration: 'none'
    }
  },
  [`& .${classes.text}`]: {
    padding: `${theme.spacing()} ${theme.spacing(2)}`,
    marginBottom: 0,
    '& a': {
      color: theme.palette.text.primary
    }
  },
  [`& .${classes.snippetContent}`]: {
    textDecoration: 'none',
    color: '#3e3e3e'
  },
  [`& .${classes.tag}`]: {
    display: 'inline-block',
    position: 'relative',
    top: 3
  },
  [`& .${classes.actionsSection}`]: {
    padding: 0,
    display: 'flex',
    flexDirection: 'column'
  },
  [`& .${classes.replyContent}`]: {
    width: '100%',
    boxSizing: 'border-box',
    margin: 0,
    padding: theme.spacing(2)
  },
  [`& .${classes.activitiesContent}`]: {
    paddingTop: 3,
    paddingBottom: 3
  },
  [`& .${classes.infoSection}`]: {
    padding: `0px ${theme.spacing(2)}`
  },
  [`& .${classes.activityAt}`]: {
    textDecoration: 'none',
    color: 'inherit',
    marginTop: 3
  },
  [`& .${classes.deleted}`]: {
    opacity: 0.3,
    '&:hover': {
      opacity: 1
    }
  },
  '& .MuiIcon-root': {
    fontSize: '18px',
    marginBottom: '0.5px'
  }
}));

/**
 * > API documentation for the Community-UI Feed Object component. Learn about the available props and the CSS API.

 #### Import

 ```jsx
 import {FeedObject} from '@selfcommunity/ui';
 ```

 #### Component Name

 The name `SCFeedObject` can be used when providing style overrides in the theme.


 #### CSS

 |Rule Name|Global class|Description|
 |---|---|---|
 |root|.SCFeedObject-root|Styles applied to the root element.|
 |header|.SCFeedObject-header|Styles applied to the header of the card.|
 |tag|.SCFeedObject-tag|Styles applied to the tag element.|
 |title-section|.SCFeedObject-title-section|Styles applied to the title section.|
 |title|.SCFeedObject-title|Styles applied to the title element.|
 |username|.SCFeedObject-username|Styles applied to the username element.|
 |category|.SCFeedObject-category|Styles applied to the category element.|
 |content|.SCFeedObject-content|Styles applied to the content section. Content section include: title-section, text-section, snippetContent, subContent, medias-section, polls-section, info-section.|
 |text-section|.SCFeedObject-text-section|Styles applied to the text section.|
 |text|.SCFeedObject-text|Styles applied to the text element.|
 |snippet-content|.SCFeedObject-snippet-content|Styles applied to snippet content element.|
 |medias-section|.SCFeedObject-medias-section|Styles applied to the medias section.|
 |polls-section|.SCFeedObject-polls-section|Styles applied to the polls section.|
 |info-section|.SCFeedObject-info-section|Styles applied to the info section.|
 |subContent|.SCFeedObject-sub-content|Styles applied to the sub content (container placed immediately after the content, similar to a footer). Wrap the contributors and the follow button.|
 |actions-section|.SCFeedObject-actions-section|Styles applied to the actions container.|
 |reply-content|.SCFeedObject-reply-content|Styles applied to the reply box.|
 |activitiesSection|.SCFeedObject-activities-section|Styles applied to the activities section element.|
 |activitiesContent|.SCFeedObject-activities-content|Styles applied to the activities content element.|
 |activityAt|.SCFeedObject-activity-at|Styles applied to the activity at section.|
 |deleted|.SCFeedObject-deleted|Styles applied to the feed obj when is deleted (visible only for admin and moderator).|

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

  const {
    id = `feed_object_${props.feedObjectId ? props.feedObjectId : props.feedObject ? props.feedObject.id : ''}`,
    className = null,
    feedObjectId = null,
    feedObject = null,
    feedObjectType = _core.SCFeedObjectTypologyType.POST,
    feedObjectActivities = null,
    markRead = false,
    template = _feedObject.SCFeedObjectTemplateType.PREVIEW,
    hideFollowAction = false,
    hideParticipantsPreview = false,
    FollowButtonProps = {},
    FeedObjectSkeletonProps = {
      elevation: 0
    },
    ActionsProps = {},
    ReplyCommentComponent = _ReplyComment.default,
    ReplyCommentComponentProps = {
      ReplyBoxProps: {
        variant: 'outlined'
      }
    },
    CommentComponentProps = {
      variant: 'outlined'
    },
    CommentObjectSkeletonProps = {
      elevation: 0,
      WidgetProps: {
        variant: 'outlined'
      }
    },
    ContributionActionsMenuProps = {},
    MediasPreviewProps = {},
    PollObjectProps = {
      elevation: 0
    },
    ContributorsFeedObjectProps = {},
    onReply
  } = props,
        rest = _objectWithoutPropertiesLoose(props, _excluded); // CONTEXT


  const scContext = (0, _core.useSCContext)();
  const scRoutingContext = (0, _core.useSCRouting)();
  const scUserContext = (0, _core.useSCUser)();
  const {
    enqueueSnackbar
  } = (0, _notistack.useSnackbar)(); // RETRIVE OBJECTS

  const {
    obj,
    setObj
  } = (0, _core.useSCFetchFeedObject)({
    id: feedObjectId,
    feedObject,
    feedObjectType
  });
  const objId = obj ? obj.id : null; // STATE

  const [composerOpen, setComposerOpen] = (0, _react.useState)(false);
  const [expandedActivities, setExpandedActivities] = (0, _react.useState)(false);
  const [comments, setComments] = (0, _react.useState)([]);
  const [isReplying, setIsReplying] = (0, _react.useState)(false);
  const [selectedActivities, setSelectedActivities] = (0, _react.useState)(getInitialSelectedActivitiesType()); // INTL

  const intl = (0, _reactIntl.useIntl)();
  /**
   * Get initial expanded activities
   */

  function geExpandedActivities() {
    return obj && (feedObjectActivities && feedObjectActivities.length > 0 || obj.comment_count > 0);
  }
  /**
   * Get initial selected activities section
   */


  function getInitialSelectedActivitiesType() {
    if (feedObjectActivities && feedObjectActivities.length > 0) {
      return _feedObject.SCFeedObjectActivitiesType.RELEVANCE_ACTIVITIES;
    }

    return _feedObject.SCFeedObjectActivitiesType.RECENT_COMMENTS;
  }
  /**
   * Open expanded activities
   */


  (0, _react.useEffect)(() => {
    setExpandedActivities(geExpandedActivities);
  }, [objId]);
  /**
   * Handle change/update poll: votes
   */

  function handleChangePoll(pollObject) {
    const newObj = obj;
    obj['poll'] = pollObject;
    setObj(newObj);
  }
  /**
   * Render header action
   * if author = authenticated user -> render edit action
   * else render ContributionActionsMenu
   */


  function renderHeaderAction() {
    return /*#__PURE__*/_react.default.createElement(_ContributionActionsMenu.default, _extends({
      feedObject: obj,
      feedObjectType: feedObjectType,
      onEditContribution: handleToggleEdit,
      onHideContribution: handleHide,
      onDeleteContribution: handleDelete,
      onRestoreContribution: handleRestore,
      onSuspendNotificationContribution: handleSuspendNotification
    }, ContributionActionsMenuProps));
  }
  /**
   * Handle restore obj
   */


  function handleRestore() {
    setObj(prev => Object.assign({}, prev, {
      deleted: false
    }));
  }
  /**
   * Handle restore obj
   */


  function handleHide() {
    setObj(prev => Object.assign({}, prev, {
      collapsed: !prev.collapsed
    }));
  }
  /**
   * Handle delete obj
   */


  function handleDelete() {
    setObj(prev => Object.assign({}, prev, {
      deleted: !prev.deleted
    }));
  }
  /**
   * Handle suspend notification obj
   */


  function handleSuspendNotification() {
    setObj(prev => Object.assign({}, prev, {
      suspended: !prev.suspended
    }));
  }
  /**
   * Handle initial edit
   * Open composer
   */


  function handleToggleEdit() {
    setComposerOpen(prev => !prev);
  }
  /**
   * handle edit success
   */


  function handleEditSuccess(data) {
    setObj(data);
    setComposerOpen(false);
  }
  /**
   * Expand activities if the user is logged
   */


  function handleExpandActivities() {
    if (scUserContext.user) {
      setExpandedActivities(prev => !prev);
    } else {
      scContext.settings.handleAnonymousAction();
    }
  }
  /**
   * Handle follow obj
   */


  function handleFollow(isFollow) {
    setObj(prev => Object.assign({}, prev, {
      followed: isFollow
    }));
  }
  /**
   * Handle delete comment callback
   */


  function handleDeleteComment() {
    setObj(prev => Object.assign({}, prev, {
      comment_count: Math.max(prev.comment_count - 1, 0)
    }));
  }
  /**
   * Handle select activities
   */


  function handleSelectedActivities(type) {
    setSelectedActivities(type);
    setComments([]);
  }
  /**
   * Perform reply
   * Comment of first level
   */


  const performReply = (0, _react.useMemo)(() => comment => {
    return _core.http.request({
      url: _core.Endpoints.NewComment.url({}),
      method: _core.Endpoints.NewComment.method,
      data: {
        [`${feedObjectType}`]: obj.id,
        text: comment
      }
    }).then(res => {
      if (res.status >= 300) {
        return Promise.reject(res);
      }

      return Promise.resolve(res.data);
    });
  }, [objId]);
  /**
   * Handle comment
   */

  function handleReply(comment) {
    if (_core.UserUtils.isBlocked(scUserContext.user)) {
      enqueueSnackbar( /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
        id: "ui.common.userBlocked",
        defaultMessage: "ui.common.userBlocked"
      }), {
        variant: 'warning',
        autoHideDuration: 3000
      });
    } else {
      setIsReplying(true);
      performReply(comment).then(data => {
        if (selectedActivities !== _feedObject.SCFeedObjectActivitiesType.RECENT_COMMENTS) {
          setComments([]);
          setSelectedActivities(_feedObject.SCFeedObjectActivitiesType.RECENT_COMMENTS);
        } else {
          setComments([...[data], ...comments]);
        }

        setIsReplying(false);
        setObj(prev => Object.assign({}, prev, {
          comment_count: prev.comment_count + 1
        }));
        onReply && onReply(data);
      }).catch(error => {
        _core.Logger.error(_Errors.SCOPE_SC_UI, error);

        enqueueSnackbar( /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
          id: "ui.common.error.action",
          defaultMessage: "ui.common.error.action"
        }), {
          variant: 'error',
          autoHideDuration: 3000
        });
      });
    }
  }
  /**
   * Render the obj object
   * Manage variants:
   * SNIPPET, PREVIEW, DETAIL
   */


  let objElement;

  if (template === _feedObject.SCFeedObjectTemplateType.PREVIEW || template === _feedObject.SCFeedObjectTemplateType.DETAIL) {
    objElement = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, obj ? /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: (0, _classnames.default)({
        [classes.deleted]: obj && obj.deleted
      })
    }, obj.categories.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
      className: classes.category
    }, obj.categories.map(c => /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url(_core.SCRoutes.CATEGORY_ROUTE_NAME, c),
      key: c.id
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      variant: "overline"
    }, c.name)))), /*#__PURE__*/_react.default.createElement(_material.CardHeader, {
      classes: {
        root: classes.header
      },
      avatar: /*#__PURE__*/_react.default.createElement(_core.Link, {
        to: scRoutingContext.url(_core.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author)
      }, /*#__PURE__*/_react.default.createElement(_material.Avatar, {
        "aria-label": "recipe",
        src: obj.author.avatar
      }, obj.author.username)),
      title: /*#__PURE__*/_react.default.createElement(_core.Link, {
        to: scRoutingContext.url(_core.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author),
        className: classes.username
      }, obj.author.username),
      subheader: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_core.Link, {
        to: scRoutingContext.url((0, _contribution.getContributionRouteName)(obj), (0, _contribution.getRouteData)(obj)),
        className: classes.activityAt
      }, /*#__PURE__*/_react.default.createElement(_DateTimeAgo.default, {
        component: 'span',
        date: obj.added_at
      })), /*#__PURE__*/_react.default.createElement(_Bullet.default, null), /*#__PURE__*/_react.default.createElement(_material.Box, {
        className: classes.tag
      }, obj.addressing.length > 0 ? /*#__PURE__*/_react.default.createElement(_Tags.default, {
        tags: obj.addressing
      }) : /*#__PURE__*/_react.default.createElement(_material.Tooltip, {
        title: `${intl.formatMessage(messages.visibleToAll)}`
      }, /*#__PURE__*/_react.default.createElement(_Icon.default, {
        color: "disabled",
        fontSize: "small"
      }, "public")))),
      action: renderHeaderAction()
    }), /*#__PURE__*/_react.default.createElement(_CardContent.default, {
      classes: {
        root: classes.content
      }
    }, /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: classes.titleSection
    }, 'title' in obj && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, template === _feedObject.SCFeedObjectTemplateType.DETAIL ? /*#__PURE__*/_react.default.createElement(_material.Typography, {
      variant: "body1",
      gutterBottom: true,
      className: classes.title
    }, obj.title) : /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url((0, _contribution.getContributionRouteName)(obj), (0, _contribution.getRouteData)(obj))
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      variant: "body1",
      gutterBottom: true,
      className: classes.title
    }, obj.title)))), /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: classes.textSection
    }, template === _feedObject.SCFeedObjectTemplateType.DETAIL ? /*#__PURE__*/_react.default.createElement(_material.Typography, {
      component: "div",
      gutterBottom: true,
      className: classes.text,
      dangerouslySetInnerHTML: {
        __html: (0, _contribution.getContributionHtml)(obj, scRoutingContext.url)
      }
    }) : /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url((0, _contribution.getContributionRouteName)(obj), (0, _contribution.getRouteData)(obj))
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      component: "div",
      gutterBottom: true,
      className: classes.text,
      dangerouslySetInnerHTML: {
        __html: obj.summary
      }
    }))), /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: classes.mediasSection
    }, /*#__PURE__*/_react.default.createElement(_MediasPreview.default, _extends({
      medias: obj.medias
    }, MediasPreviewProps))), /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: classes.pollsSection
    }, obj['poll'] && /*#__PURE__*/_react.default.createElement(_Poll.default, _extends({
      feedObject: obj,
      pollObject: obj['poll'],
      onChange: handleChangePoll
    }, PollObjectProps))), /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: classes.infoSection
    }, /*#__PURE__*/_react.default.createElement(_material.Stack, {
      direction: "row",
      justifyContent: "space-between",
      alignItems: "center",
      spacing: 2
    }, !hideParticipantsPreview && /*#__PURE__*/_react.default.createElement(_reactLazyload.default, {
      once: true
    }, /*#__PURE__*/_react.default.createElement(_Contributors.default, _extends({
      feedObject: obj,
      feedObjectType: obj.type
    }, ContributorsFeedObjectProps))), !hideFollowAction && /*#__PURE__*/_react.default.createElement(_Follow.default, _extends({
      feedObject: obj,
      feedObjectType: obj.type,
      handleFollow: handleFollow
    }, FollowButtonProps))))), /*#__PURE__*/_react.default.createElement(_material.CardActions, {
      className: classes.actionsSection
    }, /*#__PURE__*/_react.default.createElement(_Actions.default, _extends({
      feedObject: obj,
      hideCommentAction: template === _feedObject.SCFeedObjectTemplateType.DETAIL,
      handleExpandActivities: handleExpandActivities
    }, ActionsProps)), scUserContext.user && (expandedActivities || template === _feedObject.SCFeedObjectTemplateType.DETAIL) && /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: classes.replyContent
    }, /*#__PURE__*/_react.default.createElement(ReplyCommentComponent, _extends({
      inline: true,
      onReply: handleReply,
      readOnly: isReplying || !obj,
      key: Number(isReplying)
    }, ReplyCommentComponentProps)))), template === _feedObject.SCFeedObjectTemplateType.PREVIEW && /*#__PURE__*/_react.default.createElement(_material.Collapse, {
      in: expandedActivities,
      timeout: "auto",
      unmountOnExit: true,
      classes: {
        root: classes.activitiesSection
      }
    }, /*#__PURE__*/_react.default.createElement(_CardContent.default, {
      className: classes.activitiesContent
    }, /*#__PURE__*/_react.default.createElement(_reactLazyload.default, {
      once: true
    }, /*#__PURE__*/_react.default.createElement(_Activities.default, {
      feedObject: obj,
      feedObjectActivities: feedObjectActivities,
      activitiesType: selectedActivities,
      onSetSelectedActivities: handleSelectedActivities,
      comments: comments,
      CommentsObjectProps: {
        CommentComponentProps: Object.assign({}, {
          onDelete: handleDeleteComment
        }, CommentComponentProps),
        CommentObjectSkeletonProps: CommentObjectSkeletonProps
      }
    })))), composerOpen && /*#__PURE__*/_react.default.createElement(_Composer.default, {
      open: composerOpen,
      feedObject: obj,
      onClose: handleToggleEdit,
      onSuccess: handleEditSuccess,
      maxWidth: "sm",
      fullWidth: true,
      scroll: "body"
    })) : /*#__PURE__*/_react.default.createElement(_Skeleton.default, _extends({
      template: template
    }, FeedObjectSkeletonProps)));
  } else if (template === _feedObject.SCFeedObjectTemplateType.SHARE) {
    objElement = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, obj ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, obj.categories.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
      className: classes.category
    }, obj.categories.map(c => /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url(_core.SCRoutes.CATEGORY_ROUTE_NAME, c),
      key: c.id
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      variant: "overline"
    }, c.name)))), /*#__PURE__*/_react.default.createElement(_material.CardHeader, {
      classes: {
        root: classes.header
      },
      avatar: /*#__PURE__*/_react.default.createElement(_core.Link, {
        to: scRoutingContext.url(_core.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author),
        className: classes.username
      }, /*#__PURE__*/_react.default.createElement(_material.Avatar, {
        "aria-label": "recipe",
        src: obj.author.avatar
      }, obj.author.username)),
      title: /*#__PURE__*/_react.default.createElement(_core.Link, {
        to: scRoutingContext.url(_core.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author),
        className: classes.username
      }, obj.author.username),
      subheader: /*#__PURE__*/_react.default.createElement(_core.Link, {
        to: scRoutingContext.url((0, _contribution.getContributionRouteName)(obj), (0, _contribution.getRouteData)(obj)),
        className: classes.activityAt
      }, /*#__PURE__*/_react.default.createElement(_DateTimeAgo.default, {
        date: obj.added_at
      }))
    }), /*#__PURE__*/_react.default.createElement(_CardContent.default, {
      classes: {
        root: classes.content
      }
    }, /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: classes.titleSection
    }, 'title' in obj && /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url((0, _contribution.getContributionRouteName)(obj), (0, _contribution.getRouteData)(obj))
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      variant: "body1",
      gutterBottom: true,
      className: classes.title
    }, obj.title))), /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: classes.textSection
    }, /*#__PURE__*/_react.default.createElement(_core.Link, {
      to: scRoutingContext.url((0, _contribution.getContributionRouteName)(obj), (0, _contribution.getRouteData)(obj)),
      className: classes.text
    }, /*#__PURE__*/_react.default.createElement(_material.Typography, {
      component: "div",
      className: classes.text,
      variant: "body2",
      gutterBottom: true,
      dangerouslySetInnerHTML: {
        __html: obj.html
      }
    }))), /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: classes.mediasSection
    }, /*#__PURE__*/_react.default.createElement(_MediasPreview.default, _extends({
      medias: obj.medias
    }, PollObjectProps))), /*#__PURE__*/_react.default.createElement(_material.Box, {
      className: classes.pollsSection
    }, obj['poll'] && /*#__PURE__*/_react.default.createElement(_Poll.default, _extends({
      feedObject: obj,
      pollObject: obj['poll'],
      onChange: handleChangePoll
    }, PollObjectProps))))) : /*#__PURE__*/_react.default.createElement(_Skeleton.default, _extends({
      template: template
    }, FeedObjectSkeletonProps)));
  } else {
    objElement = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, obj ? /*#__PURE__*/_react.default.createElement(_BaseItem.default, {
      elevation: 0,
      image: /*#__PURE__*/_react.default.createElement(_core.Link, {
        to: scRoutingContext.url(_core.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author)
      }, /*#__PURE__*/_react.default.createElement(_material.Avatar, {
        alt: obj.author.username,
        variant: "circular",
        src: obj.author.avatar
      })),
      primary: /*#__PURE__*/_react.default.createElement(_core.Link, {
        to: scRoutingContext.url(_core.SCRoutes.USER_PROFILE_ROUTE_NAME, obj.author),
        className: classes.username
      }, obj.author.username),
      disableTypography: true,
      secondary: /*#__PURE__*/_react.default.createElement(_material.Box, null, /*#__PURE__*/_react.default.createElement(_material.Typography, {
        variant: "body2"
      }, /*#__PURE__*/_react.default.createElement(_core.Link, {
        to: scRoutingContext.url((0, _contribution.getContributionRouteName)(obj), (0, _contribution.getRouteData)(obj)),
        className: classes.snippetContent
      }, (0, _contribution.getContributionSnippet)(obj))), /*#__PURE__*/_react.default.createElement(_core.Link, {
        to: scRoutingContext.url((0, _contribution.getContributionRouteName)(obj), (0, _contribution.getRouteData)(obj)),
        className: classes.activityAt
      }, /*#__PURE__*/_react.default.createElement(_DateTimeAgo.default, {
        component: "span",
        date: obj.added_at
      }))),
      actions: /*#__PURE__*/_react.default.createElement(_material.Button, {
        component: _core.Link,
        to: scRoutingContext.url((0, _contribution.getContributionRouteName)(obj), (0, _contribution.getRouteData)(obj)),
        variant: "outlined"
      }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
        id: "ui.feedObject.comment",
        defaultMessage: "ui.feedObject.comment"
      }))
    }) : /*#__PURE__*/_react.default.createElement(_Skeleton.default, FeedObjectSkeletonProps));
  }
  /**
   * Renders root object
   */


  return /*#__PURE__*/_react.default.createElement(Root, _extends({
    id: id,
    className: (0, _classnames.default)(classes.root, className, `${PREFIX}-${template}`)
  }, rest), obj && markRead && /*#__PURE__*/_react.default.createElement(_MarkRead.default, {
    endpoint: _core.Endpoints.FeedObjectMarkRead,
    data: {
      object: [obj.id]
    }
  }), objElement);
}