"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const styles_1 = require("@mui/material/styles");
const material_1 = require("@mui/material");
const react_core_1 = require("@selfcommunity/react-core");
const react_intl_1 = require("react-intl");
const DateTimeAgo_1 = tslib_1.__importDefault(require("../../../../../shared/DateTimeAgo"));
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const system_1 = require("@mui/system");
const BaseItem_1 = tslib_1.__importDefault(require("../../../../../shared/BaseItem"));
const UserDeletedSnackBar_1 = tslib_1.__importDefault(require("../../../../../shared/UserDeletedSnackBar"));
const constants_1 = require("../../../constants");
const messages = (0, react_intl_1.defineMessages)({
    follow: {
        id: 'ui.feedObject.relevantActivities.follow',
        defaultMessage: 'ui.feedObject.relevantActivities.follow'
    }
});
const classes = {
    root: `${constants_1.PREFIX}-activity-follow-root`,
    avatar: `${constants_1.PREFIX}-activity-follow-avatar`,
    username: `${constants_1.PREFIX}-activity-follow-username`
};
const Root = (0, styles_1.styled)(BaseItem_1.default, {
    name: constants_1.PREFIX,
    slot: 'ActivityFollowRoot'
})(() => ({}));
function FollowRelevantActivity(inProps) {
    // PROPS
    const props = (0, system_1.useThemeProps)({
        props: inProps,
        name: constants_1.PREFIX
    });
    const { className = null, activityObject = null } = props, rest = tslib_1.__rest(props, ["className", "activityObject"]);
    // CONTEXT
    const scRoutingContext = (0, react_core_1.useSCRouting)();
    // STATE
    const [openAlert, setOpenAlert] = (0, react_1.useState)(false);
    // INTL
    const intl = (0, react_intl_1.useIntl)();
    // RENDER
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Root, Object.assign({}, rest, { className: (0, classnames_1.default)(classes.root, className), image: (0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({}, (!activityObject.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, activityObject.author) }), { onClick: activityObject.author.deleted ? () => setOpenAlert(true) : null }, { children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { alt: activityObject.author.username, variant: "circular", src: activityObject.author.avatar, className: classes.avatar }) })), primary: (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: intl.formatMessage(messages.follow, {
                        username: ((0, jsx_runtime_1.jsx)(react_core_1.Link, Object.assign({}, (!activityObject.author.deleted && { to: scRoutingContext.url(react_core_1.SCRoutes.USER_PROFILE_ROUTE_NAME, activityObject.author) }), { onClick: activityObject.author.deleted ? () => setOpenAlert(true) : null, className: classes.username }, { children: activityObject.author.username })))
                    }) }), secondary: (0, jsx_runtime_1.jsx)(DateTimeAgo_1.default, { date: activityObject.active_at }) })), openAlert && (0, jsx_runtime_1.jsx)(UserDeletedSnackBar_1.default, { open: openAlert, handleClose: () => setOpenAlert(false) })] }));
}
exports.default = FollowRelevantActivity;
