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

/**
 * Formats an ISO date string using German locale.
 */
export function formatDate(iso: string): string {
  if (!iso) return '—'
  return new Date(iso).toLocaleDateString('de-DE', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
  })
}

/**
 * Capitalizes the first letter of a status string and replaces underscores
 * with spaces.
 */
export function formatStatus(status: string): string {
  if (!status) return '—'
  const normalized = status.replace(/_/g, ' ')
  return normalized.charAt(0).toUpperCase() + normalized.slice(1)
}

/**
 * Merges class names with Tailwind deduplication — thin clsx + tailwind-merge
 * wrapper.
 */
export function cn(...classes: ClassValue[]): string {
  return twMerge(clsx(classes))
}
