"use client"; import { useState, useCallback, useRef, useEffect } from "react"; import { IconPlus, IconGripHorizontal, IconPlayerPlay } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { Textarea } from "@kandev/ui/textarea"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@kandev/ui/tooltip"; import { cn } from "@/lib/utils"; import { useDraggablePopover, usePopoverDismiss } from "@/components/task/use-draggable-popover"; type EditorCommentPopoverProps = { selectedText: string; lineRange: { start: number; end: number }; position: { x: number; y: number }; onSubmit: (comment: string) => void; onSubmitAndRun?: (comment: string) => void; onClose: () => void; }; function getPopoverWidth() { if (typeof window === "undefined") return 384; return Math.min(384, Math.max(280, window.innerWidth - 32)); } function PopoverBody({ selectedText, comment, setComment, handleSubmit, handleSubmitAndRun, textareaRef, }: { selectedText: string; comment: string; setComment: (v: string) => void; handleSubmit: () => void; handleSubmitAndRun?: () => void; textareaRef: React.RefObject; }) { const previewText = selectedText.length > 100 ? selectedText.slice(0, 100).trim() + "…" : selectedText; const isDisabled = !comment.trim(); const isMac = typeof navigator !== "undefined" && navigator.platform?.includes("Mac"); const modKey = isMac ? "\u2318" : "Ctrl"; const handleKeyDown = useCallback( (e: React.KeyboardEvent) => { if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); if (e.shiftKey && handleSubmitAndRun) { handleSubmitAndRun(); } else { handleSubmit(); } } }, [handleSubmit, handleSubmitAndRun], ); return (
        {previewText}