import type { Session } from '../api/types';
import { daysInMonth } from './month';

/** Worked ms per day of `month` ("YYYY-MM"), index 0 = day 1. A shift is credited to its clock-in day. */
export function aggregateDailyWorkedMs(sessions: Session[], month: string): number[] {
  const days = new Array(daysInMonth(month)).fill(0) as number[];
  for (const session of sessions) {
    const day = new Date(session.clockIn).getDate();
    if (day >= 1 && day <= days.length) {
      days[day - 1] += session.workedMs;
    }
  }
  return days;
}
