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

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

// export function formatPrice(price: number): string {
//   if (price >= 100) return `₹${(price / 100).toFixed(2)} Cr`;
//   return `₹${price.toFixed(2)} L`;
// }
export function formatPrice(price?: number): string {
  const safePrice = Number(price ?? 0);

  if (safePrice >= 100) {
    return `₹${(safePrice / 100).toFixed(2)} Cr`;
  }

  return `₹${safePrice.toFixed(2)} L`;
}
export const FUEL_COLOR_MAP: Record<string, string> = {
  Petrol:   "bg-orange-50  text-orange-700  border-orange-200",
  Diesel:   "bg-blue-50    text-blue-700    border-blue-200",
  Electric: "bg-green-50   text-green-700   border-green-200",
  Hybrid:   "bg-teal-50    text-teal-700    border-teal-200",
  CNG:      "bg-yellow-50  text-yellow-700  border-yellow-200",
};

export const FUEL_TYPES    = ["Petrol", "Diesel", "Electric", "Hybrid", "CNG"];
export const TRANSMISSIONS = ["Manual", "Automatic", "CVT", "AMT", "DCT"];
export const BODY_TYPES    = ["SUV", "Sedan", "Hatchback", "MUV", "Coupe", "Convertible"];

export const SORT_OPTIONS = [
  { label: "Price: Low to High",  sortBy: "price",  sortOrder: 1 },
  { label: "Price: High to Low",  sortBy: "price",  sortOrder: -1 },
  { label: "Best Rating",         sortBy: "rating", sortOrder: -1 },
  { label: "Newest First",        sortBy: "year",   sortOrder: -1 },
  { label: "Name A-Z",            sortBy: "name",   sortOrder: 1 },
];
export function truncate(s: string, n: number) {
  return s.length > n ? s.slice(0, n) + "..." : s;
}

