package sbu.javafx;

import javafx.fxml.FXML;
import javafx.event.ActionEvent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.fxml.FXML;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;


public class MusicController {

    // TODO: Define your UI components using the @FXML annotation.

    //TODO: Implement the logic to play a song. This method should update the UI to show which song is currently playing.

    private Button PlayButton ;
    private MediaPlayer mediaPlayer;
    private boolean IsPlay = false ;
    @FXML
    public void Play(  Button btn)
    {
        if (!IsPlay)
        {
            btn.setText("stop");
            IsPlay = true ;

        }
        else if (IsPlay)
        {
            btn.setText("play");
            IsPlay = false ;
        }
    }
    @FXML
    public void handlePlayAction(ActionEvent event) {
        String songPath = "";
        Button button =
                (Button) event.getSource();
        //Update labels, change button icons, etc.
        if(button.getId().equals("1")) {
           if (!IsPlay) {
               songPath = "/1.mp3";
               Play( button);

           }
           else
           {
               mediaPlayer.stop();
               Play( button);



           }
        }

        else if(button.getId().equals("2")) {

            if (!IsPlay) {
                songPath = "/2.mp3";
                Play( button);

            }
            else
            {
                mediaPlayer.stop();
                Play( button);

            }
        }

        else if(button.getId().equals("3")) {

            if (!IsPlay) {
                songPath = "/3.mp3";
                Play( button);

            }
            else
            {
                mediaPlayer.stop();
                Play(button);

            }
        }

        Media media = new Media(
                getClass().getResource(songPath)
                        .toExternalForm()
        );

        mediaPlayer = new MediaPlayer(media);
        mediaPlayer.play();
        }

    //TODO: Logic to add a specific song to the user's playlist.

    public void addToPlaylist(String songName) {
        //Add the song to a list or update a ListView.
        
    }

    // TODO:This method should open a new window or change the current scene  to display the "Playlist" page.

    public void openPlaylistWindow() {
        //Create a new stage and show the playlist UI.
    }
}
