package asm.mixins;

import dev.crucifixbeta.mod.gui.accounts.AccountsScreen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Environment(EnvType.CLIENT)
@Mixin({MultiplayerScreen.class})
public abstract class MixinMultiplayerScreen extends Screen {
   protected MixinMultiplayerScreen(Text title) {
      super(title);
   }

   @Inject(
      method = {"init"},
      at = {@At("TAIL")}
   )
   private void crucifix$addTokenLoginButton(CallbackInfo ci) {
      byte var2 = 75;
      byte var3 = 3;
      byte var4 = 16;
      this.addDrawableChild(ButtonWidget.builder(Text.literal("Accounts"), button -> {
         if (this.client != null) {
            this.client.setScreen(new AccountsScreen(this));
         }
      }).dimensions(var3, var4, var2, 20).build());
   }

   @Inject(
      method = {"render"},
      at = {@At("TAIL")}
   )
   private void crucifix$renderLoggedInAs(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
      if (this.client != null) {
         String var6 = "Logged in as ";
         String var7 = this.client.getSession().getUsername();
         byte var8 = 3;
         byte var9 = 3;
         context.drawTextWithShadow(this.textRenderer, var6, var8, var9, -1);
         context.drawTextWithShadow(this.textRenderer, var7, var8 + this.textRenderer.getWidth(var6), var9, -5197648);
      }
   }
}
