import { describe, expect, it } from 'bun:test';
import { renderToStaticMarkup } from 'react-dom/server';
import { GhostCard } from './GhostCard';
import type { GhostNote } from '../../../types/research';

const sampleGhost: GhostNote = {
  id: 'ghost-1',
  workspaceId: 'workspace-1',
  ghostClass: 'candidate_thesis',
  headline: 'Possible earnings power inflection',
  body: 'Observed: margin commentary improved. Inference: earnings power may be understated.',
  tone: 'tentative',
  confidence: 0.88,
  visibilityState: 'visible',
  state: 'visible',
  supportingNoteIds: ['note-1', 'note-2'],
  contradictingNoteIds: ['note-3'],
  sourceIds: ['source-1'],
  evidenceThresholdMet: true,
  createdAt: '2026-04-09T10:00:00Z',
  updatedAt: '2026-04-09T10:00:00Z',
};

const missingEvidenceGhost: GhostNote = {
  ...sampleGhost,
  id: 'ghost-missing',
  ghostClass: 'missing_evidence_prompt',
  headline: 'Missing evidence for claim: "Revenue will grow 15%"',
  body: 'Observed: the claim "Revenue will grow 15%" is currently unsupported by a linked source note.',
  supportingNoteIds: ['note-claim-1'],
  contradictingNoteIds: [],
  sourceIds: [],
  evidenceThresholdMet: false,
};

describe('GhostCard', () => {
  it('renders ghost summary and evidence counts', () => {
    const html = renderToStaticMarkup(
      <GhostCard ghost={sampleGhost} density="comfortable" />,
    );

    expect(html).toContain('Possible earnings power inflection');
    expect(html).toContain('Candidate Thesis');
    expect(html).toContain('2 supporting');
    expect(html).toContain('1 contradicting');
  });

  it('renders View claim link for missing_evidence_prompt ghosts when onSelectNote is provided', () => {
    const html = renderToStaticMarkup(
      <GhostCard
        ghost={missingEvidenceGhost}
        density="comfortable"
        onSelectNote={() => {}}
      />,
    );

    expect(html).toContain('View claim');
    expect(html).toContain('Missing evidence for claim: &quot;Revenue will grow 15%&quot;');
  });

  it('does not render View claim link when onSelectNote is absent', () => {
    const html = renderToStaticMarkup(
      <GhostCard ghost={missingEvidenceGhost} density="comfortable" />,
    );

    expect(html).not.toContain('View claim');
  });
});
