import { Pencil, RefreshCw } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { ChatMessageBookmark } from "./ChatMessageBookmark";

interface ChatMessageActionsProps {
  role: "user" | "assistant" | "system";
  isStreaming?: boolean;
  onEdit?: () => void;
  onRetry?: () => void;
  onBookmark?: () => void;
  isBookmarked?: boolean;
}

export function ChatMessageActions({ role, isStreaming, onEdit, onRetry, onBookmark, isBookmarked }: ChatMessageActionsProps) {
  if (isStreaming) return null;

  if (role === "user" && onEdit) {
    return (
      <div className="absolute top-1 right-1 hidden group-hover:flex items-center gap-0.5">
        <Tooltip>
          <TooltipTrigger asChild>
            <Button
              variant="ghost"
              size="icon"
              className="h-6 w-6"
              onClick={onEdit}
              aria-label="Edit message"
            >
              <Pencil className="h-3.5 w-3.5" />
            </Button>
          </TooltipTrigger>
          <TooltipContent>Edit message</TooltipContent>
        </Tooltip>
        {onBookmark && (
          <ChatMessageBookmark
            messageId=""
            conversationId=""
            isBookmarked={isBookmarked ?? false}
            onToggle={onBookmark}
          />
        )}
      </div>
    );
  }

  if (role === "assistant") {
    const hasActions = !!onRetry || !!onBookmark;
    if (!hasActions) return null;
    return (
      <div className="flex justify-end mt-1 gap-0.5">
        {onRetry && (
          <Tooltip>
            <TooltipTrigger asChild>
              <Button
                variant="ghost"
                size="icon"
                className="h-6 w-6 hidden group-hover:inline-flex"
                onClick={onRetry}
                aria-label="Retry response"
              >
                <RefreshCw className="h-3.5 w-3.5" />
              </Button>
            </TooltipTrigger>
            <TooltipContent>Retry response</TooltipContent>
          </Tooltip>
        )}
        {onBookmark && (
          <div className="hidden group-hover:inline-flex">
            <ChatMessageBookmark
              messageId=""
              conversationId=""
              isBookmarked={isBookmarked ?? false}
              onToggle={onBookmark}
            />
          </div>
        )}
      </div>
    );
  }

  return null;
}
