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

/**
 * Merge Tailwind CSS classes with clsx.
 */
export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}

/**
 * Format a date string with time (e.g., "Dec 10, 2025, 02:30 PM").
 */
export function formatDateTime(dateValue: string | number | undefined): string {
  if (!dateValue) return ''
  const date = new Date(dateValue)
  return date.toLocaleDateString(undefined, {
    year: 'numeric',
    month: 'short',
    day: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
  })
}

/**
 * Format a date string without time (e.g., "Dec 10, 2025").
 */
export function formatDate(dateValue: string | number | undefined): string {
  if (!dateValue) return ''
  const date = new Date(dateValue)
  return date.toLocaleDateString(undefined, {
    year: 'numeric',
    month: 'short',
    day: 'numeric',
  })
}

/**
 * Check if running in local development mode.
 * In DSS, the global `dataiku` object is available.
 */
export function isLocal(): boolean {
  return typeof (window as Window & { dataiku?: unknown }).dataiku === 'undefined'
}
