'use client'; import { useEffect } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Check, Cpu, Monitor, Zap, Laptop } from "lucide-react"; import { GpuInfo } from "@/lib/recommendation"; import { useSettingsStore } from "@/store/settings-store"; import { cn } from "@/lib/utils"; interface GpuSelectorProps { gpus: GpuInfo[]; } export function GpuSelector({ gpus }: GpuSelectorProps) { const selectedGpu = useSettingsStore((state) => state.selectedGpu); const setSelectedGpu = useSettingsStore((state) => state.setSelectedGpu); // Se não há GPUs ou apenas uma, não mostrar seletor if (gpus.length === 0) { return null; } // Se há apenas uma GPU, selecionar automaticamente if (gpus.length === 1 && !selectedGpu) { setSelectedGpu(gpus[0].id); } // Selecionar primeira GPU por padrão se nenhuma estiver selecionada useEffect(() => { if (!selectedGpu && gpus.length > 0) { setSelectedGpu(gpus[0].id); } }, [selectedGpu, gpus, setSelectedGpu]); const getVendorIcon = (vendor: string | null) => { const iconClass = "h-5 w-5"; switch (vendor?.toUpperCase()) { case 'NVIDIA': return ; case 'AMD': return ; case 'INTEL': return ; case 'APPLE': return ; default: return ; } }; const formatMemory = (memoryMb: number | null) => { if (!memoryMb) return null; if (memoryMb >= 1024) { return `${(memoryMb / 1024).toFixed(1)} GB`; } return `${memoryMb} MB`; }; return ( Placas de Vídeo Detectadas Selecione qual GPU você deseja usar para processamento de IA {gpus.map((gpu) => { const isSelected = selectedGpu === gpu.id; const memoryStr = formatMemory(gpu.memory_mb); return ( setSelectedGpu(gpu.id)} className={cn( "relative p-4 rounded-lg border-2 transition-all text-left", "hover:border-primary/50 hover:bg-accent/50", isSelected ? "border-primary bg-primary/10 shadow-md" : "border-border bg-background" )} > {isSelected && ( )} {getVendorIcon(gpu.vendor)} {gpu.name} {gpu.vendor && ( {gpu.vendor} )} {memoryStr && ( {memoryStr} VRAM )} {!memoryStr && gpu.vendor && ( {gpu.vendor === 'Intel' ? 'GPU Integrada' : 'GPU Dedicada'} )} ); })} {gpus.length === 1 && ( Apenas uma GPU foi detectada e será usada automaticamente. )} ); }
Apenas uma GPU foi detectada e será usada automaticamente.