import { __rest } from "tslib";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { styled } from '@mui/material/styles';
import { Avatar } from '@mui/material';
import { Link, SCRoutes, useSCRouting } from '@selfcommunity/react-core';
import { defineMessages, useIntl } from 'react-intl';
import DateTimeAgo from '../../../../../shared/DateTimeAgo';
import classNames from 'classnames';
import BaseItem from '../../../../../shared/BaseItem';
import UserDeletedSnackBar from '../../../../../shared/UserDeletedSnackBar';
import { getRouteData } from '../../../../../utils/contribution';
import { PREFIX } from '../../../constants';
const messages = defineMessages({
    comment: {
        id: 'ui.feedObject.relevantActivities.comment',
        defaultMessage: 'ui.feedObject.relevantActivities.comment'
    }
});
const classes = {
    root: `${PREFIX}-activity-comment-root`,
    avatar: `${PREFIX}-activity-comment-avatar`,
    username: `${PREFIX}-activity-comment-username`,
    showMoreContent: `${PREFIX}-activity-comment-show-more-content`
};
const Root = styled(BaseItem, {
    name: PREFIX,
    slot: 'ActivityCommentRoot'
})(() => ({}));
export default function CommentRelevantActivity(props) {
    // PROPS
    const { className = null, activityObject = null } = props, rest = __rest(props, ["className", "activityObject"]);
    // CONTEXT
    const scRoutingContext = useSCRouting();
    // STATE
    const [openAlert, setOpenAlert] = useState(false);
    // INTL
    const intl = useIntl();
    // RENDER
    // const summaryHtmlTruncated =
    //   'summary_truncated' in activityObject.comment
    //     ? activityObject.comment.summary_truncated
    //     : activityObject.comment.html.length >= MAX_SUMMARY_LENGTH;
    // const commentHtml = 'summary_html' in activityObject.comment ? activityObject.comment.summary_html : activityObject.comment.summary;
    // const summaryHtml = getContributionHtml(commentHtml, scRoutingContext.url);
    return (_jsxs(_Fragment, { children: [_jsx(Root, Object.assign({}, rest, { className: classNames(classes.root, className), image: _jsx(Link, Object.assign({}, (!activityObject.author.deleted && { to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, activityObject.author) }), { onClick: activityObject.author.deleted ? () => setOpenAlert(true) : null }, { children: _jsx(Avatar, { alt: activityObject.author.username, variant: "circular", src: activityObject.author.avatar, className: classes.avatar }) })), primary: _jsx(_Fragment, { children: intl.formatMessage(messages.comment, {
                        username: (_jsx(Link, Object.assign({}, (!activityObject.author.deleted && { to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, activityObject.author) }), { onClick: activityObject.author.deleted ? () => setOpenAlert(true) : null, className: classes.username }, { children: activityObject.author.username }))),
                        link: (...chunks) => _jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes.COMMENT_ROUTE_NAME, getRouteData(activityObject.comment)) }, { children: chunks }))
                        // comment: (
                        //   <>
                        //     <Typography variant="body2" gutterBottom dangerouslySetInnerHTML={{__html: summaryHtml}} />
                        //     {summaryHtmlTruncated && (
                        //       <Link
                        //         to={scRoutingContext.url(SCRoutes.COMMENT_ROUTE_NAME, getRouteData(activityObject.comment))}
                        //         className={classes.showMoreContent}>
                        //         <FormattedMessage id="ui.commentObject.showMore" defaultMessage="ui.commentObject.showMore" />
                        //       </Link>
                        //     )}
                        //   </>
                        // )
                    }) }), secondary: _jsx(DateTimeAgo, { date: activityObject.active_at }) })), openAlert && _jsx(UserDeletedSnackBar, { open: openAlert, handleClose: () => setOpenAlert(false) })] }));
}
