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 { PREFIX } from '../../../constants';
const messages = defineMessages({
    vote: {
        id: 'ui.feedObject.relevantActivities.vote',
        defaultMessage: 'ui.feedObject.relevantActivities.vote'
    }
});
const classes = {
    root: `${PREFIX}-activity-vote-up-root`,
    avatar: `${PREFIX}-activity-vote-up-avatar`,
    username: `${PREFIX}-activity-vote-up-username`
};
const Root = styled(BaseItem, {
    name: PREFIX,
    slot: 'ActivityVoteUpRoot'
})(() => ({}));
export default function VoteUpRelevantActivity(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
    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.vote, {
                        username: (_jsx(Link, Object.assign({}, (!activityObject.author.deleted && { to: scRoutingContext.url(SCRoutes.USER_PROFILE_ROUTE_NAME, activityObject.author) }), { className: classes.username, onClick: activityObject.author.deleted ? () => setOpenAlert(true) : null }, { children: activityObject.author.username })))
                    }) }), secondary: _jsx(DateTimeAgo, { date: activityObject.active_at }) })), openAlert && _jsx(UserDeletedSnackBar, { open: openAlert, handleClose: () => setOpenAlert(false) })] }));
}
