package asm.mixins;

import dev.crucifixbeta.mod.gui.acrylic.AcrylicRuntime;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.WindowEventHandler;
import net.minecraft.client.WindowSettings;
import net.minecraft.client.util.MonitorTracker;
import net.minecraft.client.util.Window;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Environment(EnvType.CLIENT)
@Mixin({Window.class})
public class MixinWindow {
   @Shadow
   private long handle;

   @Inject(
      method = {"<init>"},
      at = {@At(
         value = "INVOKE",
         target = "Lorg/lwjgl/glfw/GLFW;glfwDefaultWindowHints()V",
         shift = Shift.AFTER,
         remap = false
      )},
      require = 0
   )
   private void crucifix$enableTransparentFramebuffer(
      WindowEventHandler eventHandler, MonitorTracker monitorTracker, WindowSettings settings, String fullscreenVideoMode, String title, CallbackInfo ci
   ) {
      AcrylicRuntime.applyWindowHints();
   }

   @Inject(
      method = {"<init>"},
      at = {@At("TAIL")},
      require = 0
   )
   private void crucifix$initAcrylic(
      WindowEventHandler eventHandler, MonitorTracker monitorTracker, WindowSettings settings, String fullscreenVideoMode, String title, CallbackInfo ci
   ) {
      AcrylicRuntime.init(this.handle);
   }
}
