package zero1hd.rhythmbullet.graphics.ui.components;

import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

import zero1hd.rhythmbullet.audio.MusicController;

public class MusicControls extends HorizontalGroup {
	private ImageButton reverse, forward;
	private CheckBox shuffle, play;
	public MusicControls(Skin skin, final MusicController sc) {
		reverse = new ImageButton(skin, "rewind-button");
		reverse.addListener(new ChangeListener() {
			@Override
			public void changed(ChangeEvent event, Actor actor) {
				sc.previous();
			}
		});
		addActor(reverse);
		
		play = new CheckBox(null, skin, "play-button") {
			@Override
			public void act(float delta) {
				if (sc.hasSongLoaded()) {
					play.setChecked(sc.isPlaying());
				} else {
					play.setChecked(false);
				}
				super.act(delta);
			}
		};
		play.addListener(new ClickListener() {
			@Override
			public void clicked(InputEvent event, float x, float y) {
				if (play.isChecked()) {
					sc.play();
				} else {
					sc.pause();
				}
				super.clicked(event, x, y);
			}
		});
		addActor(play);
		
		forward = new ImageButton(skin, "fast-forward-button");
		forward.addListener(new ChangeListener() {
			@Override
			public void changed(ChangeEvent event, Actor actor) {
				sc.skip();
			}
		});
		addActor(forward);
		shuffle = new CheckBox(null, skin, "shuffle-button") {
			@Override
			public void act(float delta) {
				shuffle.setChecked(sc.isShuffle());
				super.act(delta);
			}
		};
		shuffle.addListener(new ChangeListener() {
			@Override
			public void changed(ChangeEvent event, Actor actor) {
				if (shuffle.isChecked()) {
					sc.setShuffle(true);
				} else {
					sc.setShuffle(false);
				}
			}
		});
		addActor(shuffle);
		space(15);
		
		setSize(getMinWidth(), getMinHeight());
	}
}
