#ifndef PROGRESS_INDICATOR_HPP_
#define PROGRESS_INDICATOR_HPP_

#include <Widget/Widget.hpp>
#include <ToolTip/ToolTip.hpp>
#include <Utilities/Utilities.hpp>

/**
 * @brief A right arrow indicating progress in a machine.
 */
template<typename TProgress>
class ProgressIndicator : public Widget
{
private:
    const TProgress &m_currentProgress;
    const TProgress &m_maxProgress;

public:
    /**
     * @brief Construct this process indicator.
     * 
     * @param currentProgress Reference to the current progress.
     * @param maxProgress Reference to the 'completed' progress.
     */
    ProgressIndicator(const TProgress &currentProgress, const TProgress &maxProgress) :
        m_currentProgress(currentProgress),
        m_maxProgress(maxProgress)
    {}

    virtual void draw(GraphicsContext &context) override
    {
        context.color = glm::vec4(1.0f);
        context.drawMaterial(Material::progress, 0, 0, 10, 8, 0, 0, 10, 8);
        
        int width = std::max(0, std::min(10, static_cast<int>(m_currentProgress * 10 / m_maxProgress)));
        context.drawMaterial(Material::progress, 0, 8, width, 8, 0, 0, width, 8);

        if (isMouseInside())
        {
            ToolTip &tip = context.createToolTip();
            tip.addLine(formatString("$+/$+", m_currentProgress, m_maxProgress));
        }
    }

    virtual glm::ivec2 getMinSize() override
    {
        return glm::ivec2(10, 8);
    }
};

#endif