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

const createWorkspace = (id: string, ticker: string): ResearchWorkspace => ({
  id,
  name: `${ticker} Research`,
  primaryTicker: ticker,
  scope: 'single_company',
  stage: 'capture',
  defaultView: 'canvas',
  pinnedNoteIds: [],
  archived: false,
  createdAt: '2026-04-09T10:00:00Z',
  updatedAt: '2026-04-09T10:00:00Z',
});

describe('ResearchMode', () => {
  it('renders empty state when no workspace is selected', () => {
    const html = renderToStaticMarkup(
      <ResearchMode
        workspaces={[]}
        activeWorkspaceId={null}
        navigationIntent={null}
        onSelectWorkspace={() => {}}
        onEnsureWorkspace={async () => null}
        onCaptureResearchNote={async () => {
          throw new Error('not used');
        }}
        onConsumeNavigationIntent={() => {}}
      />,
    );

    expect(html).toContain('No research workspace selected');
    expect(html).toContain('Select a research workspace');
  });

  it('renders the selected workspace details from the active workspace id', () => {
    const html = renderToStaticMarkup(
      <ResearchMode
        workspaces={[createWorkspace('workspace-1', 'AAPL'), createWorkspace('workspace-2', 'NVDA')]}
        activeWorkspaceId="workspace-2"
        navigationIntent={null}
        onSelectWorkspace={() => {}}
        onEnsureWorkspace={async () => null}
        onCaptureResearchNote={async () => {
          throw new Error('not used');
        }}
        onConsumeNavigationIntent={() => {}}
      />,
    );

    expect(html).toContain('NVDA Research');
    expect(html).toContain('NVDA');
  });
});
