#include <BlockRegistry/BlockRegistry.hpp>
#include <Widget/BatteryView/BatteryView.hpp>
#include <Widget/DownArrow/DownArrow.hpp>
#include <Widget/FluidLevelIndicator/FluidLevelIndicator.hpp>
#include <Widget/Layout/CompoundWidget/DocOilRefineryDiagram/DocOilRefineryDiagram.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/StaticItemSlot/StaticItemSlot.hpp>
#include <Machine/MOilRefinery/MOilRefinery.hpp>

DocOilRefineryDiagram::DocOilRefineryDiagram(const std::vector<std::string> &args)
{
    static std::string oilName = "main:oil";
    static std::string petrolName = "main:petrol";
    static int oilAmount = 300;
    static int petrolAmount = 1000;
    static int storedEnergy = MOilRefinery::energyCapacity;

    addChildren(
        new Frame(
            new Form(
                new IconText(
                    blockRegistry.getBlockByName("main:oilRefinery").iconMaterial,
                    "Oil Refinery"
                ),
                new Column(
                    Layout::WithProportion<1>(),
                    new Center(
                        new FormSection(
                            new Row(
                                new Column(
                                    new Center(
                                        (new StaticItemSlot(
                                            []()
                                            {
                                                ItemStack stack = *ItemStack::fromItemOrBlockName("main:capsuleLargeTin");
                                                stack.trySetOption("fluid=main:oil");
                                                return stack;
                                            }
                                        ))
                                            ->withStaticHighlight(Color::oilHighlight)
                                    ),
                                    new Center(new DownArrow()),
                                    new Row(
                                        Layout::WithProportion<1>(),
                                        new Panel(),
                                        new FluidLevelIndicator(oilName, oilAmount, MOilRefinery::fluidCapacity)
                                    )
                                ),

                                new IconLabel(Material::distiller),

                                new Column(
                                    new Row(
                                        new FluidLevelIndicator(petrolName, petrolAmount, MOilRefinery::fluidCapacity)
                                    ),
                                    new DownArrow(),
                                    new Center(
                                        (new StaticItemSlot(
                                            []()
                                            {
                                                ItemStack stack = *ItemStack::fromItemOrBlockName("main:capsuleLargeTin");
                                                stack.trySetOption("fluid=main:petrol");
                                                return stack;
                                            }
                                        ))
                                            ->withStaticHighlight(Color::petrolHighlight)
                                    )
                                )
                            )
                        )
                    ),
                    new Center(
                        new FormSection(
                            new Row(
                                new Center(
                                    (new StaticItemSlot(
                                        []()
                                        {
                                            return *ItemStack::fromItemOrBlockName("main:battery");
                                        }
                                    ))
                                        ->withStaticHighlight(Color::petrolHighlight)
                                ),
                                new Panel(glm::ivec2(2, 0)),
                                new Center(new IconLabel(Material::rightArrow)),
                                new Panel(glm::ivec2(2, 0)),
                                new Center(new BatteryView(storedEnergy, MOilRefinery::energyCapacity))
                            )
                        )
                    )
                )
            )
        )
    );
}