'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState, useCallback } from 'react';
import { Copy, Check, Trash } from '@phosphor-icons/react';
import { cn } from '@/lib/utils';
import { MarkdownRenderer } from '../../shared/markdown-renderer';
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
import { ToolCallDisplay } from './tool-call-display';
export function AssistantMessage({ content, messageId, toolInvocations, isStreaming, onDeleteMessage, onNavigate, onNavigateToDocPage, onOpenFile }) {
    return /*#__PURE__*/ _jsxs("div", {
        className: cn("aui-assistant-message-root", "fade-in slide-in-from-bottom-1 animate-in duration-150", "relative mx-auto w-full max-w-[var(--thread-max-width)] py-3"),
        "data-role": "assistant",
        children: [
            content && /*#__PURE__*/ _jsx("div", {
                className: "aui-assistant-message-content wrap-break-word px-2 text-foreground leading-relaxed",
                children: /*#__PURE__*/ _jsx("div", {
                    className: "prose prose-sm dark:prose-invert max-w-none",
                    children: /*#__PURE__*/ _jsx(MarkdownRenderer, {
                        content: content
                    })
                })
            }),
            toolInvocations && toolInvocations.length > 0 && /*#__PURE__*/ _jsx("div", {
                className: "mt-2 px-2 space-y-1",
                children: toolInvocations.map((tool)=>/*#__PURE__*/ _jsx(ToolCallDisplay, {
                        tool: tool,
                        onNavigate: onNavigate,
                        onNavigateToDocPage: onNavigateToDocPage,
                        onOpenFile: onOpenFile
                    }, tool.toolCallId))
            }),
            !isStreaming && /*#__PURE__*/ _jsx("div", {
                className: "aui-assistant-message-footer mt-1 px-2 flex justify-end",
                children: /*#__PURE__*/ _jsx(AssistantActionBar, {
                    content: content,
                    messageId: messageId,
                    onDeleteMessage: onDeleteMessage
                })
            })
        ]
    });
}
function AssistantActionBar({ content, messageId, onDeleteMessage }) {
    const [copied, setCopied] = useState(false);
    const handleCopy = useCallback(async ()=>{
        try {
            await navigator.clipboard.writeText(content);
            setCopied(true);
            setTimeout(()=>setCopied(false), 2000);
        } catch (err) {
            console.error('Failed to copy:', err);
        }
    }, [
        content
    ]);
    const handleDelete = useCallback(()=>{
        if (messageId && onDeleteMessage) {
            onDeleteMessage(messageId);
        }
    }, [
        messageId,
        onDeleteMessage
    ]);
    return /*#__PURE__*/ _jsxs("div", {
        className: cn("aui-assistant-action-bar-root", "flex gap-1 text-muted-foreground"),
        children: [
            /*#__PURE__*/ _jsxs(Tooltip, {
                children: [
                    /*#__PURE__*/ _jsx(TooltipTrigger, {
                        asChild: true,
                        children: /*#__PURE__*/ _jsx("button", {
                            onClick: handleCopy,
                            className: "aui-button-icon size-6 p-1 rounded hover:bg-accent hover:text-foreground transition-colors",
                            "aria-label": copied ? "Copied" : "Copy",
                            children: copied ? /*#__PURE__*/ _jsx(Check, {
                                className: "size-4",
                                weight: "bold"
                            }) : /*#__PURE__*/ _jsx(Copy, {
                                className: "size-4"
                            })
                        })
                    }),
                    /*#__PURE__*/ _jsx(TooltipContent, {
                        children: copied ? "Copied!" : "Copy"
                    })
                ]
            }),
            messageId && onDeleteMessage && /*#__PURE__*/ _jsxs(Tooltip, {
                children: [
                    /*#__PURE__*/ _jsx(TooltipTrigger, {
                        asChild: true,
                        children: /*#__PURE__*/ _jsx("button", {
                            onClick: handleDelete,
                            className: "aui-button-icon size-6 p-1 rounded hover:bg-accent hover:text-foreground transition-colors",
                            "aria-label": "Delete message",
                            children: /*#__PURE__*/ _jsx(Trash, {
                                className: "size-4"
                            })
                        })
                    }),
                    /*#__PURE__*/ _jsx(TooltipContent, {
                        children: "Delete message"
                    })
                ]
            })
        ]
    });
}
