package com.example.jmastermind.Events;

import android.content.Context;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.example.jmastermind.Game.Controller;

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();
        }
    }
}
