import { useState } from 'react'; interface OfferFormProps { listingId: string; askingPrice: number; currency?: string; onSubmit: (amount: number, message: string) => Promise; onCancel?: () => void; } export function OfferForm({ listingId, askingPrice, currency = 'USD', onSubmit, onCancel, }: OfferFormProps) { const [amount, setAmount] = useState(askingPrice.toString()); const [message, setMessage] = useState(''); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); const offerAmount = parseFloat(amount); if (isNaN(offerAmount) || offerAmount <= 0) { setError('Please enter a valid offer amount'); return; } setSubmitting(true); try { await onSubmit(offerAmount, message); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to submit offer'); } finally { setSubmitting(false); } }; const suggestedOffers = [ { label: 'Full Price', value: askingPrice }, { label: '10% Off', value: Math.round(askingPrice * 0.9 * 100) / 100 }, { label: '15% Off', value: Math.round(askingPrice * 0.85 * 100) / 100 }, ]; return (
{error && (
{error}
)} {/* Suggested Offers */}
{suggestedOffers.map((suggestion) => ( ))}
{/* Custom Amount */}
$ setAmount(e.target.value)} required min="0.01" step="0.01" className="w-full pl-8 pr-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-green-500 focus:border-transparent" />

Asking price: ${askingPrice.toFixed(2)}

{/* Message */}