'use client'; import { useState, useEffect } from 'react'; import type { Locale } from '@/lib/locale'; interface RefundDialogProps { orderId: string; amount: number; onConfirm: (reason: string, force: boolean) => Promise; onCancel: () => void; warning?: string; requireForce?: boolean; dark?: boolean; locale?: Locale; } export default function RefundDialog({ orderId, amount, onConfirm, onCancel, warning, requireForce, dark = false, locale = 'zh', }: RefundDialogProps) { const [reason, setReason] = useState(''); const [force, setForce] = useState(false); const [loading, setLoading] = useState(false); const currency = locale === 'en' ? '$' : '¥'; const text = locale === 'en' ? { title: 'Confirm Refund', orderId: 'Order ID', amount: 'Refund Amount', reason: 'Refund Reason', reasonPlaceholder: 'Enter refund reason (optional)', forceRefund: 'Force refund (balance may become negative)', cancel: 'Cancel', confirm: 'Confirm Refund', processing: 'Processing...', } : { title: '确认退款', orderId: '订单号', amount: '退款金额', reason: '退款原因', reasonPlaceholder: '请输入退款原因(可选)', forceRefund: '强制退款(余额可能扣为负数)', cancel: '取消', confirm: '确认退款', processing: '处理中...', }; useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') onCancel(); }; document.addEventListener('keydown', handleKeyDown); return () => document.removeEventListener('keydown', handleKeyDown); }, [onCancel]); const handleConfirm = async () => { setLoading(true); try { await onConfirm(reason, force); } finally { setLoading(false); } }; return (
e.stopPropagation()} >

{text.title}

{text.orderId}
{orderId}
{text.amount}
{currency} {amount.toFixed(2)}
{warning && (
{warning}
)}
setReason(e.target.value)} placeholder={text.reasonPlaceholder} className={[ 'w-full rounded-lg border px-3 py-2 text-sm focus:border-blue-500 focus:outline-none', dark ? 'border-slate-600 bg-slate-800 text-slate-100' : 'border-gray-300 bg-white text-gray-900', ].join(' ')} />
{requireForce && ( )}
); }