#ifndef SPRITE_H
#define SPRITE_H

#include <string>

#include "IGraphicsEngineRenderer.hpp"
#include "TinyMath.hpp"
#include "TransformComponent.hpp"
#include <string>

/**
 * A Component implementation to load and display sprites.
 */
class SpriteComponent : public Component
{
public:
    /**
     * Construct a new Sprite Component object
     * 
     * @param transform the position of the parent GameObject
     */
    SpriteComponent(TransformComponent *transform);

    /**
     * Destroy the Sprite Component object
     */
    ~SpriteComponent();

    /**
     * Load a new image to be displayed.
     * 
     * @param filePath the path to the imagefile (must be .bmp currently)
     * @param ren the renderer to be drawn to
     * @param w the width of the Sprite
     * @param h the height of the Sprite
     * @param frames how many frames are on the spritesheet
     * @param targetDisplay how big the displayed sprite is
     */
    void LoadImage(std::string filePath, SDL_Renderer *ren, int w, int h, int frames, Vec2D targetDisplay);

    /**
     * Get the dimensions of the Sprite.
     * 
     * @return the dimensions of the Sprite 
     */
    Vec2D getDimensions();

    /**
     * Animate the Sprite based on the frame given.
     * {@inheritDoc}
     */
    void Update(SDL_Event e, int frame, std::vector<std::string> broadcastList) override;

    /**
     * Render the Sprite.
     * 
     * @param ren the SDL_Renderer to draw the sprite to
     */
    void Render(SDL_Renderer *ren) override;

    void ShowComponentEditor(bool *showEditor) override;

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

private:
    unsigned int mCurrentFrame{0};
    unsigned int mLastFrame{7};
    // An SDL Surface contains pixel data to draw an image
    SDL_Surface *mSpriteSheet = nullptr;
    SDL_Texture *mTexture = nullptr;

    SDL_Rect mSrc;
    SDL_Rect mDest;

    int width;
    int height;
    int frameCount;

    Vec2D dimensions;

    TransformComponent *transform;
    SDL_Renderer *last_used = nullptr;
};

#endif
