#include <Controller/InventoryController/InventoryController.hpp>
#include <Controller/InventoryController/NuclearReactorController/NuclearReactorController.hpp>
#include <Widget/StaticItemSlot/ItemSlot/TemperatureItemSlot/TemperatureItemSlot.hpp>

void TemperatureItemSlot::addTemperatureToToolTip(ToolTip &tip)
{
    tip.addLine(Color::temperature, formatTemperature(ctrl->slotTemperatures[m_slot]));
}

TemperatureItemSlot::TemperatureItemSlot(NuclearReactorController *ctrl, int slot) :
    ItemSlot(ctrl, "machine", slot),
    ctrl(ctrl)
{}

void TemperatureItemSlot::draw(GraphicsContext &context)
{
    int temperature = ctrl->slotTemperatures[m_slot];
    if (temperature <= 300)
    {
        float intensity = (float) (300 - temperature) / 300.0f;
        context.color = glm::vec4(0.0f, 0.0f, 1.0f, intensity);
    }
    else
    {
        float intensity = std::min(1.0f, (float) (temperature - 300) / (float) (MNuclearReactor::criticalTemperature - 300));
        context.color = glm::vec4(1.0f, 0.0f, 0.0f, intensity);
    }

    context.drawRect(0, 0, m_size.x, m_size.y);

    ItemSlot::draw(context);
}

void TemperatureItemSlot::onHoveringOverEmpty(GraphicsContext &context)
{
    ToolTip &tip = context.createToolTip();
    addTemperatureToToolTip(tip);
}

void TemperatureItemSlot::getExtraToolTipLines(ToolTip &tip)
{
    addTemperatureToToolTip(tip);
    ItemSlot::getExtraToolTipLines(tip);
}