/**
 * SET 48 — run-history entries route to the RUN view, never admin/install.
 * SET 49 — boot surface is the control panel (empty main), not AdminView.
 */
import { describe, expect, it } from 'vitest';
import {
  bootSurfaceFlags,
  flagsAfterAdminClick,
  flagsAfterInstallSummaryClick,
  flagsAfterRunEntryClick,
  resolveMainSurface,
} from '../web/src/mainSurface';

describe('SET 48/49 main surface routing', () => {
  it('boot defaults resolve to empty (control panel owns the shell)', () => {
    expect(resolveMainSurface(bootSurfaceFlags())).toBe('empty');
  });

  it('run-entry click opens RUN view for records with and without projectId', () => {
    const withProject = { id: 'run-a', projectId: 'proj-1' };
    const withoutProject = { id: 'run-b', projectId: null as string | null };
    for (const r of [withProject, withoutProject]) {
      const flags = { ...flagsAfterRunEntryClick(), hasActiveJob: false };
      expect(resolveMainSurface(flags)).toBe('run');
      // Routing keys on run id existence, never projectId shape.
      expect(r.id).toBeTruthy();
      expect(flags.adminOpen).toBe(false);
      expect(flags.installPanelOpen).toBe(false);
    }
  });

  it('sidebar summary opens install panel only', () => {
    const flags = { ...flagsAfterInstallSummaryClick(), hasActiveJob: false };
    expect(resolveMainSurface(flags)).toBe('install');
  });

  it('footer admin opens AdminView only', () => {
    const flags = { ...flagsAfterAdminClick(), hasActiveJob: false };
    expect(resolveMainSurface(flags)).toBe('admin');
  });

  it('install takes priority over admin/run when wrongly double-set', () => {
    expect(resolveMainSurface({
      installPanelOpen: true,
      adminOpen: true,
      t1Open: true,
      hasActiveJob: true,
    })).toBe('install');
  });
});
