#include <Block/SpriteBlock/CombustionGenerator/CombustionGenerator.hpp>
#include <BlockRegistry/BlockRegistry.hpp>
#include <Item/StatefulItem/Battery/Battery.hpp>
#include <ItemStack/ItemStack.hpp>
#include <Widget/BatteryView/BatteryView.hpp>
#include <Widget/DownArrow/DownArrow.hpp>
#include <Widget/FlameStatusIndicator/FlameStatusIndicator.hpp>
#include <Widget/FluidLevelIndicator/FluidLevelIndicator.hpp>
#include <Widget/ItemIcon/ItemIcon.hpp>
#include <Widget/Label/Label.hpp>
#include <Widget/Layout/Center/Center.hpp>
#include <Widget/Layout/Column/Column.hpp>
#include <Widget/Layout/CompoundWidget/Deck/Deck.hpp>
#include <Widget/Layout/CompoundWidget/DocCombustionGeneratorDiagram/DocCombustionGeneratorDiagram.hpp>
#include <Widget/Layout/CompoundWidget/Form/Form.hpp>
#include <Widget/Layout/CompoundWidget/IconText/IconText.hpp>
#include <Widget/Layout/Frame/Frame.hpp>
#include <Widget/Layout/PotView/PotView.hpp>
#include <Widget/Layout/Row/Row.hpp>
#include <Widget/Panel/Panel.hpp>
#include <Widget/StaticItemSlot/StaticItemSlot.hpp>
#include <Machine/MCombustionGenerator/MCombustionGenerator.hpp>

DocCombustionGeneratorDiagram::DocCombustionGeneratorDiagram(const std::vector<std::string> &args)
{
    static std::string petrolName = "main:petrol";
    static int petrolLevel = MCombustionGenerator::fluidCapacity - 6200;

    static int energy = MCombustionGenerator::energyCapacity - 400;

    addChildren(
        new Frame(
            new Form(
                new IconText(
                    blockRegistry.getBlockByName("main:combustionGenerator").iconMaterial,
                    "Combustion Generator"
                ),
                new Center(
                    new Deck<Column, Center>(
                        new Panel(glm::ivec2(100, 0)),
                        new Row(
                            new Center(
                                new Column(
                                    new Center(
                                        (new StaticItemSlot(
                                            []()
                                            {
                                                ItemStack stack = *ItemStack::fromItemOrBlockName("main:capsuleLargeTin");
                                                stack.trySetOption("fluid=main:petrol");
                                                return stack;
                                            }
                                        ))
                                            ->withStaticHighlight(Color::petrolHighlight)
                                    ),
                                    new Center(new DownArrow()),
                                    new Center(new FluidLevelIndicator(
                                        petrolName,
                                        petrolLevel,
                                        MCombustionGenerator::fluidCapacity
                                    ))
                                )
                            ),

                            new Center(new IconLabel(Material::rightArrow)),

                            new Center(
                                new Column(
                                    new Center(new BatteryView(
                                        energy,
                                        MCombustionGenerator::energyCapacity
                                    )),
                                    new Center(new DownArrow()),
                                    new Center(
                                        (new StaticItemSlot(
                                            []()
                                            {
                                                ItemStack battery = *ItemStack::fromItemOrBlockName("main:battery");
                                                battery.trySetOption(formatString("energy=$+", Battery::capacity));
                                                return battery;
                                            }
                                        ))
                                            ->withStaticHighlight(Color::rechargeHighlight)
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )
    );
}