/**
 * @bobfrankston/mailx-compose
 * Compose message logic — builds prefilled compose data for reply/forward.
 * UI lives in client/compose/; this package has the shared logic.
 */
/** Build compose init data from an original message and mode */
export function buildComposeInit(mode, accountId, original) {
    const init = {
        mode,
        accountId,
        to: [],
        cc: [],
        subject: "",
        bodyHtml: "",
        inReplyTo: "",
        references: [],
    };
    if (!original)
        return init;
    const rePrefix = /^(re|fwd?):\s*/i;
    const cleanSubject = original.subject.replace(rePrefix, "");
    switch (mode) {
        case "reply":
            init.to = [original.from];
            init.subject = `Re: ${cleanSubject}`;
            init.bodyHtml = quoteBody(original);
            init.inReplyTo = original.messageId;
            init.references = [...original.references, original.messageId];
            break;
        case "replyAll":
            init.to = [original.from, ...original.to.filter(a => a.address !== original.from.address)];
            init.cc = original.cc || [];
            init.subject = `Re: ${cleanSubject}`;
            init.bodyHtml = quoteBody(original);
            init.inReplyTo = original.messageId;
            init.references = [...original.references, original.messageId];
            break;
        case "forward":
            init.subject = `Fwd: ${cleanSubject}`;
            init.bodyHtml = forwardBody(original);
            break;
    }
    return init;
}
function quoteBody(msg) {
    const date = new Date(msg.date).toLocaleString();
    const from = msg.from.name ? `${msg.from.name} <${msg.from.address}>` : msg.from.address;
    const body = msg.bodyHtml || `<pre>${escapeHtml(msg.bodyText)}</pre>`;
    return `<br><div class="reply"><p>On ${date}, ${escapeHtml(from)} wrote:</p><blockquote>${body}</blockquote></div>`;
}
function forwardBody(msg) {
    const date = new Date(msg.date).toLocaleString();
    const from = msg.from.name ? `${msg.from.name} <${msg.from.address}>` : msg.from.address;
    const to = msg.to.map(a => a.name ? `${a.name} <${a.address}>` : a.address).join(", ");
    const body = msg.bodyHtml || `<pre>${escapeHtml(msg.bodyText)}</pre>`;
    return `<br><div class="reply"><p>---------- Forwarded message ----------<br>From: ${escapeHtml(from)}<br>Date: ${date}<br>Subject: ${escapeHtml(msg.subject)}<br>To: ${escapeHtml(to)}</p>${body}</div>`;
}
function escapeHtml(s) {
    return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
//# sourceMappingURL=index.js.map