#ifndef FLAME_STATUS_INDICATOR_HPP_
#define FLAME_STATUS_INDICATOR_HPP_

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

/**
 * @brief A flame indicating the fuel content in a pot or steam engine.
 */
template<typename TProgress>
class FlameStatusIndicator : public Widget
{
private:
    TProgress &m_fuelCurrent;
    TProgress &m_fuelBatch;

private:
    float getFuelProportion()
    {
        if (m_fuelCurrent == m_fuelBatch)
        {
            return m_fuelCurrent * 1;
        }

        return (float) m_fuelCurrent / (float) m_fuelBatch;
    }

public:
    /**
     * @brief Construct this flame status indicator.
     * 
     * @param fuelCurrent Reference to the current amount of fuel.
     * @param fuelBatch Reference to the amount of fuel in a batch.
     */
    FlameStatusIndicator(TProgress &fuelCurrent, TProgress &fuelBatch) :
        m_fuelCurrent(fuelCurrent),
        m_fuelBatch(fuelBatch)
    {}

    virtual void draw(GraphicsContext &context) override
    {
        context.color = glm::vec4(1.0f);
        context.drawMaterial(Material::flameStatus, 0, 12, 8, 12, 0, 0, 8, 12);
        
        int height = std::max(0, std::min(12, static_cast<int>(getFuelProportion() * 12)));
        context.drawMaterial(Material::flameStatus, 0, 12-height, 8, height, 0, 12-height, 8, height);

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

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

#endif