import type { TDashboardTrendPoint } from "@/lib/api/types";
import type { DailyPoint } from "./daily-trend-chart";

/**
 * Convert an API daily series (`{ date: "YYYY-MM-DD", count }`) into chart
 * points with a locale-formatted axis label. API dates are UTC calendar days
 * and are kept verbatim in `date` for lookups.
 */
export function toLabeledPoints(series: TDashboardTrendPoint[]): DailyPoint[] {
  return series.map((point) => {
    const [y, m, d] = point.date.split("-").map(Number);
    const date = new Date(Date.UTC(y, (m ?? 1) - 1, d ?? 1));
    return {
      date: point.date,
      label: date.toLocaleDateString("en", {
        month: "short",
        day: "numeric",
      }),
      count: point.count,
    };
  });
}
