"use client"; import { useState, useRef, useEffect } from "react"; import { Button } from "@kandev/ui/button"; import { Textarea } from "@kandev/ui/textarea"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@kandev/ui/tooltip"; import { IconPlayerPlay, IconSend, IconX } from "@tabler/icons-react"; import { useTranslation } from "react-i18next"; interface CommentFormProps { initialContent?: string; onSubmit: (content: string) => void; onCancel?: () => void; onSubmitAndRun?: (content: string) => void; isEditing?: boolean; autoFocus?: boolean; } function ActionButtons({ disabled, modKey, isEditing, showRunButton, onCancel, onSubmit, onSubmitAndRun, }: { disabled: boolean; modKey: string; isEditing: boolean; showRunButton: boolean; onCancel?: () => void; onSubmit: () => void; onSubmitAndRun?: () => void; }) { const { t } = useTranslation(); return (
{onCancel && ( )}

{t("diff:saveCommentForReview", { modKey })}

{showRunButton && onSubmitAndRun && (

{t("diff:saveAndSendToAgent", { modKey })}

)}
); } export function CommentForm({ initialContent = "", onSubmit, onCancel, onSubmitAndRun, isEditing = false, autoFocus = true, }: CommentFormProps) { const { t } = useTranslation(); const [content, setContent] = useState(initialContent); const textareaRef = useRef(null); useEffect(() => { if (autoFocus && textareaRef.current) textareaRef.current.focus(); }, [autoFocus]); const handleSubmit = () => { const trimmed = content.trim(); if (trimmed) { onSubmit(trimmed); setContent(""); } }; const handleSubmitAndRun = () => { const trimmed = content.trim(); if (trimmed && onSubmitAndRun) { onSubmitAndRun(trimmed); setContent(""); } }; const isMac = typeof navigator !== "undefined" && navigator.platform?.includes("Mac"); const modKey = isMac ? "⌘" : "Ctrl"; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); if (e.shiftKey && onSubmitAndRun) handleSubmitAndRun(); else handleSubmit(); } else if (e.key === "Escape" && onCancel) { e.preventDefault(); onCancel(); } }; const disabled = !content.trim(); const showRunButton = !!onSubmitAndRun && !isEditing; return (