File size: 1,597 Bytes
c65cae0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
export default function MoveHistory({ history }) {
  return (
    <div className="comic-card h-[300px] flex flex-col">
      <h3 className="font-['Bangers'] text-xl mb-3 border-b-4 border-black pb-2 flex items-center gap-2">
        <span>📜</span> Battle Log
      </h3>
      
      <div className="flex-1 overflow-y-auto space-y-2 pr-2 custom-scrollbar">
        {history.length === 0 ? (
          <div className="text-center text-gray-500 font-bold py-10 italic">
            "The battle begins..."
          </div>
        ) : (
          history.map((move, i) => (
            <div key={i} className="flex items-center gap-2 text-sm font-bold animate-slide-in">
              <span className="bg-black text-white w-6 h-6 flex items-center justify-center rounded-full text-xs">
                {Math.floor(i / 2) + 1}
              </span>
              <span className={i % 2 === 0 ? 'text-comic-blue' : 'text-comic-red'}>
                {getPieceName(move.piece)}
              </span>
              <span className="text-gray-600">
                {String.fromCharCode(97 + move.from.c)}{8 - move.from.r} → {String.fromCharCode(97 + move.to.c)}{8 - move.to.r}
              </span>
            </div>
          ))
        )}
        <div ref={(el) => el?.scrollIntoView({ behavior: 'smooth' })} />
      </div>
    </div>
  );
}

const getPieceName = (p) => {
  const names = {
    'P': 'Pawn', 'N': 'Knight', 'B': 'Bishop', 'R': 'Rook', 'Q': 'Queen', 'K': 'King',
    'p': 'Pawn', 'n': 'Knight', 'b': 'Bishop', 'r': 'Rook', 'q': 'Queen', 'k': 'King',
  };
  return names[p] || p;
};