"use client"; import { LoaderIcon } from "lucide-react"; import { useTranslations } from "next-intl"; import { compactNumberFormatter, formatCost } from "./shared"; export type TopEntity = { key: string; label: string; sublabel?: string | null; requests: number; totalTokens: number; costUsd: number | null; }; type TopEntitiesListProps = { entities: TopEntity[]; isLoading: boolean; nameColumnLabel: string; emptyLabel?: string; }; export function TopEntitiesList(props: TopEntitiesListProps) { const t = useTranslations(); const totalCost = props.entities.reduce( (sum, e) => sum + (e.costUsd ?? 0), 0 ); return (
{props.entities.length > 0 && (
{props.nameColumnLabel}
{t("aiUsageRequests")}
{t("aiUsageTokens")}
{t("aiUsageCost")}
%
)}
    {props.entities.length === 0 && (
    {props.isLoading ? ( <> {t("aiUsageLoading")} ) : ( (props.emptyLabel ?? t("aiUsageNoData")) )}
    )} {props.entities.map((entity) => { const percent = totalCost > 0 ? (entity.costUsd ?? 0) / totalCost : 0; return (
  1. {entity.label} {entity.sublabel && ( {entity.sublabel} )}
    {compactNumberFormatter.format(entity.requests)}
    {compactNumberFormatter.format( entity.totalTokens )}
    {formatCost(entity.costUsd)}
    {Math.round(percent * 100)}%
  2. ); })}
); }