package top.leisuretimedock.dglabgame.core.event;

import com.lowdragmc.lowdraglib.gui.modular.IUIHolder;
import com.lowdragmc.lowdraglib.gui.modular.ModularUI;
import com.lowdragmc.lowdraglib.gui.modular.ModularUIGuiContainer;
import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.loading.FMLEnvironment;
import top.leisuretimedock.dglabgame.DGLabGame;
import top.leisuretimedock.dglabgame.client.DLGKeyMapping;
import top.leisuretimedock.dglabgame.client.gui.ConfirmGui;
import top.leisuretimedock.dglabgame.client.gui.DGLabManagementGui;
import top.leisuretimedock.dglabgame.core.capability.DGLabDataProvider;

public class ClientEventHandler {
    @net.minecraftforge.fml.common.Mod.EventBusSubscriber(modid = DGLabGame.MOD_ID, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
    public static class Game extends ClientEventHandler {
        @SubscribeEvent
        public static void onKetBoardInput(InputEvent.Key event) {
            Minecraft minecraft = Minecraft.getInstance();
            LocalPlayer player = minecraft.player;
            if(player == null) return;
            if (DLGKeyMapping.KEY_TEST.isDown() && !FMLEnvironment.production) {
                player.getCapability(DGLabDataProvider.DG_LAB_DATA_CAPABILITY).ifPresent(data -> {
                    if (!data.hasAcceptUseAgreements()) {
                        new ConfirmGui().display();
                    } else player.displayClientMessage(Component.literal("You had accept use agreements").withStyle(ChatFormatting.RED).withStyle(ChatFormatting.BOLD), true);
                });
            }
            if (DLGKeyMapping.KEY_MANAGEMENT.isDown()) {
                player.getCapability(DGLabDataProvider.DG_LAB_DATA_CAPABILITY).ifPresent(data -> {
                    if (data.hasAcceptUseAgreements()) {
                        new DGLabManagementGui().display();
                    } else {
                        player.displayClientMessage(Component.translatable("dglabgame.user_agreement.reject_use").withStyle(ChatFormatting.RED), true);
                    }
                });
            }
        }
    }
    @net.minecraftforge.fml.common.Mod.EventBusSubscriber(modid = DGLabGame.MOD_ID, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
    public static class Mod extends ClientEventHandler {
        @SubscribeEvent
        public static void onRegisterKeyMappings (RegisterKeyMappingsEvent event) {
            event.register(DLGKeyMapping.KEY_TEST);
            event.register(DLGKeyMapping.KEY_MANAGEMENT);
        }
    }

}
