import assert from 'node:assert/strict';
import test from 'node:test';

import { SceneTokensSessionStore } from './sceneTokensSessionStore';

void test('SceneTokensSessionStore setSize is session-only and survives move', () => {
  const store = new SceneTokensSessionStore();
  const s1 = store.dispatch({ kind: 'setSize', placementId: 't1', sizeN: 0.2 });
  assert.equal(s1.byPlacementId.t1?.sizeN, 0.2);
  assert.equal(s1.byPlacementId.t1?.nx, undefined);
  const s2 = store.dispatch({ kind: 'move', placementId: 't1', nx: 0.3, ny: 0.4 });
  assert.equal(s2.byPlacementId.t1?.sizeN, 0.2);
  assert.equal(s2.byPlacementId.t1?.nx, 0.3);
  const s3 = store.dispatch({ kind: 'setSize', placementId: 't1', sizeN: 0.01 });
  assert.equal(s3.byPlacementId.t1?.sizeN, 0.02); // clamped min
});

void test('SceneTokensSessionStore rotateMapCwSteps keeps sizeN', () => {
  const store = new SceneTokensSessionStore();
  store.dispatch({ kind: 'move', placementId: 't1', nx: 0.2, ny: 0.1 });
  store.dispatch({ kind: 'setSize', placementId: 't1', sizeN: 0.15 });
  const s = store.rotateMapCwSteps(1);
  assert.equal(s.byPlacementId.t1?.nx, 0.9);
  assert.equal(s.byPlacementId.t1?.ny, 0.2);
  assert.equal(s.byPlacementId.t1?.sizeN, 0.15);
});
