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

import dev.crucifixbeta.api.events.eventbus.EventListener;
import dev.crucifixbeta.api.events.impl.ModuleToggleEvent;
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;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;

@Environment(EnvType.CLIENT)
public class Sounds extends Module {
   public static Sounds INSTANCE;
   public final EnumSetting<Sounds.SoundMode> mode = this.add(new EnumSetting<>("Mode", Sounds.SoundMode.Default));
   public final EnumSetting<Sounds.GuiSoundMode> guiSound = this.add(new EnumSetting<>("GuiSound", Sounds.GuiSoundMode.Chime));
   public final EnumSetting<Sounds.SwitchSoundMode> switchSound = this.add(new EnumSetting<>("SwitchSound", Sounds.SwitchSoundMode.Off));
   public final SliderSetting guiSoundPitch = this.add(
      new SliderSetting("GuiPitch", 0.0, 0.0, 2.0, 0.1, () -> !this.guiSound.is(Sounds.GuiSoundMode.Off))
   );
   public final SliderSetting switchSoundPitch = this.add(
      new SliderSetting("SwitchPitch", 0.0, 0.0, 2.0, 0.1, () -> !this.switchSound.is(Sounds.SwitchSoundMode.Off))
   );

   public Sounds() {
      super("Sounds", Module.Category.Client);
      this.setChinese("\u97f3\u6548");
      this.guiSound.setChinese("GUI\u97f3\u6548");
      this.switchSound.setChinese("\u5f00\u5173\u97f3\u6548");
      this.guiSoundPitch.setChinese("GUI\u97f3\u8c03");
      this.switchSoundPitch.setChinese("\u5f00\u5173\u97f3\u8c03");
      INSTANCE = this;
   }

   public void playGuiSound() {
      if (mc != null && mc.getSoundManager() != null && !this.guiSound.is(Sounds.GuiSoundMode.Off)) {
         switch ((Sounds.GuiSoundMode)this.guiSound.getValue()) {
            case Off:
            default:
               break;
            case Chime:
               mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.BLOCK_NOTE_BLOCK_CHIME, this.guiSoundPitch.getValueFloat()));
               break;
            case Bell:
               mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.BLOCK_NOTE_BLOCK_BELL, this.guiSoundPitch.getValueFloat()));
         }
      }
   }

   public void playSwitchSound() {
      if (mc != null && mc.getSoundManager() != null && !this.switchSound.is(Sounds.SwitchSoundMode.Off)) {
         switch ((Sounds.SwitchSoundMode)this.switchSound.getValue()) {
            case Off:
            default:
               break;
            case Chime:
               mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.BLOCK_NOTE_BLOCK_CHIME, this.switchSoundPitch.getValueFloat()));
               break;
            case Bell:
               mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.BLOCK_NOTE_BLOCK_BELL, this.switchSoundPitch.getValueFloat()));
         }
      }
   }

   @EventListener
   public void onModuleToggle(ModuleToggleEvent event) {
      if (mc != null && mc.getSoundManager() != null && event.getModule() != this) {
         String var2 = this.mode.getValue().name().toLowerCase();
         String var3 = var2.equals("default") ? "" : var2;
         String var4 = event.isEnabled() ? "enable" + var3 : "disable" + var3;

         try {
            mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvent.of(Identifier.of("alien", var4)), 1.0F, 1.0F));
         } catch (Exception var6) {
         }
      }
   }
@Environment(EnvType.CLIENT)
   public static enum GuiSoundMode {
      Off,
      Chime,
      Bell;

}

   @Environment(EnvType.CLIENT)
   public static enum SoundMode {
      Default,
      Akrien,
      Alarm,
      Dev,
      Discord,
      Frontiers,
      Hanabi,
      Heavy,
      Sigma,
      Speech,
      Tone;

}

   @Environment(EnvType.CLIENT)
   public static enum SwitchSoundMode {
      Off,
      Chime,
      Bell;

}
}
