/**
 * Utilities for extracting copyable plain text from AgentMessages.
 * Used by the copy selector modal to present message content for clipboard copy.
 */
/**
 * Extract copyable plain text from any AgentMessage.
 * Returns the original source text without any terminal wrapping or ANSI codes.
 * Returns empty string for messages with no meaningful text content (e.g., image-only).
 */
export function extractCopyableText(message) {
    switch (message.role) {
        case "user":
            return extractUserText(message);
        case "assistant":
            return extractAssistantText(message);
        case "toolResult":
            return extractToolResultText(message);
        case "bashExecution":
            return extractBashText(message);
        case "branchSummary":
            return message.summary;
        case "compactionSummary":
            return message.summary;
        case "custom":
            return extractCustomText(message);
        default:
            return "";
    }
}
/**
 * Get a short label for a message's role (used in the copy selector UI).
 */
export function getMessageRoleLabel(message) {
    switch (message.role) {
        case "user":
            return "You";
        case "assistant":
            return "Assistant";
        case "toolResult":
            return `Tool: ${message.toolName}`;
        case "bashExecution":
            return "Bash";
        case "branchSummary":
            return "Branch";
        case "compactionSummary":
            return "Summary";
        case "custom":
            return `Custom: ${message.customType}`;
        default:
            return "Unknown";
    }
}
/**
 * Get a single-line preview of a message's content (for display in selector).
 * Returns plain text, no ANSI, truncated to ~200 chars. Caller handles width truncation.
 */
export function getMessagePreview(message) {
    const text = extractCopyableText(message);
    if (!text) {
        return "[no text content]";
    }
    // Normalize to single line: replace newlines with spaces, collapse whitespace
    const singleLine = text.replace(/\n/g, " ").replace(/\s+/g, " ").trim();
    if (singleLine.length <= 200) {
        return singleLine;
    }
    return singleLine.slice(0, 200);
}
// --- Internal helpers ---
function extractTextBlocks(content) {
    return content
        .filter((block) => block.type === "text")
        .map((block) => block.text)
        .join("\n");
}
function extractUserText(message) {
    if (typeof message.content === "string") {
        return message.content;
    }
    return extractTextBlocks(message.content);
}
function extractAssistantText(message) {
    const parts = [];
    // Collect text blocks
    const textParts = message.content
        .filter((block) => block.type === "text")
        .map((block) => block.text);
    if (textParts.length > 0) {
        parts.push(textParts.join("\n"));
    }
    // Collect thinking blocks with header
    for (const block of message.content) {
        if (block.type === "thinking" && "thinking" in block) {
            parts.push(`[thinking]\n${block.thinking}`);
        }
    }
    return parts.join("\n");
}
function extractToolResultText(message) {
    const textContent = extractTextBlocks(message.content);
    if (!textContent) {
        return "";
    }
    return `[${message.toolName}]\n${textContent}`;
}
function extractBashText(message) {
    return `$ ${message.command}\n${message.output}`;
}
function extractCustomText(message) {
    if (typeof message.content === "string") {
        return message.content;
    }
    if (Array.isArray(message.content)) {
        return extractTextBlocks(message.content);
    }
    return "";
}
//# sourceMappingURL=message-text.js.map