#include <Block/SpriteBlock/SteamGenerator/SteamGenerator.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/DocSteamGeneratorDiagram/DocSteamGeneratorDiagram.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/MSteamGenerator/MSteamGenerator.hpp>

DocSteamGeneratorDiagram::DocSteamGeneratorDiagram(const std::vector<std::string> &args)
{
    static uint32_t fuelCurrent = 1000;
    static uint32_t fuelBatch = 1200;
    static uint32_t temperature = 3000;

    static std::string waterName = "main:water";
    static int waterAmount = MSteamGenerator::waterCapacity - 6200;

    static int energy = MSteamGenerator::energyCapacity - 400;

    addChildren(
        new Frame(
            new Form(
                new IconText(Material::steamGeneratorTodo, "Steam Generator"),
                new Center(
                    new Deck<Column, Center>(
                        new Panel(glm::ivec2(100, 0)),
                        new Deck<Row, Center>(
                            new Column(
                                new Row(
                                    (new StaticItemSlot(
                                        []()
                                        {
                                            ItemStack stack = *ItemStack::fromItemOrBlockName("main:capsuleLargeTin");
                                            stack.trySetOption("fluid=main:water");
                                            return stack;
                                        }
                                    ))
                                        ->withStaticHighlight(Color::inputHighlight)
                                ),

                                new Center(new DownArrow()),

                                new PotView(
                                    temperature,
                                    new Row(
                                        new Panel(glm::ivec2(5, 0)),
                                        new Column(
                                            new FluidLevelIndicator(waterName, waterAmount, MSteamGenerator::waterCapacity),
                                            new Panel(glm::ivec2(0, 3))
                                        )
                                    )
                                ),

                                new Row(
                                    new Panel(glm::ivec2(6, 1)),
                                    new FlameStatusIndicator<uint32_t>(
                                        fuelCurrent,
                                        fuelBatch
                                    )
                                ),

                                new Row(
                                    (new StaticItemSlot(
                                        []()
                                        {
                                            return *ItemStack::fromItemOrBlockName("main:coal", 12);
                                        }
                                    ))
                                        ->withStaticHighlight(Color::fuelHighlight)
                                )
                            ),

                            new IconLabel(Material::rightArrow),

                            new Column(
                                new Center(new BatteryView(energy, MSteamGenerator::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)
                                )
                            )
                        )
                    )
                )
            )
        )
    );
}