package dev.crucifixbeta.core.impl;

import dev.crucifixbeta.api.utils.Wrapper;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.util.Identifier;
import org.ladysnake.satin.api.managed.ManagedShaderEffect;
import org.ladysnake.satin.api.managed.ShaderEffectManager;

@Environment(EnvType.CLIENT)
public class BlurManager implements Wrapper {
   public static final ManagedShaderEffect BLUR;

   public void applyBlur(float radius, float startX, float startY, float width, float height) {
      this.applyBlur(radius, startX, startY, width, height, 0.0F);
   }

   public void applyBlur(float radius, float startX, float startY, float width, float height, float blurType) {
      if (mc != null && mc.getWindow() != null && !(width <= 0.0F) && !(height <= 0.0F) && !(radius <= 0.0F)) {
         float var7 = (float)mc.getWindow().getScaleFactor();
         float var8 = startX * var7;
         float var9 = (float)mc.getWindow().getHeight() - (startY + height) * var7;
         BLUR.setUniformValue("Radius", Math.max(0.0F, radius));
         BLUR.setUniformValue("BlurType", blurType);
         BLUR.setUniformValue("BlurXY", var8, var9);
         BLUR.setUniformValue("BlurCoord", width * var7, height * var7);
         BLUR.render(mc.getRenderTickCounter().getTickDelta(true));
      }
   }

   static {

      BLUR = ShaderEffectManager.getInstance().manage(Identifier.of("shaders/post/blurarea.json"));
   }
}
