import { describe, it, expect } from 'vitest';
import { statusTone, toneClasses, formatActivityMeta } from './utils';

describe('statusTone', () => {
  it('returns theme-adaptive light-dark() colors', () => {
    const t = statusTone('failed');
    expect(t.bg).toBe('light-dark(#fee2e2, rgba(239,68,68,.15))');
    expect(t.fg).toBe('light-dark(#b91c1c, #fca5a5)');
  });
  it('falls back to neutral surface/muted vars', () => {
    const t = statusTone('whatever-unknown');
    expect(t.bg).toBe('light-dark(#e2e8f0, var(--surface-2))');
    expect(t.fg).toBe('light-dark(#475569, var(--muted))');
  });
});

describe('toneClasses', () => {
  it('pairs light + dark for colored tones', () => {
    expect(toneClasses('danger')).toContain('bg-red-50');
    expect(toneClasses('danger')).toContain('dark:text-red-300');
    expect(toneClasses('success')).toContain('dark:bg-emerald-500/15');
  });
  it('neutral stays on semantic tokens (auto-themed, no dark: needed)', () => {
    expect(toneClasses('neutral')).toBe('bg-surface-2 text-slate-700 border-hairline');
  });
});

describe('formatActivityMeta (backend-primary labels)', () => {
  it('shows the physical backend as the worker with a via-proxy suffix', () => {
    expect(formatActivityMeta('aao-gateway', 'quality', 'gpu-rtx-a'))
      .toBe('worker: gpu-rtx-a (via aao-gateway) · mode: quality');
  });

  it('falls back to the plain worker name when no backend tag exists', () => {
    expect(formatActivityMeta('my-worker', null, null)).toBe('worker: my-worker');
  });

  it('ignores a backend equal to the worker id (direct worker echo)', () => {
    expect(formatActivityMeta('gpu-a', 'auto', 'gpu-a'))
      .toBe('worker: gpu-a · mode: auto');
  });
});
