package wtf.opal.client.screen.click.dropdown.panel.property.impl;

import com.ibm.icu.impl.Pair;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
import wtf.opal.client.feature.module.property.impl.bool.BooleanProperty;
import wtf.opal.client.renderer.component.ToggleSwitchComponent;
import wtf.opal.client.renderer.repository.FontRepository;
import wtf.opal.client.screen.click.dropdown.panel.property.PropertyPanel;
import wtf.opal.utility.render.ColorUtility;

@Environment(EnvType.CLIENT)
public final class BooleanPropertyComponent extends PropertyPanel<BooleanProperty> {
   private final ToggleSwitchComponent toggleSwitch;

   public BooleanPropertyComponent(BooleanProperty property) {
      super(property);
      this.toggleSwitch = new ToggleSwitchComponent(property::toggle, property::getValue);
   }

   @Override
   public void init() {
      this.toggleSwitch.reset();
   }

   @Override
   public void render(DrawContext context, int mouseX, int mouseY, float delta) {
      super.render(context, mouseX, mouseY, delta);
      FontRepository.getFont("productsans-medium").drawString(this.getProperty().getName(), this.x + 5.0F, this.y + 10.5F, 7.0F, -1);
      this.toggleSwitch.setBoxColors(Pair.of(ColorUtility.getToggleFillColor(), ColorUtility.getToggleBackgroundColor()));
      this.toggleSwitch.render(this.x + 88.0F, this.y + 3.8F, 0.85F);
   }

   @Override
   public void mouseClicked(double mouseX, double mouseY, int button) {
      if (button == 0) {
         this.toggleSwitch.mouseClicked(this.x, this.y, this.width, this.height, mouseX, mouseY);
      }
   }
}
