#include <Item/StatefulItem/PlutoniumCaptureCell/PlutoniumCaptureCell.hpp>
#include <Machine/MNuclearReactor/MNuclearReactor.hpp>
#include <Controller/InventoryController/NuclearReactorController/NuclearReactorController.hpp>

PlutoniumCaptureCell::PlutoniumCaptureCell(std::string name) : StatefulItem(name)
{
    setMaxStackSize(1);
}

void PlutoniumCaptureCell::describeInNuclearReactor(ItemStack &stack, std::ostream &os)
{
    os << "Generates plutonium for each uranium burned." << std::endl;
}

bool PlutoniumCaptureCell::updateNuclearReactor(ItemStack &stack, MNuclearReactor &reactor, glm::ivec2 cellPos)
{
    reactor.plutoniumCaptureCells++;
    return true;
}

float PlutoniumCaptureCell::getHeatConductivity(ItemStack &stack)
{
    return 0.2f;
}

std::string PlutoniumCaptureCell::getDisplayName(const ItemStack &stack)
{
    return "Plutonium Capture Cell";
}

void PlutoniumCaptureCell::draw(GraphicsContext &context, int x, int y, const ItemStack &stack)
{
    context.color = glm::vec4(1.0f);
    context.drawMaterial(Material::plutoniumCaptureCell, x, y);

    uint32_t usesLeft = maxDamage - state(stack);
    if (usesLeft == maxDamage)
    {
        return;
    }

    context.color = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
    context.drawRect(x, y+6, 8, 2);

    context.color = Color::warning;
    context.drawRect(x, y+6, 8 * usesLeft / maxDamage, 2);
}

void PlutoniumCaptureCell::draw3D(GraphicsContext &context, WorldDisplay &worldDisplay, glm::vec3 pos, ItemStack &stack)
{
    worldDisplay.drawMeshedIcon(context, Material::plutoniumCaptureCell, pos);
}

void PlutoniumCaptureCell::drawFlat(GraphicsContext &context, WorldDisplay &worldDisplay, glm::mat4 matrix, ItemStack &stack)
{
    worldDisplay.drawMeshedIconFlat(context, Material::plutoniumCaptureCell, matrix);
}