import { __rest } from "tslib";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { styled } from '@mui/material/styles';
import { Avatar, Box, Stack, Typography } from '@mui/material';
import Icon from '@mui/material/Icon';
import { camelCase } from '@selfcommunity/utils';
import { Link, useSCRouting, SCRoutes } from '@selfcommunity/react-core';
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
import { getContributionType, getContributionSnippet, getRouteData } from '../../../utils/contribution';
import DateTimeAgo from '../../../shared/DateTimeAgo';
import classNames from 'classnames';
import { SCNotificationObjectTemplateType } from '../../../types';
import NotificationItem from '../../../shared/NotificationItem';
import { PREFIX } from '../constants';
const messages = defineMessages({
    youWrote: {
        id: 'ui.notification.kindlyNoticeFor.youWrote',
        defaultMessage: 'ui.notification.kindlyNoticeFor.youWrote'
    },
    kindlyNoticeAdvertising: {
        id: 'ui.notification.kindlyNoticeFor.kindlyNoticeAdvertising',
        defaultMessage: 'ui.notification.kindlyNoticeFor.kindlyNoticeAdvertising'
    },
    kindlyNoticeAggressive: {
        id: 'ui.notification.kindlyNoticeFor.kindlyNoticeAggressive',
        defaultMessage: 'ui.notification.kindlyNoticeFor.kindlyNoticeAggressive'
    },
    kindlyNoticeVulgar: {
        id: 'ui.notification.kindlyNoticeFor.kindlyNoticeVulgar',
        defaultMessage: 'ui.notification.kindlyNoticeFor.kindlyNoticeVulgar'
    },
    kindlyNoticePoor: {
        id: 'ui.notification.kindlyNoticeFor.kindlyNoticePoor',
        defaultMessage: 'ui.notification.kindlyNoticeFor.kindlyNoticePoor'
    },
    kindlyNoticeOfftopic: {
        id: 'ui.notification.kindlyNoticeFor.kindlyNoticeOfftopic',
        defaultMessage: 'ui.notification.kindlyNoticeFor.kindlyNoticeOfftopic'
    }
});
const classes = {
    root: `${PREFIX}-kindly-notice-for-root`,
    flagIcon: `${PREFIX}-flag-icon`,
    flagText: `${PREFIX}-flag-text`,
    activeAt: `${PREFIX}-active-at`,
    contributionWrap: `${PREFIX}-contribution-wrap`,
    contributionYouWroteLabel: `${PREFIX}-contribution-you-wrote-label`,
    contributionText: `${PREFIX}-contribution-text`
};
const Root = styled(NotificationItem, {
    name: PREFIX,
    slot: 'KindlyNoticeForRoot'
})(() => ({}));
/**
 * This component render the content of the notification of type kindly notice for
 * @constructor
 * @param props
 */
export default function KindlyNoticeForNotification(props) {
    // PROPS
    const { notificationObject, id = `n_${props.notificationObject['sid']}`, className, template = SCNotificationObjectTemplateType.DETAIL } = props, rest = __rest(props, ["notificationObject", "id", "className", "template"]);
    // ROUTING
    const scRoutingContext = useSCRouting();
    // CONST
    const isSnippetTemplate = template === SCNotificationObjectTemplateType.SNIPPET;
    const contributionType = getContributionType(notificationObject);
    //INTL
    const intl = useIntl();
    /**
     * Renders root object
     */
    return (_jsx(Root, Object.assign({ id: id, className: classNames(classes.root, className, `${PREFIX}-${template}`), template: template, isNew: notificationObject.is_new, disableTypography: true, image: _jsx(Avatar, Object.assign({ variant: "circular", classes: { root: classes.flagIcon } }, { children: _jsx(Icon, { children: "outlined_flag" }) })), primary: _jsx(_Fragment, { children: isSnippetTemplate ? (_jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes[`${contributionType.toUpperCase()}_ROUTE_NAME`], getRouteData(notificationObject[contributionType])) }, { children: _jsx(Typography, Object.assign({ component: "div", color: "inherit", className: classes.flagText }, { children: _jsx(FormattedMessage, { id: `ui.notification.kindlyNoticeFor.${camelCase(notificationObject.type)}Snippet`, defaultMessage: `ui.notification.kindlyNoticeFor.${camelCase(notificationObject.type)}Snippet` }) })) }))) : (_jsx(Typography, Object.assign({ component: "div", color: "inherit", className: classes.flagText }, { children: intl.formatMessage(messages[camelCase(notificationObject.type)], { b: (...chunks) => _jsx("strong", { children: chunks }) }) }))) }), secondary: (template === SCNotificationObjectTemplateType.DETAIL || template === SCNotificationObjectTemplateType.SNIPPET) && (_jsx(DateTimeAgo, { date: notificationObject.active_at, className: classes.activeAt })), footer: isSnippetTemplate ? null : (_jsxs(_Fragment, { children: [_jsxs(Box, Object.assign({ className: classes.contributionWrap }, { children: [_jsx(Typography, Object.assign({ variant: 'body2', color: 'inherit', component: 'div', classes: { root: classes.contributionYouWroteLabel } }, { children: intl.formatMessage(messages.youWrote, {
                                b: (...chunks) => _jsx("strong", { children: chunks })
                            }) })), _jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes[`${contributionType.toUpperCase()}_ROUTE_NAME`], getRouteData(notificationObject[contributionType])), className: classes.contributionText }, { children: _jsx(Typography, Object.assign({ component: 'span', variant: "body2" }, { children: getContributionSnippet(notificationObject[contributionType]) })) }))] })), template === SCNotificationObjectTemplateType.TOAST && (_jsxs(Stack, Object.assign({ direction: "row", justifyContent: "space-between", alignItems: "center", spacing: 2 }, { children: [_jsx(DateTimeAgo, { date: notificationObject.active_at }), _jsx(Typography, Object.assign({ color: "primary", component: 'div' }, { children: _jsx(Link, Object.assign({ to: scRoutingContext.url(SCRoutes[`${notificationObject[contributionType]['type'].toUpperCase()}_ROUTE_NAME`], getRouteData(notificationObject[contributionType])) }, { children: _jsx(FormattedMessage, { id: "ui.userToastNotifications.viewContribution", defaultMessage: 'ui.userToastNotifications.viewContribution' }) })) }))] })))] })) }, rest)));
}
