#include <BlockRegistry/BlockRegistry.hpp>
#include <GraphicsContext/GraphicsContext.hpp>
#include <ItemStack/ItemStack.hpp>
#include <Machine/MItemProcessor/MMacerator/MMacerator.hpp>
#include <Widget/BatteryView/BatteryView.hpp>
#include <Widget/ItemIcon/ItemIcon.hpp>
#include <Widget/Layout/CompoundWidget/DocItemProcDiagram/DocItemProcDiagram.hpp>
#include <Widget/Layout/CompoundWidget/Form/Form.hpp>
#include <Widget/Layout/CompoundWidget/FormSection/FormSection.hpp>
#include <Widget/Layout/CompoundWidget/IconText/IconText.hpp>
#include <Widget/Layout/Frame/Frame.hpp>
#include <Widget/Panel/Panel.hpp>
#include <Widget/ProgressIndicator/ProgressIndicator.hpp>
#include <Widget/StaticItemSlot/StaticItemSlot.hpp>
#include <Item/StatefulItem/Battery/Battery.hpp>

DocItemProcDiagram::DocItemProcDiagram(const std::vector<std::string> &args)
{
    static int storedEnergy = 3000;
    static int progress = MMacerator::completedProgress / 2;

    machineStack = blockRegistry.getBlockByName(args[1]).toItemStack();
    ItemStack inputStack = *ItemStack::fromItemOrBlockName(args[2], std::stoi(args[3]));
    ItemStack 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 Row(
                    new Center(
                        new FormSection(
                            new Column(
                                new Center(
                                    (new StaticItemSlot(
                                        []()
                                        {
                                            return *ItemStack::fromItemOrBlockName("main:battery");
                                        }
                                    ))
                                        ->withStaticHighlight(Color::rechargeHighlight)
                                ),
                                new Center(new IconLabel(Material::downArrow)),
                                new Panel(glm::ivec2(0, 2)),
                                new Center(new BatteryView(storedEnergy, MMacerator::energyCapacity, 1000))
                            )
                        )
                    ),

                    Layout::WithProportion<1>(),
                    new Center(
                        new FormSection(
                            new Row(
                                new Center(
                                    (new StaticItemSlot(
                                        [inputStack]()
                                        {
                                            return inputStack;
                                        }
                                    ))
                                        ->withStaticHighlight(Color::inputHighlight)
                                ),
                                new Center(new ProgressIndicator<int>(progress, MMacerator::completedProgress)),
                                new Center(
                                    (new StaticItemSlot(
                                        [outputStack]()
                                        {
                                            return outputStack;
                                        }
                                    ))
                                        ->withStaticHighlight(Color::faded)
                                )
                            )
                        )
                    ),

                    new Center(
                        new FormSection(
                            new Deck<Column, Center>(
                                new IconLabel(Material::upgradeIcon),
                                (new StaticItemSlot(
                                    []()
                                    {
                                        return *ItemStack::fromItemOrBlockName("main:speedUpgrade", 64);
                                    }
                                ))->withStaticHighlight(Color::upgradeHighlight),
                                (new StaticItemSlot(
                                    []()
                                    {
                                        return *ItemStack::fromItemOrBlockName("main:efficiencyUpgrade", 64);
                                    }
                                ))->withStaticHighlight(Color::upgradeHighlight),
                                (new StaticItemSlot(
                                    []()
                                    {
                                        return ItemStack();
                                    }
                                ))
                                    ->withStaticHighlight(Color::upgradeHighlight)
                                    ->withEmptyToolTip(GraphicsContext::colorstr(Color::upgradeHighlight) + "Upgrades"),
                                (new StaticItemSlot(
                                    []()
                                    {
                                        return ItemStack();
                                    }
                                ))
                                    ->withStaticHighlight(Color::upgradeHighlight)
                                    ->withEmptyToolTip(GraphicsContext::colorstr(Color::upgradeHighlight) + "Upgrades")
                            )
                        )
                    )
                )
            )
        )
    );
}