import { Component, Input } from '@angular/core';

@Component({
  selector: 'app-chess-piece',
  standalone: true,
  templateUrl: './chess-piece.component.html',
  styleUrl: './chess-piece.component.css'
})
export class ChessPieceComponent {
  @Input({ required: true }) pieceCode: string | null = null;

  get spriteUrl(): string {
    if (!this.pieceCode) {
      return '';
    }

    const color = this.pieceCode === this.pieceCode.toUpperCase() ? 'white' : 'black';
    const pieceName = this.getPieceName(this.pieceCode.toLowerCase());
    return `/arabian-chess/sprites/pieces/${color}_${pieceName}.png`;
  }

  private getPieceName(piece: string): string {
    switch (piece) {
      case 'k':
        return 'king';
      case 'q':
        return 'queen';
      case 'r':
        return 'rook';
      case 'b':
        return 'bishop';
      case 'n':
        return 'knight';
      case 'p':
        return 'pawn';
      default:
        return 'pawn';
    }
  }
}
