#include "tank.h"
#include "../items.h"
#include <cstdio>
#include <imgui/imgui.h>
#include <color.h>

namespace game{

void tank::select() noexcept
{
    _needShowGui = true;
    currentlyShown = this;
}

void tank::_drawWindow()
{
    ImGui::SetNextWindowSizeConstraints(ImVec2(256,160), ImVec2(256,800));
    if(ImGui::Begin(u8"Цистерна", &_needShowGui, ImVec2(256,160)))
    {
        if(_item != 0xFFFFFFFF)
        {
            ImGui::Text(getItemById(_item)->name.c_str());
            ImGui::SameLine();
        }

        ImGui::ProgressBar(getFilledSpace());

        ImGui::Separator();

        ImGui::PushStyleColor(ImGuiCol_Button, color::uint2rgba(0xe43b44));
        ImGui::PushStyleColor(ImGuiCol_ButtonHovered, color::uint2rgba(0xe43b44));
        ImGui::PushStyleColor(ImGuiCol_ButtonActive, color::uint2rgba(0xe43b44));

        if(ImGui::Button(u8"Сломать"))
            onCellDestroyed();
        ImGui::SameLine();
        if(ImGui::Button(u8"Очистить"))
            _amount = 0;

        ImGui::PopStyleColor(3);
    }
    else
    {
        if(!ImGui::IsWindowCollapsed())
            _needShowGui = false;
    }

    ImGui::End();
}

void tank::_drawShortInfo()
{
    if(ImGui::Begin(u8"Цистерна ", 0, ImVec2(160,80), -1, ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_NoCollapse))
    {
        ImGui::SetWindowSize(ImVec2(160,0), ImGuiCond_Always);
        ImGui::SetWindowPos(ImVec2(0,20), ImGuiCond_Always);
        if(_item != 0xFFFFFFFF)
            ImGui::Text(getItemById(_item)->name.c_str());

        ImGui::ProgressBar(getFilledSpace());
    }
    ImGui::End();
}

}
