// Labels shared by the Recent Check Runs table and the run details page.

export const RUN_STATUS = {
  RUNNING: { label: "Running", className: "text-slate-700" },
  COMPLETED: { label: "Completed", className: "text-emerald-700" },
  FAILED: { label: "Failed", className: "text-red-700" },
} as const;

export function runTriggerLabel(run: { trigger: "SCHEDULED" | "MANUAL"; startedBy: string | null }): string {
  return run.trigger === "SCHEDULED" ? "Scheduled" : `Manual${run.startedBy ? ` · ${run.startedBy}` : ""}`;
}

/** "42s" / "3m 5s"; null while the run is still going. */
export function runDuration(startedAt: Date, finishedAt: Date | null): string | null {
  if (!finishedAt) return null;
  const seconds = Math.max(0, Math.round((finishedAt.getTime() - startedAt.getTime()) / 1000));
  return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${seconds % 60}s`;
}
