package fanch.multijeu.findwords.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import java.io.FileNotFoundException;
import java.util.ArrayList;

import fanch.multijeu.R;
import fanch.multijeu.common.core.Word;
import fanch.multijeu.findwords.data.dictionaire.Dictionaire;
import fanch.multijeu.common.utils.TimeUtils;
import fanch.multijeu.findwords.widget.LetterWidget;
import fanch.multijeu.findwords.widget.PlaceHolderLayout2;
import fanch.multijeu.numbers.activity.MenuNumberActivity;

public class DumbActivity extends AppCompatActivity implements TextView.OnEditorActionListener {

    EditText m_et;
    TextView m_tv;
    Dictionaire m_dict;
    boolean mLayoutFinish=false;

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

        /*m_et=findViewById(R.id.editText);
        m_tv=findViewById(R.id.textView);

        m_et.setOnEditorActionListener(this);*/
       /* PlaceHolderRootLayout phll = new PlaceHolderRootLayout(this);
        //lv=findViewById(R.id.letterwidget);
        LinearLayout lv = findViewById(R.id.dumb);
        String list[]={
                "Bonjour",
                "a",
                "tout",
                "le",
                "a",
                "et",
                "a",
                "b"
        };
        phll.setWords(list);
        lv.addView(phll);*/

       /* lv.addView(xxx("abv"));
        lv.addView(xxx("Bds"));
        lv.addView(xxx("Cfsd"));
        lv.addView(xxx("Dfd"));*/
       // lv.addView(new Button(this));


        try {
            m_dict = new Dictionaire(this, R.raw.liste_francais_latin1);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        onJeu(null);

    }

    View xxx(String txt)
    {
        PlaceHolderLayout2 phl = new PlaceHolderLayout2(this);
        phl.setText(txt);
        return  phl;
    }


    @Override
    public boolean onEditorAction(TextView textView, int k, KeyEvent keyEvent) {
        valid();
        return false;
    }

    public void valid()
    {
        TimeUtils.TimeInterval ti = new TimeUtils.TimeInterval();
        ArrayList<Word> list = m_dict.constructWithIgnoreAccent(m_et.getText().toString());
        m_tv.setText(list.size()+" mots trouvés en "+ti.tick()+" s\n");
        for(int i=0; i<list.size(); i++)
            m_tv.append(list.get(i)+"\n");
    }



    public void onClick(View view) {
        valid();
    }

    public void onJeu(View view) {
       /* String list[] = {
                "laz",
                "laz"
        };
        WordCheckerList w = new RandomWordChekerList();
        //WordCheckerList w = new SimpleWordCheckerList(m_dict,list);
        //DictionaireReader rd = new DictionaireReader(this, R.raw.ligthdico);

        //m_dict.save(this, "test3");
        //rd.getIndex().save(this, "test3");

        WordActivity.start(this, m_dict, w);*/

        Intent in = new Intent(this, MenuNumberActivity.class);
        startActivity(in);


    }
}
