package fr.monkhanny.dorfromantik.gui;

import fr.monkhanny.dorfromantik.Options;
import fr.monkhanny.dorfromantik.controller.ButtonHoverAnimationListener;

import javax.swing.*;
import java.awt.*;

public class ButtonHoverAnimator {

    private final JButton button;
    private final Color originalColor;
    private static Font originalFont;
    private Timer animationTimer;
        
    public ButtonHoverAnimator(JButton button) {
        this.button = button;
        this.originalColor = button.getForeground();
        ButtonHoverAnimator.originalFont = button.getFont();
    }
    
    public void startAnimation(boolean entering) {
        if (animationTimer != null && animationTimer.isRunning()) {
            animationTimer.stop();
        }
    
        // Create a new ActionListener instance
        animationTimer = new Timer(Options.ANIMATION_DELAY, new ButtonHoverAnimationListener(entering, button, originalColor, originalFont));
        animationTimer.start();
    }
    
    public static void updateOriginalFont(float newFontSize) {
        originalFont = originalFont.deriveFont(newFontSize);
    }

}
