import { describe, it, expect } from 'vitest';
import { battleMapSchema } from '@/lib/schemas';
import { toPlayerProjection } from './projection';

function map(over: Record<string, unknown>) {
  return battleMapSchema.parse({ id: 'm', campaignId: 'c', name: 'M', createdAt: 't', updatedAt: 't', gridSize: 50, ...over });
}

describe('toPlayerProjection fog visibility', () => {
  const tokens = [
    { id: 'lit', label: 'Hero', col: 0, row: 0, size: 1 },
    { id: 'dark', label: 'Lurker', col: 5, row: 5, size: 1 },
    { id: 'secret', label: 'Trap', col: 0, row: 0, size: 1, gmOnly: true },
  ];

  it('hides tokens whose cells are unrevealed when fog is on', () => {
    const p = toPlayerProjection(map({ fogEnabled: true, revealed: ['0,0'], tokens }));
    expect(p.tokens.map((t) => t.id)).toEqual(['lit']); // dark = fogged, secret = gmOnly
  });

  it('shows all non-gmOnly tokens when fog is off', () => {
    const p = toPlayerProjection(map({ fogEnabled: false, revealed: [], tokens }));
    expect(p.tokens.map((t) => t.id).sort()).toEqual(['dark', 'lit']);
  });
});
