"use client"

export type Purchase = { id: string; amount: number; time: string; item: string }

export default function PurchaseHistory({ items }: { items: Purchase[] }) {
  if (!items?.length) return <div className="text-sm text-muted-foreground">暂无购买记录</div>
  return (
    <div className="grid gap-2">
      {items.map((o) => (
        <div key={o.id} className="flex items-center justify-between rounded-lg border p-3 bg-white">
          <div className="min-w-0">
            <div className="text-sm font-medium truncate">{o.item}</div>
            <div className="text-xs text-muted-foreground">
              {new Date(o.time).toLocaleDateString("zh-CN")}
            </div>
          </div>
          <div className="text-sm font-semibold">¥{o.amount.toLocaleString("zh-CN")}</div>
        </div>
      ))}
    </div>
  )
}
