import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
function timeAgo(iso) {
    if (!iso)
        return "\u2014";
    const diff = Date.now() - new Date(iso).getTime();
    if (diff < 0)
        return "just now";
    const seconds = Math.floor(diff / 1000);
    if (seconds < 60)
        return `${seconds}s ago`;
    const minutes = Math.floor(seconds / 60);
    if (minutes < 60)
        return `${minutes}m ago`;
    const hours = Math.floor(minutes / 60);
    if (hours < 24)
        return `${hours}h ago`;
    const days = Math.floor(hours / 24);
    return `${days}d ago`;
}
export function AgentTable({ agents }) {
    if (!agents || agents.length === 0) {
        return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "Agents" }), _jsx(Text, { dimColor: true, children: "No agents yet. Start making LLM calls through the proxy." })] }));
    }
    // Sort by last activity (most recent first)
    const sorted = [...agents].sort((a, b) => {
        if (!a.last_activity)
            return 1;
        if (!b.last_activity)
            return -1;
        return new Date(b.last_activity).getTime() - new Date(a.last_activity).getTime();
    });
    return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "Agents" }), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: ["Agent".padEnd(16), "Status".padEnd(10), "Provider".padEnd(12), "Calls".padStart(8), "Cost".padStart(10), "  Last Activity"] }) }), sorted.map((agent) => (_jsx(Box, { children: _jsxs(Text, { children: [agent.agent_id.slice(0, 15).padEnd(16), _jsx(Text, { color: agent.status === "active" ? "green" : "yellow", children: agent.status.padEnd(10) }), (agent.primary_provider || "\u2014").padEnd(12), agent.recent_calls.toLocaleString().padStart(8), `$${agent.cost_today.toFixed(2)}`.padStart(10), "  ", timeAgo(agent.last_activity)] }) }, agent.agent_id)))] }));
}
//# sourceMappingURL=AgentTable.js.map