package de.fullrisk.citrusDev;

import io.wispforest.owo.ui.component.ButtonComponent;
import io.wispforest.owo.ui.core.AnimatableProperty;
import io.wispforest.owo.ui.core.OwoUIGraphics;
import net.minecraft.network.chat.Component;

import java.util.function.Consumer;

public class ScalableButton extends ButtonComponent {

    protected final AnimatableProperty<ScaleValue> scale = AnimatableProperty.of(new ScaleValue(0f));

    public ScalableButton(Component message, Consumer<ButtonComponent> onPress) {
        super(message, onPress);
    }

    public AnimatableProperty<ScaleValue> scale() {
        return this.scale;
    }

    @Override
    public void update(float delta, int mouseX, int mouseY) {
        super.update(delta, mouseX, mouseY);
        this.scale.update(delta);
    }

    @Override
    public void draw(OwoUIGraphics graphics, int mouseX, int mouseY, float partialTicks, float delta) {
        float s = this.scale.get().value();

        float centerX = this.x() + this.width() / 2f;
        float centerY = this.y() + this.height() / 2f;

        graphics.pose().pushMatrix();
        graphics.pose().translate(centerX, centerY);
        graphics.pose().scale(s, s);
        graphics.pose().translate(-centerX, -centerY);

        super.draw(graphics, mouseX, mouseY, partialTicks, delta);

        graphics.pose().popMatrix();
    }
}