'use client'; import React, { useState } from 'react'; import { Label } from '@/components/ui/label'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { CheckCircle2, Zap, RotateCcw, AlertCircle, Info, Loader2 } from 'lucide-react'; import { cn } from '@/lib/utils'; import { ModelInfo } from '@/lib/api'; import { ModelSelectionIndicator, AutoSelectionStatus } from './model-selection-indicator'; interface EnhancedModelSelectProps { modelType: string; label: string; description?: string; value: string | null; availableModels: ModelInfo[]; isAutoSelected: boolean; isUserOverride: boolean; isLoading?: boolean; onValueChange: (value: string) => void; onSetUserOverride: (value: string) => void; onClearOverride: () => void; onRevertToAuto?: () => void; placeholder?: string; className?: string; disabled?: boolean; } export function EnhancedModelSelect({ modelType, label, description, value, availableModels, isAutoSelected, isUserOverride, isLoading = false, onValueChange, onSetUserOverride, onClearOverride, onRevertToAuto, placeholder = "Select a model...", className, disabled = false, }: EnhancedModelSelectProps) { const [isOpen, setIsOpen] = useState(false); const selectedModel = value ? availableModels.find(m => m.name === value) : null; const isLoaded = selectedModel?.loaded || false; const handleValueChange = (newValue: string) => { if (newValue !== value) { onValueChange(newValue); onSetUserOverride(newValue); } }; const handleClearOverride = () => { onClearOverride(); }; const handleRevertToAuto = () => { if (onRevertToAuto) { onRevertToAuto(); } }; const getModelIcon = (type: string) => { switch (type.toLowerCase()) { case 'vae': return ; case 'checkpoint': case 'stable-diffusion': return ; default: return ; } }; const getModelStatusColor = (model: ModelInfo) => { if (model.loaded) { return 'text-green-600 dark:text-green-400'; } return 'text-muted-foreground'; }; return (
{description && (

{description}

)}
{/* Auto-selection indicator */} {isAutoSelected && !isUserOverride && (
)} {/* User override indicator */} {isUserOverride && (
)}
{/* Model info display */} {selectedModel && (
Type: {selectedModel.type}
{selectedModel.file_size_mb && (
Size: {selectedModel.file_size_mb.toFixed(1)} MB
)}
{selectedModel.architecture && (
Architecture: {selectedModel.architecture}
)}
)} {/* No models warning */} {availableModels.length === 0 && !isLoading && (

No {modelType} models found. Please add {modelType} models to your models directory.

)}
); } interface EnhancedModelSelectGroupProps { title: string; description?: string; children: React.ReactNode; isLoading?: boolean; className?: string; } export function EnhancedModelSelectGroup({ title, description, children, isLoading = false, className, }: EnhancedModelSelectGroupProps) { return (

{title}

{description && (

{description}

)}
{isLoading ? (
Loading models...
) : (
{children}
)}
); }