"use client"; import { useRef, useState, useCallback } from "react"; import { IconEdit, IconTrash, IconGripHorizontal } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { cn } from "@/lib/utils"; import type { DiffComment } from "@/lib/diff/types"; import { CommentForm } from "@/components/diff/comment-form"; import { useDraggablePopover, usePopoverDismiss } from "@/components/task/use-draggable-popover"; type CommentViewPopoverProps = { comments: DiffComment[]; position: { x: number; y: number }; onDelete: (commentId: string) => void; onUpdate?: (commentId: string, text: string) => void; onClose: () => void; }; function formatLineRange(start: number, end: number) { return start === end ? `L${start}` : `L${start}-${end}`; } function CommentItem({ comment, onDelete, onUpdate, isEditing, onStartEdit, onCancelEdit, }: { comment: DiffComment; onDelete: (id: string) => void; onUpdate?: (id: string, text: string) => void; isEditing: boolean; onStartEdit: (id: string) => void; onCancelEdit: () => void; }) { const handleUpdate = useCallback( (text: string) => { onUpdate?.(comment.id, text); onCancelEdit(); }, [comment.id, onCancelEdit, onUpdate], ); return (
{formatLineRange(comment.startLine, comment.endLine)}
{onUpdate && !isEditing && ( )}
{isEditing ? ( ) : ( <> {comment.codeContent && (
              {comment.codeContent}
            
)}

{comment.text}

)}
); } export function CommentViewPopover({ comments, position, onDelete, onUpdate, onClose, }: CommentViewPopoverProps) { const popoverRef = useRef(null); const [editingCommentId, setEditingCommentId] = useState(null); const { pos, onDragStart } = useDraggablePopover(position, 350, 200); usePopoverDismiss(onClose, popoverRef); return (
{comments.length} comment{comments.length !== 1 ? "s" : ""}
{comments.map((comment) => ( setEditingCommentId(null)} /> ))}
); }