"use client";
import { TrendingUp, Newspaper, Radio } from "lucide-react";
import {
ComposedChart,
Line,
Bar,
XAxis,
YAxis,
Tooltip,
ResponsiveContainer,
CartesianGrid,
Legend,
} from "recharts";
import { TrendScore, MemberTrendScore } from "@/lib/types";
type AnyTrendScore = TrendScore | MemberTrendScore;
interface TrendChartProps {
data?: AnyTrendScore[];
title?: string;
}
function ScoreBadge({ label, value, icon }: { label: string; value: number | string; icon: React.ReactNode }) {
return (
);
}
export function TrendChart({ data, title = "Public Interest" }: TrendChartProps) {
const chartData = data?.map((d) => ({
date: new Date(d.score_date + "T00:00:00").toLocaleDateString("en-US", { month: "short", day: "numeric" }),
score: Math.round(d.composite_score),
newsapi: d.newsapi_count,
gnews: d.gnews_count,
gtrends: Math.round(d.gtrends_score),
})) ?? [];
const latest = data?.[data.length - 1];
return (
{title}
{latest !== undefined && (
{Math.round(latest.composite_score)}
)}
{/* Signal breakdown badges */}
{latest && (
)}
{chartData.length === 0 ? (
Interest data not yet available. Check back after the nightly scoring run.
) : (
{
const labels: Record = {
score: "Composite",
newsapi: "NewsAPI articles",
gnews: "Google News articles",
gtrends: "Google Trends",
};
return [value, labels[name] ?? name];
}}
/>
)}
Composite 0–100 · NewsAPI articles (max 40 pts) + Google News volume (max 30 pts) + Google Trends score (max 30 pts)
);
}