#include <BlockRegistry/BlockRegistry.hpp>
#include <ItemStack/ItemStack.hpp>
#include <Widget/IconLabel/IconLabel.hpp>
#include <Widget/ItemIcon/ItemIcon.hpp>
#include <Widget/Label/Label.hpp>
#include <Widget/Layout/CompoundWidget/DocItemListTag/DocItemListTag.hpp>
#include <Widget/Layout/CompoundWidget/Form/Form.hpp>
#include <Widget/Layout/CompoundWidget/IconText/IconText.hpp>
#include <Widget/Layout/Frame/Frame.hpp>
#include <Widget/Panel/Panel.hpp>
#include <Widget/StaticItemSlot/StaticItemSlot.hpp>
#include <string>

DocItemListTag::DocItemListTag(const std::vector<std::string> &args)
{
    if ((args.size() % 2) != 0 || args.size() < 2)
    {
        addChildren(new Label("<!!!>", Color::error));
        return;
    }

    ItemStack machineStack = blockRegistry.getBlockByName(args[1]).toItemStack();

    std::vector<Widget*> inputs;
    for (size_t i = 2; i < args.size(); i += 2)
    {
        ItemStack stack = *ItemStack::fromItemOrBlockName(args[i], std::stoi(args[i + 1]));
        inputs.push_back(new StaticItemSlot([stack]() { return stack; }));
    }

    addChildren(
        new Frame(
            new Form(
                new Deck<Row, Center>(
                    new ItemIcon(machineStack),
                    new Panel(glm::ivec2(1, 0)),
                    new Label(machineStack.getDisplayName())
                ),
                new Column(
                    new Panel(glm::ivec2(120, 0)),
                    new Center(
                        new Row(inputs)
                    )
                )
            )
        )
    );
}