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

// Removed duplicate declaration of the `cn` function

interface FormatDateOptions {
  includeDay?: boolean;
  format?: "short" | "long";
  includeTime?: boolean;
}

export function formatDate(
  date: string | Date | null,
  options?: FormatDateOptions
): string {
  if (!date) return "";

  const dateObj = typeof date === "string" ? new Date(date) : date;
  const {
    includeDay = true,
    format = "long",
    includeTime = true,
  } = options || {};

  // Default format options
  const formatOptions: Intl.DateTimeFormatOptions = {
    year: "numeric",
    month: format === "short" ? "short" : "long",
    day: "numeric",
  };

  // Add weekday if requested
  if (includeDay) {
    formatOptions.weekday = format === "short" ? "short" : "long";
  }

  // Add time if requested
  if (includeTime) {
    formatOptions.hour = "numeric";
    formatOptions.minute = "numeric";
    formatOptions.hour12 = true;
  }

  return new Intl.DateTimeFormat("en-US", formatOptions).format(dateObj);
}

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

export function capitalize(str: string): string {
  if (!str) return "";
  return str
    .split(" ")
    .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
    .join(" ");
}
