"use client" import { useMemo, useState } from 'react' import { AreaChart, Area, CartesianGrid, XAxis, YAxis, Tooltip, ResponsiveContainer, } from 'recharts' import { DailyData } from './types' import { buildDailyTrendData, formatCurrency, formatTokens, getHeatmapColor, prepareHeatmapData, } from './utils' export default function Activity({ daily }: { daily: DailyData[] }) { const [viewMode, setViewMode] = useState<'heatmap' | 'chart'>('heatmap') const [selectedMetric, setSelectedMetric] = useState<'cost' | 'tokens'>('cost') const dailyTrendData = useMemo(() => buildDailyTrendData(daily), [daily]) const heatmapWeeks = useMemo(() => prepareHeatmapData(daily), [daily]) const maxCost = useMemo( () => (daily.length ? Math.max(...daily.map(d => d.totalCost)) : 0), [daily] ) return (

Activity

{viewMode === 'heatmap' ? 'Heatmap' : 'Chart'}
{viewMode === 'heatmap' ? (
{['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'].map((day) => (
{day}
))}
{(() => { const monthLabels: { month: string; position: number }[] = [] let lastMonth = -1 heatmapWeeks.forEach((week, weekIndex) => { const firstDay = week.find(d => d !== null) if (firstDay) { const date = new Date(firstDay.date + 'T00:00:00Z') const month = date.getUTCMonth() if (month !== lastMonth) { monthLabels.push({ month: date.toLocaleDateString('en-US', { month: 'short', timeZone: 'UTC' }), position: weekIndex * 20 }) lastMonth = month } } }) return (
{monthLabels.map((label, idx) => (
{label.month}
))}
) })()}
{heatmapWeeks.map((week, weekIndex) => (
{week.map((day, dayIndex) => (
{day && (

{day.formattedDate}

Cost: ${day.cost.toFixed(2)}

Tokens: {(day.tokens / 1000000).toFixed(2)}M

)}
))}
))}
Less
More
) : ( <>
selectedMetric === 'cost' ? formatCurrency(value) : formatTokens(value)} /> )}
) }