const SDL = @import("sdl2");

const Game = @import("game.zig");
const Bag = @import("bag.zig");
const Grid = @import("grid.zig");
const Piece = @import("piece.zig");

pub fn renderBag(renderer: *SDL.SDL_Renderer, bag: Bag, cell_size: i32, pos_x: i32, pos_y: i32) void {
    for (bag.contents[0..5]) |_, i| {
        if (bag.contents[i]) |piece_type| {
            Piece.init(piece_type).render(renderer, cell_size, pos_x, pos_y + @intCast(i32, i) * cell_size * 4);
        }
    }
}

pub fn renderHeld(renderer: *SDL.SDL_Renderer, held: Piece.Type, cell_size: i32, pos_x: i32, pos_y: i32) void {
    Piece.init(held).render(renderer, cell_size, pos_x, pos_y);
}

pub fn render(game: Game) void {
    game.grid.render(game.renderer, game.grid_cell_size, game.grid_pos_x, game.grid_pos_y);
    game.piece.render(game.renderer, game.grid_cell_size, game.grid_pos_x, game.grid_pos_y);
    game.shadow.render(game.renderer, game.grid_cell_size, game.grid_pos_x, game.grid_pos_y);
    renderBag(game.renderer, game.bag, game.grid_cell_size, game.grid_pos_x + game.grid_cell_size * (Grid.ncolumns + 1), game.grid_pos_y);
    if (game.held) |held_piece| {
        renderHeld(game.renderer, held_piece, game.grid_cell_size, game.grid_pos_x - (game.grid_cell_size * 5), game.grid_pos_y);
    }

}
