import { describe, expect, it } from 'vitest';
import { ManualClock, OfficeRuntime, renderScenario } from '../src/index.ts';
import { demoOffice } from './helpers.ts';

const office = demoOffice();
const hello = (o: typeof office, ui?: boolean) => new OfficeRuntime({ office: o, clock: new ManualClock(), ui }).hello();
const COLD = '/sprites/modern-ui/16x16/Modern_UI_Style_2.png';

describe('шкура интерфейса в hello (спека интерфейса §3.3–3.4)', () => {
  it('флаг ui и раздел в каталоге — hello.ui: URL листов и плитки обеих сеток', () => {
    const ui = hello(office, true).ui!;
    expect(ui.default).toBe('cold');
    expect(ui.themes['cold']!.sheet).toBe(COLD);
    expect(ui.icons['gear']!.off['cold']).toEqual([464, 16, 16, 16]);
    expect(ui.icons['gear']!.on['warm']).toEqual([464, 208, 16, 16]);
  });

  it('без флага — поля нет', () => {
    expect(hello(office).ui).toBeUndefined();
    expect(hello(office, false).ui).toBeUndefined();
  });

  it('без раздела ui в каталоге — поля нет и с флагом', () => {
    const bare = { ...office, bundle: { ...office.bundle, catalog: { ...office.bundle.catalog, ui: null } } };
    expect(hello(bare, true).ui).toBeUndefined();
  });

  it('тестовый режим: флаг передаётся в renderScenario', async () => {
    const q = { scenario: 'morning', t: '0', seed: '1' };
    expect((await renderScenario(office, q, { ui: true }))[0].ui?.default).toBe('cold');
    expect((await renderScenario(office, q))[0].ui).toBeUndefined();
  });
});
