package fr.monkhanny.dorfromantik.listeners;

import fr.monkhanny.dorfromantik.Options;
import fr.monkhanny.dorfromantik.utils.MusicPlayer;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MuteCheckBoxListener implements ActionListener {
    private String label;

    public MuteCheckBoxListener(String label) {
        this.label = label;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        JCheckBox checkBox = (JCheckBox) e.getSource();
        
        if ("Musique".equals(label)) {
            Options.MUSIC_MUTED = !checkBox.isSelected();
            if (Options.MUSIC_MUTED) {
                MusicPlayer.pauseMusic();
            } else {
                MusicPlayer.playMusic();
            }
        } else if ("SFX".equals(label)) {
            Options.SOUNDS_MUTED = !checkBox.isSelected();
        }
    }
}
