package fanch.multijeu.sudoku.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import fanch.multijeu.R;
import fanch.multijeu.sudoku.view.SudokuOverlay;
import fanch.multijeu.sudoku.view.SudokuView;

public class SudokuLauncher extends AppCompatActivity {


    protected RadioGroup mRG;
    protected RadioButton mRB[]=new RadioButton[6];
    protected CheckBox mCbIndice;
    protected CheckBox mCbResolve;
    protected CheckBox mCbFilter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sudoku_launcher);

        mRG=findViewById(R.id.rg_difficulty);

        int ids[]={R.id.rb_lvl1, R.id.rb_lvl2, R.id.rb_lvl3, R.id.rb_lvl4, R.id.rb_lvl5,R.id.rb_lvl6};
        for(int i =0; i<mRB.length; i++)
            mRB[i] = findViewById(ids[i]);

        mCbFilter=findViewById(R.id.cb_filter);
        mCbResolve=findViewById(R.id.cb_resolve);
        mCbIndice=findViewById(R.id.cb_indices);


    }

    public void onStart(View view) {
        SudokuActivity.Attrs attrs = new SudokuActivity.Attrs();
        attrs.overlayAttr.select=(mCbFilter.isChecked()?
                SudokuOverlay.SelectMode.DISABLE_BUTTON:
                SudokuOverlay.SelectMode.NO_ASSIST);

        attrs.canIndices=mCbIndice.isChecked();
        attrs.canResolve=mCbResolve.isChecked();
        int id = mRG.getCheckedRadioButtonId();
        int lvl = 2;
        for(int i=0; i<mRB.length; i++) {
            Log.e("--------------", "i="+i);
            if (mRB[i].getId() == id)
                lvl = i;
        }
        attrs.difficulty=lvl;
        SudokuActivity.start(this, attrs);
    }

    public static void start(Context c)
    {
        Intent in = new Intent(c, SudokuLauncher.class);
        c.startActivity(in);
    }
}
