"use client" import { useEffect, useState } from "react" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" import { Label } from "@/components/ui/label" import { Database } from "lucide-react" import { getAvailableSources } from "@/lib/api" import type { DataSourceInfo } from "@/lib/types" interface DataSourceSelectorProps { market: string selectedSource: string onSourceChange: (source: string) => void disabled?: boolean showLabel?: boolean } export function DataSourceSelector({ market, selectedSource, onSourceChange, disabled = false, showLabel = true }: DataSourceSelectorProps) { const [sources, setSources] = useState([]) const [loading, setLoading] = useState(false) useEffect(() => { async function loadSources() { if (!market) return setLoading(true) try { const data = await getAvailableSources(market) setSources(data.sources.filter(s => s.available)) // 如果当前选中的源不可用,自动选择第一个可用的 const availableSources = data.sources.filter(s => s.available) if (availableSources.length > 0 && !availableSources.find(s => s.source === selectedSource)) { onSourceChange(availableSources[0].source) } } catch (error) { console.error("Failed to load data sources:", error) } finally { setLoading(false) } } loadSources() }, [market]) if (sources.length === 0) { return null } return (
{showLabel && (
)} { sources.length === 1 && (

该市场仅支持 {sources[0].source} 数据源

) }
) }