import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Button } from "@/components/ui/button";
import { MoreHorizontal } from "lucide-react";

interface AgentActionsProps {
  agentId: string;
  status: string;
  isDismissed: boolean;
  onStop: (id: string) => void;
  onDelete: (id: string) => void;
  onDismiss: (id: string) => void;
  onGoToInbox: () => void;
}

export function AgentActions({
  agentId,
  status,
  isDismissed,
  onStop,
  onDelete,
  onDismiss,
  onGoToInbox,
}: AgentActionsProps) {
  return (
    <DropdownMenu>
      <DropdownMenuTrigger asChild>
        <Button variant="ghost" size="icon" className="h-6 w-6">
          <MoreHorizontal className="h-3.5 w-3.5" />
          <span className="sr-only">Agent actions</span>
        </Button>
      </DropdownMenuTrigger>
      <DropdownMenuContent align="end">
        {status === "waiting_for_input" && (
          <>
            <DropdownMenuItem onClick={onGoToInbox}>
              Go to Inbox
            </DropdownMenuItem>
            <DropdownMenuSeparator />
          </>
        )}
        {(status === "running" || status === "waiting_for_input") && (
          <DropdownMenuItem onClick={() => onStop(agentId)}>
            Stop
          </DropdownMenuItem>
        )}
        {!isDismissed &&
          ["stopped", "crashed", "idle"].includes(status) && (
            <DropdownMenuItem onClick={() => onDismiss(agentId)}>
              Dismiss
            </DropdownMenuItem>
          )}
        {(isDismissed ||
          ["stopped", "crashed", "idle"].includes(status)) && (
          <>
            <DropdownMenuSeparator />
            <DropdownMenuItem
              className="text-destructive"
              onClick={() => onDelete(agentId)}
            >
              Delete
            </DropdownMenuItem>
          </>
        )}
      </DropdownMenuContent>
    </DropdownMenu>
  );
}
