import React from 'react';
import classnames from 'classnames';
import i18n from 'ui-i18n';
import { ErrorBoundary } from '../../../../../ErrorBoundary';
import { ActivitiesFactory } from '../../../ActivitiesFactory';
import { ActivityTitle } from '../../../ActivityTitle';
import { getActivityType, splitActivityByType } from '../../../utils/activities';
import { CLIENT_TYPES } from '../../constants';
import styles from './ActivityItem.module.css';
export var ActivityItem = function (_a) {
    var _b, _c;
    var item = _a.item;
    var type = getActivityType(item);
    var activities = splitActivityByType(item);
    var clientTypeName = CLIENT_TYPES[(_c = (_b = item.items) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.clientType];
    return (React.createElement("div", { className: styles.activityItem, "data-reltio-id": "activity-log-item" },
        React.createElement("div", { className: styles.activityIcon }, ActivitiesFactory.getIcon(type)),
        React.createElement("div", { className: styles.activityInfo },
            React.createElement("div", { className: styles.userContainer },
                React.createElement("span", { className: styles.activityUser }, item.user),
                clientTypeName ? (React.createElement("span", { className: classnames(styles.activityUser, styles.activityUserClient) },
                    "(",
                    i18n.text('via'),
                    " ",
                    clientTypeName,
                    " ",
                    i18n.text('agent'),
                    ")")) : null,
                React.createElement("span", { className: styles.date }, i18n.date(item.timestamp, 'LT'))),
            activities.map(function (activity, index) {
                var activityType = getActivityType(activity);
                return (React.createElement("div", { key: index, className: styles.activityEvent },
                    React.createElement(ErrorBoundary, { error: React.createElement(React.Fragment, null,
                            React.createElement(ActivityTitle, { type: activityType }),
                            i18n.text("Can't render activity")) }, ActivitiesFactory.getComponent({
                        type: activityType,
                        data: activity
                    }))));
            }))));
};
