#include "render.h"
void renderBoard(
    Board& board,
    Vector2 mousePos,
    bool clicked,
    std::vector<Move> legal,
    std::function<void(int,int)> callback,
    bool disable
){
  int blackCount = __builtin_popcountll(board.black);
  int whiteCount = __builtin_popcountll(board.white);
  DrawText(std::to_string(blackCount).c_str(), 0, 0, 20, BLACK);
  DrawText(std::to_string(whiteCount).c_str(), 0, 25, 20, WHITE);
  for(int x=0;x<8;x++){
    for(int y=0;y<8;y++){
      Rectangle tileRect={97+35*x,83+35*y,35,35};
      DrawRectangleRec(tileRect, GREEN);      
      DrawRectangleLinesEx(tileRect,2,BLACK);
      bool black=hasPiece(board.black,x,y);
      bool white=hasPiece(board.white,x,y);
      Vector2 circleCenter={115+35*x,100+35*y};
      if(white){
        DrawCircleV(circleCenter,14,WHITE);
      } else if (black){
        DrawCircleV(circleCenter,14,BLACK);
      } else if(!disable) {
        bool isLegal = false;
        for (auto &m : legal) {
          if (m.x == x && m.y == y) {
            isLegal = true;
            break;
          }
        }

        if(isLegal){
          DrawCircleV(circleCenter,14,RED);

          if(CheckCollisionPointCircle(mousePos,circleCenter,14)){
            DrawCircleV(circleCenter,14,YELLOW);
            if(clicked){
              callback(x,y);
            }
          }
        }
      }
    
    }
  }
}