#ifndef TILE_H
#define TILE_H

#include <string>

#include "IGraphicsEngineRenderer.hpp"
#include "GameObject.hpp"
#include "Component.hpp"
#include "RigidbodyComponent.hpp"
#include <string>

/**
 * This is a minimal implementation of a TileMapComponent
 */
class TileMapComponent : public Component {
public:
    /**
     * Constructor for a tilemap
     */
    TileMapComponent(std::string tileSheetFileName, int rows, int cols, int _TileWidth, int _TileHeight, int _mapX,
                     int _mapY, SDL_Renderer *ren, std::vector<GameObject *>* gameobjects);

    /**
     * Destructor for a tilemap
     */
    ~TileMapComponent();

    /**
     * Temporary function for generating a simple
     * map to display some tiles
     */
    void GenerateSimpleMap();

    /**
     * Function for printing text to console
     */
    void PrintMap();

    /**
     * Set the 'type' of tile at an x and y position
     */
    void SetTile(int x, int y, int type);

    /**
     * Return the tile type at an x and y position
     */
    int GetTileType(int x, int y);

    /**
     * Draw all of the tiles in the tilemap
     */
    void Update(SDL_Event e, int frame, std::vector<std::string> broadcastList) override;

    void Render(SDL_Renderer *ren) override;

    void ShowComponentEditor(bool* showEditor) override;

    const char* ComponentTypeName() override {return "Tile Map Component";}

private:
    // Dimensions of our TileMapComponent and individual tiles.
    // Used for spiltting up the sprite sheet
    int m_Rows;
    int m_Cols;
    // How big each tile is.
    int m_TileWidth;
    int m_TileHeight;
    // size of our tilemap
    int m_MapX;
    int m_MapY;
    // Where our TileMapComponent is rendered
    // An SDL Surface contains pixel data to draw our TileMapComponent
    SDL_Surface *m_TileSpriteSheet;
    SDL_Texture *m_Texture;
    // Stores our tile types
    int *m_Tiles;
    std::vector<GameObject *>* m_gameobjects;
};

#endif
