#include <ItemStack/ItemStack.hpp>
#include <Widget/IconLabel/IconLabel.hpp>
#include <Widget/ItemIcon/ItemIcon.hpp>
#include <Widget/Label/Label.hpp>
#include <Widget/Layout/CompoundWidget/DocItemProcTag/DocItemProcTag.hpp>
#include <BlockRegistry/BlockRegistry.hpp>
#include <Widget/Layout/CompoundWidget/Form/Form.hpp>
#include <Widget/Panel/Panel.hpp>
#include <Widget/StaticItemSlot/StaticItemSlot.hpp>

DocItemProcTag::DocItemProcTag(const std::vector<std::string> &args)
{
    if (args.size() != 6)
    {
        addChildren(new Label("<!!!>", Color::error));
        return;
    }

    machineStack = blockRegistry.getBlockByName(args[1]).toItemStack();
    inputStack = *ItemStack::fromItemOrBlockName(args[2], std::stoi(args[3]));
    outputStack = *ItemStack::fromItemOrBlockName(args[4], std::stoi(args[5]));

    addChildren(
        new Frame(
            new Form(
                new Row(
                    new ItemIcon(machineStack),
                    new Panel(glm::ivec2(1, 0)),
                    new Label(machineStack.getDisplayName())
                ),
                new Column(
                    new Panel(glm::ivec2(100, 0)),
                    new Center(
                        new Deck<Row, Center>(
                            new StaticItemSlot(
                                [this]() { return inputStack; }
                            ),
                            new IconLabel(Material::rightArrow),
                            new StaticItemSlot(
                                [this]() { return outputStack; }
                            )
                        )
                    )
                )
            )
        )
    );
}