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({
    pollVote: {
        id: 'ui.feedObject.relevantActivities.pollVote',
        defaultMessage: 'ui.feedObject.relevantActivities.pollVote'
    }
});
const classes = {
    root: `${PREFIX}-activity-poll-vote-root`,
    avatar: `${PREFIX}-activity-poll-vote-avatar`,
    username: `${PREFIX}-activity-poll-vote-username`
};
const Root = styled(BaseItem, {
    name: PREFIX,
    slot: 'ActivityPollVoteRoot'
})(() => ({}));
export default function PollVoteRelevantActivity(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.pollVote, {
                        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 })))
                    }) }), secondary: _jsx(DateTimeAgo, { date: activityObject.active_at }) })), openAlert && _jsx(UserDeletedSnackBar, { open: openAlert, handleClose: () => setOpenAlert(false) })] }));
}
