import React from "react";
import { ConsolidatedData } from "@/hooks/useConsolidatedHoldingsReport";
import { formatNumberWithCommas } from "@/lib/consolidated-holdings-utils";

interface AssetClassTableProps {
  data: ConsolidatedData;
  assetClassSummary: Record<string, number>;
}

export const AssetClassTable: React.FC<AssetClassTableProps> = ({ data, assetClassSummary }) => {
  return (
    <div className="max-h-[550px] overflow-y-auto scrollbar-thin scrollbar-thumb-slate-300 scrollbar-track-slate-100 rounded-lg border border-border text-foreground">
      <table className="w-full text-sm min-w-[300px]">
        <thead className="sticky top-0 bg-card z-10 border-b-2 border-border-strong">
          <tr>
            <th className="text-left py-2.5 px-4 font-semibold text-foreground bg-card">Asset Class</th>
            <th className="text-right py-2.5 px-4 font-semibold text-foreground bg-card">Default Currency Value</th>
          </tr>
        </thead>
        <tbody>
          {Object.entries(assetClassSummary).map(([name, value]: [string, any]) => (
            <tr key={name} className="border-b border-border hover:bg-muted transition-colors">
              <td className="py-2.5 px-4 text-foreground">{name}</td>
              <td className="text-right py-2.5 px-4 text-foreground font-medium">{formatNumberWithCommas(value)}</td>
            </tr>
          ))}
          <tr className="font-bold border-t-2 border-border-strong bg-muted">
            <td className="py-3 px-4 text-primary">Total</td>
            <td className="text-right py-3 px-4 text-primary">
              {data?.currency_code} {formatNumberWithCommas(data?.total_market_value_without_interest || 0)}
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  );
};
