'use client'; import { useState, useMemo } from 'react'; import { Edit3, QrCode, Trash2, Coins, Search, LayoutGrid, List, Link as LinkIcon, Copy, Check, ToggleLeft, ToggleRight, Loader2, Plus, Layers, CreditCard } from 'lucide-react'; import { Provider } from '@/types'; import { getPaymentProviderIcon } from './paymentIcons'; interface ProviderListProps { providers: Provider[]; loading: boolean; onEdit: (provider: Provider) => void; onManageQr: (provider: Provider) => void; onDelete: (provider: Provider) => void; onToggleStatus?: (provider: Provider) => Promise; onCreateNew?: () => void; } function ProviderLogo({ name, icon, size = 'md' }: { name: string; icon?: string; size?: 'sm' | 'md' | 'lg' }) { const [failed, setFailed] = useState(false); const resolvedIcon = getPaymentProviderIcon(name, icon); const containerClasses = { sm: 'w-7 h-7 border border-black p-0.5', md: 'w-9 h-9 border-2 border-black p-1 shadow-[1px_1px_0px_#000]', lg: 'w-10 h-10 border-2 border-black p-1 shadow-[2px_2px_0px_#000]' }[size]; return (
{resolvedIcon && !failed ? ( {name} setFailed(true)} /> ) : (
{name ? name.slice(0, 2) : }
)}
); } export default function ProviderList({ providers, loading, onEdit, onManageQr, onDelete, onToggleStatus, onCreateNew }: ProviderListProps) { const [viewMode, setViewMode] = useState<'grid' | 'table'>('grid'); const [searchQuery, setSearchQuery] = useState(''); const [statusFilter, setStatusFilter] = useState<'all' | 'active' | 'disabled'>('all'); const [channelFilter, setChannelFilter] = useState<'all' | 'qr_static' | 'online_link'>('all'); const [copiedCode, setCopiedCode] = useState(null); const [togglingId, setTogglingId] = useState(null); const handleCopyCode = (code: string) => { navigator.clipboard.writeText(code); setCopiedCode(code); setTimeout(() => setCopiedCode(null), 2000); }; const handleToggle = async (provider: Provider) => { if (!onToggleStatus) return; setTogglingId(provider.id); try { await onToggleStatus(provider); } finally { setTogglingId(null); } }; const filteredProviders = useMemo(() => { return providers.filter(p => { const q = searchQuery.toLowerCase().trim(); const matchSearch = !q || p.name.toLowerCase().includes(q) || (p.title && p.title.toLowerCase().includes(q)) || (p.currency && p.currency.toLowerCase().includes(q)); const isEnabled = Boolean(p.enabled); const matchStatus = statusFilter === 'all' || (statusFilter === 'active' && isEnabled) || (statusFilter === 'disabled' && !isEnabled); const matchChannel = channelFilter === 'all' || p.channel === channelFilter; return matchSearch && matchStatus && matchChannel; }); }, [providers, searchQuery, statusFilter, channelFilter]); const renderChannelBadge = (channel: string) => { if (channel === 'qr_static') { return ( 静态收款码 ); } return ( 在线直连网关 ); }; const renderCurrencyBadge = (currency: string) => ( {currency || 'CNY'} ); return (
{/* 顶部工具栏 */}
{/* 搜索框 */}
setSearchQuery(e.target.value)} className="w-full pl-9 pr-8 py-2 text-xs bg-neutral-50 border-2 border-black focus:bg-white outline-none shadow-[2px_2px_0px_#000] text-black font-mono" /> {searchQuery && ( )}
{/* 筛选与视图切换 */}
{/* 内容区域 */} {loading ? (

[ FETCHING PAYMENT GATEWAYS... ]

) : filteredProviders.length === 0 ? (

[ NO GATEWAYS FOUND ]

未检索到匹配的支付渠道配置

) : viewMode === 'grid' ? (
{filteredProviders.map((p) => { const isEnabled = Boolean(p.enabled); const isToggling = togglingId === p.id; return (
{/* 卡片头部 */}

{p.title || p.name}

{p.name}
{renderChannelBadge(p.channel)} {renderCurrencyBadge(p.currency)}
{/* 卡片底部操作栏 */}
{p.channel === 'qr_static' ? ( ) : ( ONLINE GATEWAY )}
); })}
) : ( /* 表格视图 */
{filteredProviders.map((p) => { const isEnabled = Boolean(p.enabled); const isToggling = togglingId === p.id; return ( ); })}
[ 服务商 / 标识 ] [ 通道类型 ] [ 结算货币 ] [ 状态 ] [ 操作 ]
{p.title || p.name}
{p.name}
{renderChannelBadge(p.channel)} {renderCurrencyBadge(p.currency)}
{p.channel === 'qr_static' && ( )}
)}
); }