type DebugConsole = Pick<Console, 'log' | 'warn' | 'error' | 'group' | 'groupEnd' | 'table'>

function runInDev(method: keyof DebugConsole, args: unknown[]) {
  if (!import.meta.env.DEV) return
  console[method](...args)
}

export function debugLog(...args: unknown[]) {
  runInDev('log', args)
}

export function debugWarn(...args: unknown[]) {
  runInDev('warn', args)
}

export function debugError(...args: unknown[]) {
  runInDev('error', args)
}

export function debugGroup(...args: unknown[]) {
  runInDev('group', args)
}

export function debugGroupEnd() {
  runInDev('groupEnd', [])
}

export function debugTable(data?: unknown, columns?: string[]) {
  if (!import.meta.env.DEV) return
  console.table(data, columns)
}
