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,
  targetClaimText: 'Margins can inflect enough to change earnings power.',
  counterCase: 'The margin improvement may be temporary or already priced in.',
  resolutionStatus: 'open',
  leverageScore: 0.86,
  supportStrength: 'mixed',
  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'],
  targetNoteId: 'note-claim-1',
  contradictingNoteIds: [],
  sourceIds: [],
  evidenceThresholdMet: false,
  targetClaimText: 'Revenue will grow 15%',
  counterCase: 'The growth claim may be unsupported or already reflected in expectations.',
  leverageScore: 0.64,
  supportStrength: 'none',
};

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

    expect(html).toContain('Possible earnings power inflection');
    expect(html).toContain('Candidate Thesis');
    expect(html).toContain('High leverage');
    expect(html).toContain('Support: Mixed');
    expect(html).toContain('Status: Open');
    expect(html).toContain('Counter-case');
  });

  it('renders View targeted point link when target note is available', () => {
    const html = renderToStaticMarkup(
      <GhostCard
        ghost={missingEvidenceGhost}
        density="comfortable"
        onSelectNote={() => {}}
      />,
    );

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

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

    expect(html).not.toContain('View targeted point');
  });
});
