package com.example.jmastermind.Events;

import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import com.example.jmastermind.Game.ColorDefSelect;
import com.example.jmastermind.Game.Popup;
import com.example.jmastermind.Game.Game;
import com.example.jmastermind.Menu.Menu;
import com.example.jmastermind.R;

public class PopupEvent implements DialogInterface.OnClickListener, View.OnClickListener {
    private MediaPlayer mp;
    private int tentative;
    private AppCompatActivity context;
    private Boolean isMulti;

    /**
     * Event lié au popup de fin de partie.
     * @param context Le context.
     * @param tentative Le nombre de tentative.
     * @param mp La musique lance avant de declancher une action du Popup.
     * @param isMulti Le mode de jeu.
     * */
    public PopupEvent(AppCompatActivity context, int tentative, MediaPlayer mp, Boolean isMulti) {
        this.context = context;
        this.tentative = tentative;
        this.mp = mp;
        this.isMulti = isMulti;
    }

    @Override
    public void onClick(DialogInterface dialogInterface, int i) {
        switch(i) {
            case 0: {
                this.mp.stop();

                Intent a;

                if(!this.isMulti) {
                    a =  new Intent(this.context, Game.class);
                } else {
                    a =  new Intent(this.context, ColorDefSelect.class);
                }

                this.context.startActivity(a);
                break;
            }

            case 1: {
                this.mp.stop();
                Button btn = (Button) this.context.findViewById(R.id.validate);
                btn.setText("Finish HIM");
                btn.setOnClickListener(this);

                dialogInterface.cancel();
                break;
            }

            case 2: {
                this.mp.stop();
                Intent c =  new Intent(this.context, Menu.class);
                this.context.startActivity(c);
                break;
            }
        }
    }


    @Override
    public void onClick(View view) {
        String[] opts = new String[] {
                "Rejouer",
                "Voir votre jeu",
                "Retourner au menu"
        };

        Popup pop = new Popup(this.context, opts, this.isMulti, this.tentative);
        pop.show();
    }
}
