package net.puzzlemc.gui.screen;

import net.puzzlemc.gui.PuzzleApi;
import net.minecraft.client.gui.screen.ScreenTexts;
import net.minecraft.text.TranslatableText;
import net.puzzlemc.gui.PuzzleClient;
import net.puzzlemc.gui.screen.page.GraphicsPage;
import net.puzzlemc.gui.screen.page.MiscPage;
import net.puzzlemc.gui.screen.page.PerformancePage;
import net.puzzlemc.gui.screen.page.ResourcesPage;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;

import java.util.Objects;

public class PuzzleOptionsScreen extends Screen {

    public PuzzleOptionsScreen(Screen parent) {
        super(new TranslatableText("puzzle.screen.title"));
        this.parent = parent;
    }
    private final Screen parent;

    @Override
    protected void init() {
        super.init();
        if (!PuzzleClient.lateInitDone) PuzzleClient.lateInit();
        GraphicsPage graphicsPage = new GraphicsPage(this);
        MiscPage miscPage = new MiscPage(this);
        PerformancePage performancePage = new PerformancePage(this);
        ResourcesPage resourcesPage = new ResourcesPage(this);

        if (!PuzzleApi.GRAPHICS_OPTIONS.isEmpty()) this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 48 - 6, 150, 20, graphicsPage.getTitle().copy().append("..."), (button) -> Objects.requireNonNull(client).setScreen(graphicsPage)));
        if (!PuzzleApi.RESOURCE_OPTIONS.isEmpty()) this.addDrawableChild(new ButtonWidget(this.width / 2 + 5, this.height / 6 + 48 - 6, 150, 20, resourcesPage.getTitle().copy().append("..."), (button) -> Objects.requireNonNull(client).setScreen(resourcesPage)));
        if (!PuzzleApi.PERFORMANCE_OPTIONS.isEmpty()) this.addDrawableChild(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 72 - 6, 150, 20, performancePage.getTitle().copy().append("..."), (button) -> Objects.requireNonNull(client).setScreen(performancePage)));
        if (!PuzzleApi.MISC_OPTIONS.isEmpty()) this.addDrawableChild(new ButtonWidget(this.width / 2 + 5, this.height / 6 + 72 - 6, 150, 20, miscPage.getTitle().copy().append("..."), (button) -> Objects.requireNonNull(client).setScreen(miscPage)));
        this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts.DONE, (button) -> Objects.requireNonNull(client).setScreen(parent)));
    }

    @Override
    public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
        this.renderBackground(matrices);

        super.render(matrices, mouseX, mouseY, delta);
        drawCenteredText(matrices, textRenderer, title, width/2, 15, 0xFFFFFF);
    }
}
