package dev.crucifixbeta.mod.modules.impl.render;

import dev.crucifixbeta.CrucifixBeta;
import dev.crucifixbeta.api.events.eventbus.EventListener;
import dev.crucifixbeta.api.events.impl.Render3DEvent;
import dev.crucifixbeta.api.utils.math.Animation;
import dev.crucifixbeta.api.utils.math.Easing;
import dev.crucifixbeta.mod.modules.Module;
import dev.crucifixbeta.mod.modules.settings.impl.EnumSetting;
import dev.crucifixbeta.mod.modules.settings.impl.SliderSetting;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT)
public class Zoom extends Module {
   public static Zoom INSTANCE;
   public static boolean on;
   public final EnumSetting<Easing> ease = this.add(new EnumSetting<>("Ease", Easing.CubicInOut));
   final SliderSetting fov = this.add(new SliderSetting("ZoomFov", 60.0, 0.0, 130.0, 1.0));
   final Animation animation = new Animation();
   private final SliderSetting animTime = this.add(new SliderSetting("AnimTime", 300, 0, 1000));
   public double currentFov;

   public Zoom() {
      super("Zoom", Module.Category.Render);
      this.setChinese("\u653e\u5927");
      INSTANCE = this;
      CrucifixBeta.EVENT_BUS.subscribe(new Zoom.ZoomAnim());
   }

   @Override
   public void onEnable() {
      if (nullCheck()) {
         this.disable();
      }
   }

   static {

      on = false;
   }
@Environment(EnvType.CLIENT)
   public class ZoomAnim {
      @EventListener
      public void onRender3D(Render3DEvent event) {
         if (Zoom.this.isOn()) {
            Zoom.this.currentFov = Zoom.this.animation.get(Zoom.this.fov.getValue(), (long)Zoom.this.animTime.getValueInt(), Zoom.this.ease.getValue());
            Zoom.on = true;
         } else if (Zoom.on) {
            Zoom.this.currentFov = Zoom.this.animation.get(0.0, (long)Zoom.this.animTime.getValueInt(), Zoom.this.ease.getValue());
            if ((int)Zoom.this.currentFov == 0) {
               Zoom.on = false;
            }
         }
      }
   }
}
