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

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

export function formatCurrency(amount: number): string {
  return new Intl.NumberFormat("en-US", {
    style: "currency",
    currency: "USD",
    minimumFractionDigits: 0,
    maximumFractionDigits: 0,
  }).format(amount);
}

export function formatNumber(num: number): string {
  return new Intl.NumberFormat("en-US").format(num);
}

export function formatPercent(num: number): string {
  return `${num.toFixed(2)}%`;
}

export function formatDate(date: string): string {
  return new Date(date).toLocaleDateString("en-US", {
    year: "numeric",
    month: "short",
    day: "numeric",
  });
}

export function formatRelativeTime(date: string): string {
  const now = new Date();
  const then = new Date(date);
  const diffMs = now.getTime() - then.getTime();
  const diffMins = Math.floor(diffMs / 60000);
  const diffHours = Math.floor(diffMs / 3600000);
  const diffDays = Math.floor(diffMs / 86400000);

  if (diffMins < 1) return "just now";
  if (diffMins < 60) return `${diffMins}m ago`;
  if (diffHours < 24) return `${diffHours}h ago`;
  if (diffDays < 7) return `${diffDays}d ago`;
  return formatDate(date);
}

export function truncate(str: string, length: number): string {
  if (str.length <= length) return str;
  return str.slice(0, length) + "...";
}

export function getInitials(name: string): string {
  return name
    .split(" ")
    .map((n) => n[0])
    .join("")
    .toUpperCase()
    .slice(0, 2);
}

export function getStatusColor(status: string): string {
  const colors: Record<string, string> = {
    active: "bg-emerald-100 text-emerald-800",
    pending: "bg-amber-100 text-amber-800",
    matched: "bg-blue-100 text-blue-800",
    closed: "bg-gray-100 text-gray-800",
    withdrawn: "bg-red-100 text-red-800",
    "high-intent": "bg-emerald-100 text-emerald-800",
    unresponsive: "bg-red-100 text-red-800",
    inactive: "bg-gray-100 text-gray-800",
    approved: "bg-blue-100 text-blue-800",
    sent: "bg-indigo-100 text-indigo-800",
    interested: "bg-emerald-100 text-emerald-800",
    passed: "bg-red-100 text-red-800",
    draft: "bg-gray-100 text-gray-800",
    queued: "bg-amber-100 text-amber-800",
    delivered: "bg-blue-100 text-blue-800",
    opened: "bg-indigo-100 text-indigo-800",
    clicked: "bg-purple-100 text-purple-800",
    replied: "bg-emerald-100 text-emerald-800",
    bounced: "bg-red-100 text-red-800",
    failed: "bg-red-100 text-red-800",
  };
  return colors[status] || "bg-gray-100 text-gray-800";
}

export const ASSET_TYPES = [
  "Office",
  "Industrial",
  "Retail",
  "Multifamily",
  "Mixed-Use",
  "Land",
  "Hospitality",
  "Other",
] as const;

export const MARKETS = [
  "New York, NY",
  "Los Angeles, CA",
  "Chicago, IL",
  "Dallas, TX",
  "Houston, TX",
  "Miami, FL",
  "Atlanta, GA",
  "Phoenix, AZ",
  "Denver, CO",
  "Seattle, WA",
  "San Francisco, CA",
  "Boston, MA",
  "Nashville, TN",
  "Austin, TX",
  "Charlotte, NC",
  "Tampa, FL",
  "Orlando, FL",
  "San Diego, CA",
  "Portland, OR",
  "Minneapolis, MN",
  "Other",
] as const;
