package com.example.jmastermind.Events;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import com.example.jmastermind.Game.Controller;
import com.example.jmastermind.Menu.Menu;

public class ControlEvent extends View implements View.OnClickListener {
    private final AppCompatActivity context;
    private Controller controller;

    /**
     * Event relier aux boutons "Valider" et "Effacer"
     * @param context Le context
     * @param controller Le controller du jeu
     * */
    public ControlEvent(AppCompatActivity context, Controller controller) {
        super(context);
        this.context = context;
        this.controller = controller;
    }

    @Override
    public void onClick(View view) {
        int idOfButton = view.getId();
        Button btnClicked = (Button) this.context.findViewById(idOfButton);
        CharSequence text = btnClicked.getText();

        if ("Valider".equals(text)) {
            this.controller.viewValidate();
        } else if ("Effacer".equals(text)) {
            this.controller.viewReset();
        } else if("Quitter".equals(text)) {
            Intent i =  new Intent(this.context, Menu.class);
            this.context.startActivity(i);
        }
    }
}
