import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]): string {
  return twMerge(clsx(inputs));
}

export function formatTokens(count: number): string {
  if (count >= 1_000_000) return (count / 1_000_000).toFixed(1).replace(/\.0$/, "") + "M";
  return (count / 1000).toFixed(1).replace(/\.0$/, "") + "K";
}

export type StatusCategory = "success" | "client_error" | "server_error" | "pending";

export function getStatusCategory(status: number | null): StatusCategory {
  if (status === null) return "pending";
  if (status >= 200 && status < 300) return "success";
  if (status >= 400 && status < 500) return "client_error";
  if (status >= 500) return "server_error";
  return "pending";
}
