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

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

export function formatStatus(status: string) {
  switch (status) {
    case "NOT_STARTED":
      return "Not Started";
    case "IN_PROGRESS":
      return "In Progress";
    case "COMPLETED":
      return "Completed";
    default:
      return status;
  }
}
export function formatTimeFilter(time: string) {
  switch (time) {
    case "week":
      return "Week";
    case "month":
      return "Month";
    case "alltime":
      return "All";
    default:
      return "Today";
  }
}

export function getRandomColor() {
  const colors = [
    "bg-cyan-700",
    "bg-lime-600",
    "bg-green-500",
    "bg-slate-700",
    "bg-violet-600",
    "bg-sky-500",
    "bg-indigo-600",
    "bg-gray-400",
    "bg-red-500",
    "bg-orange-500",
    "bg-yellow-500",
    "bg-teal-500",
    "bg-blue-500",
    "bg-purple-500",
    "bg-pink-500",
    "bg-rose-500",
    "bg-amber-500",
    "bg-emerald-500",
    "bg-fuchsia-500",
    "bg-lime-500",
    "bg-cyan-500",
    "bg-blue-600",
    "bg-indigo-700",
    "bg-purple-700",
    "bg-pink-700",
    "bg-red-600",
    "bg-orange-600",
    "bg-yellow-600",
    "bg-teal-600",
    "bg-emerald-600",
    "bg-rose-600",
    "bg-amber-600",
    "bg-fuchsia-600",
    "bg-lime-700",
    "bg-cyan-600",
    "bg-blue-700",
    "bg-indigo-800",
    "bg-purple-800",
    "bg-pink-800",
    "bg-red-700",
  ];
  return colors[Math.floor(Math.random() * colors.length)];
}

export const formatTime = (seconds: number) => {
  const m = Math.floor(seconds / 60);
  const s = seconds % 60;
  return `${m}:${s.toString().padStart(2, "0")}`;
};

export const slideVariants = {
  initial: (direction: number) => ({
    x: direction > 0 ? 100 : -100,
    opacity: 0,
  }),
  animate: {
    x: 0,
    opacity: 1,
    transition: { duration: 0.35 },
  },
  exit: (direction: number) => ({
    x: direction > 0 ? -100 : 100,
    opacity: 0,
    transition: { duration: 0.25 },
  }),
};

export const formatGroupTitle = (status: string) => {
  switch (status) {
    case "IN_PROGRESS":
      return "In Progress";
    case "NOT_STARTED":
      return "Not Started";
    case "COMPLETED":
      return "Completed";
    default:
      return status;
  }
};

export const truncate = (str: string | undefined, max = 14): string => {
  if (!str) return "";
  return str.length > max ? str.slice(0, max - 1) + "…" : str;
};
