import { Badge } from "@/components/ui/badge";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";

export function UsageView({
  stats,
}: {
  stats: {
    totalRequests: number;
    totalTokens: number;
    totalCost: number;
    byAgent: Record<string, { requests: number; tokens: number; cost: number }>;
  };
}) {
  return (
    <div className="space-y-6">
      <div className="grid gap-4 md:grid-cols-3">
        <Card>
          <CardHeader>
            <CardTitle>Total Requests</CardTitle>
          </CardHeader>
          <CardContent className="text-3xl font-semibold">{stats.totalRequests}</CardContent>
        </Card>
        <Card>
          <CardHeader>
            <CardTitle>Total Tokens</CardTitle>
          </CardHeader>
          <CardContent className="text-3xl font-semibold">{stats.totalTokens}</CardContent>
        </Card>
        <Card>
          <CardHeader>
            <CardTitle>Estimated Cost</CardTitle>
          </CardHeader>
          <CardContent className="text-3xl font-semibold">${stats.totalCost.toFixed(2)}</CardContent>
        </Card>
      </div>
      <Card>
        <CardHeader>
          <CardTitle>By Agent</CardTitle>
          <CardDescription>Aggregated from the taskboard usage tracking table.</CardDescription>
        </CardHeader>
        <CardContent className="space-y-3">
          {Object.entries(stats.byAgent).map(([agent, value]) => (
            <div className="flex items-center justify-between rounded-xl border border-white/10 bg-slate-950/40 p-4" key={agent}>
              <div>
                <p className="font-medium">{agent}</p>
                <p className="text-sm text-slate-400">{value.tokens} tokens</p>
              </div>
              <div className="flex gap-2">
                <Badge variant="secondary">{value.requests} req</Badge>
                <Badge variant="outline">${value.cost.toFixed(2)}</Badge>
              </div>
            </div>
          ))}
        </CardContent>
      </Card>
    </div>
  );
}
