export type BatchStatusTone =
  | 'neutral'
  | 'info'
  | 'warning'
  | 'danger'
  | 'success'
  | 'accent'
  | 'muted'

export type BatchStatusIcon =
  | 'upload'
  | 'edit'
  | 'clock'
  | 'reject'
  | 'check'
  | 'shield'
  | 'approve'
  | 'done'
  | 'cancel'
  | 'unknown'

export interface BatchStatusMeta {
  label: string
  tone: BatchStatusTone
  icon: BatchStatusIcon
}

/** Canonical labels aligned with design-doc § Status labels. */
export const BATCH_STATUS_META: Record<string, BatchStatusMeta> = {
  UPLOADED: { label: 'Uploaded', tone: 'neutral', icon: 'upload' },
  IN_ENTRY: { label: 'In Entry', tone: 'warning', icon: 'edit' },
  PENDING_VERIFICATION: { label: 'Pending Verification', tone: 'warning', icon: 'clock' },
  REJECTED: { label: 'Verification Rejected', tone: 'danger', icon: 'reject' },
  VERIFIED: { label: 'Verified', tone: 'info', icon: 'check' },
  AWAITING_CLINICAL_APPROVAL: { label: 'Pending Approval', tone: 'accent', icon: 'shield' },
  APPROVED: { label: 'Approved', tone: 'success', icon: 'approve' },
  PROMOTED: { label: 'Promoted', tone: 'success', icon: 'done' },
  CANCELLED: { label: 'Cancelled', tone: 'muted', icon: 'cancel' },
}

export const BATCH_STATUS_TONE_CLASSES: Record<BatchStatusTone, string> = {
  neutral: 'bg-canvas text-ink-strong border border-line',
  info: 'bg-primary-50 text-primary-800 border border-primary-100',
  warning: 'bg-clinical-warning-bg text-clinical-warning border border-[#FEDF89]',
  danger: 'bg-clinical-danger-bg text-clinical-danger border border-[#FECDCA]',
  success: 'bg-clinical-safe-bg text-clinical-safe border border-[#ABEFC6]',
  accent: 'bg-primary-50 text-primary-700 border border-primary-100',
  muted: 'bg-canvas text-ink-disabled border border-line',
}

export function getBatchStatusMeta(status: string | null | undefined): BatchStatusMeta {
  if (!status) {
    return { label: 'Unknown', tone: 'neutral', icon: 'unknown' }
  }
  const key = status.toUpperCase()
  return (
    BATCH_STATUS_META[key] ?? {
      label: key
        .replace(/_/g, ' ')
        .toLowerCase()
        .replace(/\b\w/g, (c) => c.toUpperCase()),
      tone: 'neutral',
      icon: 'unknown',
    }
  )
}
