"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const ufo_1 = require("ufo");
const components_1 = require("@react-email/components");
// @ts-ignore
const constant_1 = require("@abtnode/constant");
const copyright_1 = __importDefault(require("./copyright"));
const powered_by_1 = __importDefault(require("./powered-by"));
const style_1 = require("../_libs/style");
function PointDivider() {
    return (0, jsx_runtime_1.jsx)("span", { style: { color: '#757575', fontSize: '12px', fontWeight: 'bold' }, children: "\u00A0\u00B7\u00A0" });
}
function ContactUs({ signatureConfig, fontFamily }) {
    const linkStyle = Object.assign(Object.assign({}, (0, style_1.getLinkStyle)(fontFamily)), { color: '#898989', fontSize: '12px' });
    return ((0, jsx_runtime_1.jsxs)(components_1.Text, { style: (0, style_1.getFooterStyle)(fontFamily), children: [signatureConfig.companyName ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [signatureConfig.companyLink ? ((0, jsx_runtime_1.jsx)(components_1.Link, { href: signatureConfig.companyLink, target: "_blank", style: linkStyle, children: signatureConfig.companyName })) : (signatureConfig.companyName), (0, jsx_runtime_1.jsx)(PointDivider, {})] })) : null, signatureConfig.companyAddress ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [signatureConfig.companyAddress, (0, jsx_runtime_1.jsx)(PointDivider, {})] })) : null, signatureConfig.supportEmail ? ((0, jsx_runtime_1.jsx)(components_1.Link, { href: `mailto:${signatureConfig.supportEmail}`, style: linkStyle, children: signatureConfig.supportEmail })) : null] }));
}
function Footer({ showLogo = false, showCopyright = false, appInfo, locale = 'en', unsubscribeToken, userInfo, poweredBy, signatureConfig, fontFamily, }) {
    const linkStyle = Object.assign(Object.assign({}, (0, style_1.getLinkStyle)(fontFamily)), { color: '#898989', fontSize: '12px' });
    const footerStyle = (0, style_1.getFooterStyle)(fontFamily);
    const userInfoName = (userInfo === null || userInfo === void 0 ? void 0 : userInfo.fullName) || (userInfo === null || userInfo === void 0 ? void 0 : userInfo.email);
    const userInfoDescription = userInfo === null || userInfo === void 0 ? void 0 : userInfo.did;
    let userInfoContent = userInfoName;
    if (userInfoDescription) {
        userInfoContent += ` <${userInfoDescription}>`;
    }
    const showContactUs = (signatureConfig === null || signatureConfig === void 0 ? void 0 : signatureConfig.companyName) || (signatureConfig === null || signatureConfig === void 0 ? void 0 : signatureConfig.companyAddress) || (signatureConfig === null || signatureConfig === void 0 ? void 0 : signatureConfig.supportEmail);
    function UnsubscribeContent() {
        if (!userInfoContent) {
            return null;
        }
        // @note: Cannot use joinURL here because appInfo.url may contain query strings
        const unsubscribeTokenUrl = (0, ufo_1.resolveURL)(appInfo.url, constant_1.WELLKNOWN_SERVICE_PATH_PREFIX, `/user/unsubscribe?token=${unsubscribeToken}`);
        if (locale === 'zh') {
            return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["\u7531\u4E8E\u60A8\u662F", (0, jsx_runtime_1.jsx)(components_1.Link, { href: appInfo.url, target: "_blank", style: linkStyle, children: appInfo.title }), "\u7684\u8BA2\u9605\u8005\u6216\u7528\u6237\uFF0C\u6B64\u7535\u5B50\u90AE\u4EF6\u5DF2\u53D1\u9001\u5230", (userInfo === null || userInfo === void 0 ? void 0 : userInfo.email) ? ((0, jsx_runtime_1.jsx)(components_1.Link, { href: `mailto:${userInfo === null || userInfo === void 0 ? void 0 : userInfo.email}`, style: linkStyle, children: userInfo === null || userInfo === void 0 ? void 0 : userInfo.email })) : (userInfoContent), "\u3002", unsubscribeToken ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["\u5982\u679C\u60A8\u4E0D\u60F3\u518D\u6536\u5230\u6B64\u7C7B\u90AE\u4EF6\uFF0C\u60A8\u53EF\u4EE5", ' ', (0, jsx_runtime_1.jsx)(components_1.Link, { href: unsubscribeTokenUrl, style: linkStyle, target: "_blank", children: "\u9000\u8BA2" }), "\u3002"] })) : null] }));
        }
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["This email was sent to", ' ', (userInfo === null || userInfo === void 0 ? void 0 : userInfo.email) ? ((0, jsx_runtime_1.jsx)(components_1.Link, { href: `mailto:${userInfo === null || userInfo === void 0 ? void 0 : userInfo.email}`, style: linkStyle, children: userInfo === null || userInfo === void 0 ? void 0 : userInfo.email })) : (userInfoContent), ' ', "as you are a subscriber or a user of", ' ', (0, jsx_runtime_1.jsx)(components_1.Link, { href: appInfo.url, target: "_blank", style: linkStyle, children: appInfo.title }), ".", ' ', unsubscribeToken ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["If you'd rather not receive this kind of email, you can", ' ', (0, jsx_runtime_1.jsx)(components_1.Link, { href: unsubscribeTokenUrl, style: linkStyle, target: "_blank", children: "unsubscribe" }), "."] })) : null] }));
    }
    return ((0, jsx_runtime_1.jsxs)(components_1.Section, { children: [showLogo && (0, jsx_runtime_1.jsx)(components_1.Img, { src: appInfo.logo, width: "32", height: "32", alt: appInfo.title }), !showContactUs ? null : (0, jsx_runtime_1.jsx)(ContactUs, { signatureConfig: signatureConfig, fontFamily: fontFamily }), (0, jsx_runtime_1.jsx)(components_1.Text, { style: footerStyle, children: (0, jsx_runtime_1.jsx)(UnsubscribeContent, {}) }), poweredBy && (0, jsx_runtime_1.jsx)(powered_by_1.default, Object.assign({}, poweredBy, { fontFamily: fontFamily })), showCopyright && (0, jsx_runtime_1.jsx)(copyright_1.default, {})] }));
}
exports.default = Footer;
