import { DndContext, closestCenter, useSensor, useSensors, PointerSensor, KeyboardSensor, } from '@dnd-kit/core' import { SortableContext, verticalListSortingStrategy, arrayMove, useSortable, } from '@dnd-kit/sortable' import { CSS } from '@dnd-kit/utilities' import { IconDots, IconStarFilled, IconTrash, IconEdit, IconStar, } from '@tabler/icons-react' import { useThreads } from '@/hooks/useThreads' import { cn } from '@/lib/utils' import { route } from '@/constants/routes' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { useTranslation } from 'react-i18next' import { DialogClose, DialogFooter, DialogHeader } from '@/components/ui/dialog' import { Dialog, DialogTrigger, DialogContent, DialogTitle, DialogDescription, } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { memo, useMemo, useState } from 'react' import { useNavigate, useMatches } from '@tanstack/react-router' import { toast } from 'sonner' import { Input } from '@/components/ui/input' const SortableItem = memo(({ thread }: { thread: Thread }) => { const { attributes, listeners, setNodeRef, transform, transition, isDragging, } = useSortable({ id: thread.id }) const style = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.5 : 1, } const { toggleFavorite, deleteThread, renameThread } = useThreads() const { t } = useTranslation() const [openDropdown, setOpenDropdown] = useState(false) const navigate = useNavigate() // Check if current route matches this thread's detail page const matches = useMatches() const isActive = matches.some( (match) => match.routeId === '/threads/$threadId' && 'threadId' in match.params && match.params.threadId === thread.id ) const handleClick = () => { if (!isDragging) { navigate({ to: route.threadsDetail, params: { threadId: thread.id } }) } } const [title, setTitle] = useState(thread.title || 'New Thread') return (