"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const components_1 = require("@react-email/components");
// @ts-ignore
const util_1 = require("@abtnode/util/lib/notification-preview/util");
// @ts-ignore
const constant_1 = require("@abtnode/constant");
const ufo_1 = require("ufo");
const style_1 = require("../_libs/style");
function getActivityContent(activity, receiverDid) {
    const { type, target } = activity || {};
    const { type: targetType, author } = target || {};
    const descriptionFn = util_1.ACTIVITY_DESCRIPTIONS[type];
    const targetName = targetType === 'doc' ? 'document' : targetType;
    // email 这里不涉及相同 type 合并的情况，所以 count 固定为 1
    const isAuthor = !author || (receiverDid && author === receiverDid);
    return descriptionFn ? descriptionFn(targetName, 1, isAuthor) : null;
}
function Activity({ activity, actor, siteDomain = '', severity = 'normal', userInfo, }) {
    const content = getActivityContent(activity, (userInfo === null || userInfo === void 0 ? void 0 : userInfo.did) || '');
    const { target, meta } = activity || {};
    const { fullName = 'System', did } = actor || {};
    // 避免 siteDomain 中带有协议
    const profileLink = (0, ufo_1.withQuery)((0, ufo_1.joinURL)((0, ufo_1.withHttps)(siteDomain), constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, 'user'), { did });
    return ((0, jsx_runtime_1.jsxs)(components_1.Section, { children: [content ? ((0, jsx_runtime_1.jsxs)(components_1.Text, { className: "content", children: [did ? ((0, jsx_runtime_1.jsx)(components_1.Link, { href: profileLink, style: { display: 'inline' }, children: fullName })) : (fullName), ' ', content, ' ', (0, jsx_runtime_1.jsxs)(components_1.Link, { href: target.id, style: { display: 'inline' }, children: [target.name || target.desc, "."] })] })) : null, meta && meta.content ? ((0, jsx_runtime_1.jsx)(components_1.Section, { style: Object.assign(Object.assign({}, style_1.attachmentsStyle), { borderColor: style_1.severityColorMap[severity] || style_1.severityColorMap.normal }), children: (0, jsx_runtime_1.jsx)("a", { href: meta.id, target: "_blank", style: {
                        textDecoration: 'none',
                        color: 'initial',
                        display: 'block',
                    }, children: (0, jsx_runtime_1.jsx)(components_1.Text, { children: meta.content }) }) })) : null] }));
}
exports.default = Activity;
