import { useDraggable } from "@dnd-kit/core"; import { useQuery } from "@tanstack/react-query"; import { AlertTriangle } from "lucide-react"; import { useEffect, useRef } from "react"; import { ManaCost } from "@/components/ManaCost"; import { getPrimaryFace } from "@/lib/card-faces"; import type { DeckCard } from "@/lib/deck-types"; import type { Violation } from "@/lib/deck-validation"; import { getCardByIdQueryOptions } from "@/lib/queries"; import type { ScryfallId } from "@/lib/scryfall-types"; interface DraggableCardProps { card: DeckCard; uniqueId: string; onCardHover?: (cardId: ScryfallId | null) => void; onCardClick?: (card: DeckCard) => void; disabled?: boolean; isDraggingGlobal?: boolean; isHighlighted?: boolean; violations?: Violation[]; } export interface DragData { scryfallId: ScryfallId; section: string; tags: string[]; } export function DraggableCard({ card, uniqueId, onCardHover, onCardClick, disabled = false, isDraggingGlobal = false, isHighlighted = false, violations, }: DraggableCardProps) { const { data: cardData, isLoading } = useQuery( getCardByIdQueryOptions(card.scryfallId), ); const dragData: DragData = { scryfallId: card.scryfallId, section: card.section, tags: card.tags ?? [], }; const { attributes, listeners, setNodeRef, isDragging } = useDraggable({ id: uniqueId, data: dragData, disabled, }); const highlightRef = useRef(null); useEffect(() => { if (isHighlighted && highlightRef.current) { highlightRef.current.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 2000, easing: "ease-out", }); } }, [isHighlighted]); const primaryFace = cardData ? getPrimaryFace(cardData) : null; return ( ); }