import { describe, it, expect } from 'vitest';
import { EQUIPMENT_TYPES } from '@/lib/game/data/equipment';
import { isTwoHanded } from '@/lib/game/crafting-utils';

// ─── Regression test: Off-hand slot visual blocking for 2H weapons ─────────
// https://gitea.tailf367e3.ts.net/Anexim/Mana-Loop/issues/341

describe('EquipmentSlotGrid — two-handed weapon off-hand blocking', () => {
  // The visual blocking logic in EquipmentSlotGrid uses getTwoHandedBlocker()
  // which checks: if slot === 'offHand' and mainHand has a two-handed weapon,
  // return the weapon name. We test the underlying data + isTwoHanded guard
  // that the component relies on.

  it('basicStaff is marked two-handed in equipment data', () => {
    // basicStaff is the starting weapon — this is the primary case for the bug
    expect(isTwoHanded('basicStaff')).toBe(true);
  });

  it('oakStaff is marked two-handed in equipment data', () => {
    expect(isTwoHanded('oakStaff')).toBe(true);
  });

  it('arcanistStaff is marked two-handed in equipment data', () => {
    expect(isTwoHanded('arcanistStaff')).toBe(true);
  });

  it('battlestaff is marked two-handed in equipment data', () => {
    expect(isTwoHanded('battlestaff')).toBe(true);
  });

  it('apprenticeWand is NOT two-handed', () => {
    expect(isTwoHanded('apprenticeWand')).toBe(false);
  });

  it('crystalWand is NOT two-handed', () => {
    expect(isTwoHanded('crystalWand')).toBe(false);
  });

  it('ironBlade (sword) is NOT two-handed', () => {
    expect(isTwoHanded('ironBlade')).toBe(false);
  });

  it('basicCatalyst is NOT two-handed', () => {
    expect(isTwoHanded('basicCatalyst')).toBe(false);
  });

  it('isTwoHanded returns false for unknown type IDs', () => {
    expect(isTwoHanded('nonexistent_type')).toBe(false);
  });

  it('exactly 4 equipment types are two-handed', () => {
    const twoHandedTypes = Object.values(EQUIPMENT_TYPES).filter((t) => t.twoHanded);
    expect(twoHandedTypes.length).toBe(4);
    const ids = twoHandedTypes.map((t) => t.id);
    expect(ids).toContain('basicStaff');
    expect(ids).toContain('oakStaff');
    expect(ids).toContain('arcanistStaff');
    expect(ids).toContain('battlestaff');
  });

  it('all two-handed types are in the mainHand slot category', () => {
    const twoHandedTypes = Object.values(EQUIPMENT_TYPES).filter((t) => t.twoHanded);
    for (const type of twoHandedTypes) {
      expect(type.slot).toBe('mainHand');
    }
  });
});
