import React from "react"; import { useTranslation } from "react-i18next"; import { Zap } from "lucide-react"; import { ProviderCategory } from "../../types"; import { ClaudeIcon, CodexIcon } from "../BrandIcons"; interface Preset { name: string; isOfficial?: boolean; category?: ProviderCategory; } interface PresetSelectorProps { title?: string; presets: Preset[]; selectedIndex: number | null; onSelectPreset: (index: number) => void; onCustomClick: () => void; customLabel?: string; renderCustomDescription?: () => React.ReactNode; // 新增:自定义描述渲染 } const PresetSelector: React.FC = ({ title, presets, selectedIndex, onSelectPreset, onCustomClick, customLabel, renderCustomDescription, }) => { const { t } = useTranslation(); const getButtonClass = (index: number, preset?: Preset) => { const isSelected = selectedIndex === index; const baseClass = "inline-flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-colors"; if (isSelected) { if (preset?.isOfficial || preset?.category === "official") { // Codex 官方使用黑色背景 if (preset?.name.includes("Codex")) { return `${baseClass} bg-gray-900 text-white`; } // Claude 官方使用品牌色背景 return `${baseClass} bg-[#D97757] text-white`; } return `${baseClass} bg-blue-500 text-white`; } return `${baseClass} bg-gray-100 dark:bg-gray-800 text-gray-500 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-gray-700`; }; const getDescription = () => { if (selectedIndex === -1) { // 如果提供了自定义描述渲染函数,使用它 if (renderCustomDescription) { return renderCustomDescription(); } return t("presetSelector.customDescription"); } if (selectedIndex !== null && selectedIndex >= 0) { const preset = presets[selectedIndex]; return preset?.isOfficial || preset?.category === "official" ? t("presetSelector.officialDescription") : t("presetSelector.presetDescription"); } return null; }; return (
{presets.map((preset, index) => ( ))}
{getDescription() && (
{getDescription()}
)}
); }; export default PresetSelector;