package de.winniepat.citrus.gui;

import de.winniepat.citrus.draggui.HudConfig;
import de.winniepat.citrus.draggui.HudUtils;
import de.winniepat.citrus.utils.text.TextComponent;
import io.wispforest.owo.ui.base.BaseOwoScreen;
import io.wispforest.owo.ui.container.Containers;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.core.*;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;

public class ModuleToggleScreen extends BaseOwoScreen<FlowLayout> {

    @Override
    protected @NotNull OwoUIAdapter<FlowLayout> createAdapter() { return OwoUIAdapter.create(this, Containers::verticalFlow); }

    @Override
    protected void build(FlowLayout root) {
        root.horizontalAlignment(HorizontalAlignment.CENTER)
                .verticalAlignment(VerticalAlignment.CENTER);

        FlowLayout content = (FlowLayout) Containers.verticalFlow(Sizing.content(), Sizing.content())
                .padding(Insets.of(12))
                .surface(Surface.DARK_PANEL)
                .horizontalAlignment(HorizontalAlignment.CENTER);
        content.gap(3);

        var mainTitle = new TextComponent(Text.literal("Module Toggles")).scale(1.8f).horizontalSizing(Sizing.fixed(140)).margins(Insets.of(10));

        content.child(mainTitle).gap(10);

        FlowLayout firstRow = Containers.horizontalFlow(Sizing.content(), Sizing.content());
        firstRow.gap(6);
        content.child(firstRow);

        FlowLayout secondRow = Containers.horizontalFlow(Sizing.content(), Sizing.content());
        secondRow.gap(6);
        content.child(secondRow);

        HudConfig c = HudConfig.INSTANCE;

        firstRow.child(HudUtils.createButton("FPS", "fps", "Frames per second", c.fpsEnabled, state -> c.fpsEnabled = state));
        firstRow.child(HudUtils.createButton("Ping", "ping", "Your latency", c.pingEnabled, state -> c.pingEnabled = state));
        firstRow.child(HudUtils.createButton("Server", "server", "Server address", c.serverEnabled, state -> c.serverEnabled = state));

        secondRow.child(HudUtils.createButton("Keys", "key", "Keystrokes", c.keyEnabled, state -> c.keyEnabled = state));
        secondRow.child(HudUtils.createButton("Armor", "armor", "Armor status", c.armorEnabled, state -> c.armorEnabled = state));
        secondRow.child(HudUtils.createButton("Potion", "potion", "Active effects", c.potionEnabled, state -> c.potionEnabled = state));

        root.child(content);
    }
}
