import React from "react";
import { formatNumber } from "@/lib/debt-intelligence-utils";

interface CurrencyBreakdownTableProps {
  title: string;
  data: Record<string, number>;
  bgColor: string;
  textColor: string;
  emptyMessage: string;
}

export const CurrencyBreakdownTable: React.FC<CurrencyBreakdownTableProps> = ({
  title,
  data,
  bgColor,
  textColor,
  emptyMessage,
}) => {
  return (
    <div className="rounded-lg border border-border bg-card shadow-sm overflow-hidden">
      <div className={`p-4 ${bgColor} border-b border-border`}>
        <h3 className="text-sm font-semibold text-foreground">
          {title}
        </h3>
      </div>
      <div className="overflow-x-auto">
        <table className="w-full text-sm">
          <thead>
            <tr className="border-b border-border bg-muted">
              <th className="px-4 py-3 text-left font-semibold text-foreground">
                Currency
              </th>
              <th className="px-4 py-3 text-right font-semibold text-foreground">
                Total {title.includes("Income") ? "Income" : "Expense"}
              </th>
            </tr>
          </thead>
          <tbody>
            {Object.entries(data).map(([currency, amount]) => (
              <tr
                key={currency}
                className="border-b border-border hover:bg-muted transition-colors"
              >
                <td className="px-4 py-3 text-foreground font-medium">
                  {currency === '' || currency === 'null' ? 'Other' : currency}
                </td>
                <td className={`px-4 py-3 text-right font-medium ${textColor}`}>
                  {formatNumber(Math.abs(amount))}
                </td>
              </tr>
            ))}
            {Object.keys(data).length === 0 && (
              <tr>
                <td colSpan={2} className="px-4 py-3 text-center text-muted-foreground">
                  {emptyMessage}
                </td>
              </tr>
            )}
          </tbody>
        </table>
      </div>
    </div>
  );
};
