"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActivityItem = void 0;
var react_1 = __importDefault(require("react"));
var classnames_1 = __importDefault(require("classnames"));
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var ErrorBoundary_1 = require("../../../../../ErrorBoundary");
var ActivitiesFactory_1 = require("../../../ActivitiesFactory");
var ActivityTitle_1 = require("../../../ActivityTitle");
var activities_1 = require("../../../utils/activities");
var constants_1 = require("../../constants");
var ActivityItem_module_css_1 = __importDefault(require("./ActivityItem.module.css"));
var ActivityItem = function (_a) {
    var _b, _c;
    var item = _a.item;
    var type = (0, activities_1.getActivityType)(item);
    var activities = (0, activities_1.splitActivityByType)(item);
    var clientTypeName = constants_1.CLIENT_TYPES[(_c = (_b = item.items) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.clientType];
    return (react_1.default.createElement("div", { className: ActivityItem_module_css_1.default.activityItem, "data-reltio-id": "activity-log-item" },
        react_1.default.createElement("div", { className: ActivityItem_module_css_1.default.activityIcon }, ActivitiesFactory_1.ActivitiesFactory.getIcon(type)),
        react_1.default.createElement("div", { className: ActivityItem_module_css_1.default.activityInfo },
            react_1.default.createElement("div", { className: ActivityItem_module_css_1.default.userContainer },
                react_1.default.createElement("span", { className: ActivityItem_module_css_1.default.activityUser }, item.user),
                clientTypeName ? (react_1.default.createElement("span", { className: (0, classnames_1.default)(ActivityItem_module_css_1.default.activityUser, ActivityItem_module_css_1.default.activityUserClient) },
                    "(",
                    ui_i18n_1.default.text('via'),
                    " ",
                    clientTypeName,
                    " ",
                    ui_i18n_1.default.text('agent'),
                    ")")) : null,
                react_1.default.createElement("span", { className: ActivityItem_module_css_1.default.date }, ui_i18n_1.default.date(item.timestamp, 'LT'))),
            activities.map(function (activity, index) {
                var activityType = (0, activities_1.getActivityType)(activity);
                return (react_1.default.createElement("div", { key: index, className: ActivityItem_module_css_1.default.activityEvent },
                    react_1.default.createElement(ErrorBoundary_1.ErrorBoundary, { error: react_1.default.createElement(react_1.default.Fragment, null,
                            react_1.default.createElement(ActivityTitle_1.ActivityTitle, { type: activityType }),
                            ui_i18n_1.default.text("Can't render activity")) }, ActivitiesFactory_1.ActivitiesFactory.getComponent({
                        type: activityType,
                        data: activity
                    }))));
            }))));
};
exports.ActivityItem = ActivityItem;
