/**
 * Shared formatting utilities — import from here, never redefine inline.
 */

export function formatDate(iso) {
  if (!iso) return '—'
  return new Date(iso).toLocaleDateString(undefined, {
    month: 'short',
    day: 'numeric',
    year: 'numeric',
  })
}

export function formatSize(bytes) {
  if (!bytes) return '—'
  if (bytes < 1024) return bytes + ' B'
  if (bytes < 1048576) return (bytes / 1024).toFixed(1) + ' KB'
  return (bytes / 1048576).toFixed(1) + ' MB'
}

/** Maps a cloud provider slug to a Tailwind text-color class. */
export function providerColor(provider) {
  const map = {
    google_drive: 'text-blue-500',
    onedrive: 'text-sky-500',
    nextcloud: 'text-orange-500',
    webdav: 'text-gray-500',
  }
  return map[provider] ?? 'text-gray-400'
}

/** Maps a cloud provider slug to a Tailwind background-color class. */
export function providerBg(provider) {
  const map = {
    google_drive: 'bg-blue-50',
    onedrive: 'bg-sky-50',
    nextcloud: 'bg-orange-50',
    webdav: 'bg-gray-50',
  }
  return map[provider] ?? 'bg-gray-50'
}

/** Human-readable label for a cloud provider slug. */
export function providerLabel(provider) {
  const map = {
    google_drive: 'Google Drive',
    onedrive: 'OneDrive',
    nextcloud: 'Nextcloud',
    webdav: 'WebDAV',
  }
  return map[provider] ?? provider
}
