import { useEffect, useState } from "react"; import { useSortable } from "@dnd-kit/sortable"; import { CSS } from "@dnd-kit/utilities"; import { downloadIconCache } from "@/services/cmds"; import { convertFileSrc } from "@tauri-apps/api/core"; import { cn } from "@root/lib/utils"; // Новые импорты import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { GripVertical, Trash2, Undo2 } from "lucide-react"; interface Props { type: "prepend" | "original" | "delete" | "append"; group: IProxyGroupConfig; onDelete: () => void; } // Определяем стили для каждого типа элемента const typeStyles = { original: "bg-secondary/50", delete: "bg-destructive/20 text-muted-foreground line-through", prepend: "bg-green-500/20", append: "bg-green-500/20", }; export const GroupItem = (props: Props) => { const { type, group, onDelete } = props; // Drag-and-drop будет работать только для 'prepend' и 'append' типов const isSortable = type === "prepend" || type === "append"; const { attributes, listeners, setNodeRef, transform, transition, isDragging, } = useSortable({ id: group.name, disabled: !isSortable }); const [iconCachePath, setIconCachePath] = useState(""); const getFileName = (url: string) => url.substring(url.lastIndexOf("/") + 1); async function initIconCachePath() { if (group.icon && group.icon.trim().startsWith("http")) { const fileName = group.name.replaceAll(" ", "") + "-" + getFileName(group.icon); const iconPath = await downloadIconCache(group.icon, fileName); setIconCachePath(convertFileSrc(iconPath)); } } useEffect(() => { initIconCachePath(); }, [group.icon, group.name]); const style = { transform: CSS.Transform.toString(transform), transition, zIndex: isDragging ? 100 : undefined, }; return (
{/* Ручка для перетаскивания */}
{/* Иконка группы */} {group.icon && ( {group.name} )} {/* Название и тип группы */}

{group.name}

{group.type}
{/* Кнопка действия */}
); };