#include <MapTool/MapPanTool/MapPanTool.hpp>
#include <MapTool/MapPinTool/MapPinTool.hpp>
#include <MapTool/MapTool.hpp>
#include <Widget/IconToggle/IconToggle.hpp>
#include <Widget/Layout/Column/Column.hpp>
#include <Widget/Layout/CompoundWidget/MapToolBox/MapToolBox.hpp>
#include <Widget/Layout/Row/Row.hpp>

Widget* MapToolBox::makeToolToggle(MapTool* &value, MapTool *tool)
{
    return (new IconToggle<MapTool*>(
        value,
        tool,
        tool->getIcon()
    ))
        ->withToolTip(tool->getName());
}

MapToolBox::MapToolBox(MapTool* &tool, IEquipment::MapLevel level)
{
    std::vector<MapTool*> tools = {
        &MapPanTool::instance,
        &MapPinTool::instance,
    };

    std::vector<Widget*> rows;
    for (size_t i = 0; i < tools.size(); i++)
    {
        if (level < tools[i]->getRequiredMapLevel())
        {
            continue;
        }

        rows.push_back(makeToolToggle(tool, tools[i]));
    }

    addChildren(new Column(rows));
}