package com.acethewildfire.acesbs.screen.custom;

import com.acethewildfire.acesbs.component.ModDataComponentTypes;
import com.acethewildfire.acesbs.util.ModPackets;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.item.ItemStack;

import net.minecraft.text.Text;

import java.util.Map;
import java.util.TreeMap;

public class CommandCoreScreen extends Screen {


    private final ItemStack stack;
    private final TreeMap<String, String> options;

    public CommandCoreScreen(ItemStack stack) {
        super(Text.literal("Select Option"));
        this.stack = stack;
        this.options = new TreeMap<>();
        options.put("Sight", "Blindness has no effect on you");
        options.put("Omnipotence", "Hit entities will glow for 30 seconds");
//        options.put("Intimidate", "Warn any would be foes that you mean business");
        options.put("Immunity", "Poison and Wither have no effect on you");
        options.put("Immovable", "You cannot be moved against your will");
        options.put("Unstoppable", "You cannot be stopped by obstacles");
        options.put("Grounded", "You always have sure footing");
        options.put("Arborist", "You have an affinity with plants");
        options.put("Wither", "Causes foes to wither away");
        options.put("Immolate", "Causes foes to sacrifice themselves to you");
        options.put("Begone", "Removes a foe from your sight");
        options.put("Scorch", "Attackers are set on fire");
        options.put("Terrify", "Show a foe your true appearance");
        options.put("Grovel", "Forces a foe to collapse under your might");
        options.put("Satisfy", "Bless an ally with a full stomach");
        options.put("Soothe", "Soothe an ally, healing their wounds");
        options.put("Leap", "Launch yourself into the air");
        options.put("Lunge", "Launch yourself forward");

//        options.put("", "");




        options.put("TEST", "Set yourself on fire");
    }

    @Override
    protected void init() {
        int y = 20;
        int x = this.width / 4 - 50;
        int count = 8;

        for (Map.Entry<String, String> entry : options.entrySet()) {
            String option = entry.getKey();
            String tooltip = entry.getValue();

            ButtonWidget button = ButtonWidget.builder(
                            Text.literal(option), // Button text
                            button1 -> {
                                ClientPlayNetworking.send(new ModPackets.SetCommandPayload(option));
                                MinecraftClient.getInstance().setScreen(null); // Close screen
                            }
                    )
                    .size(100, 20) // width, height
                    .position(x, y) // x, y
                    .tooltip(Tooltip.of(Text.literal(tooltip)))
                    .build();

            this.addDrawableChild(button);
            y += 24;
            count -= 1;
            if (count <= 0){
                count = 8;
                y = 20;
                x = x + (this.width / 4);
            }
        }
    }

    @Override
    public boolean shouldPause() {
        return false; // Doesn't pause the game
    }


}
