package fanch.multijeu.findwords.fragments;

import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import fanch.multijeu.R;
import fanch.multijeu.findwords.data.checker.WordChecker;
import fanch.multijeu.findwords.fragments.ui.compose.ComposeViewModel;
import fanch.multijeu.findwords.widget.LetterWidget;

public class ComposeFragment extends Fragment {

    private ComposeViewModel mViewModel;

    public static ComposeFragment newInstance() {
        return new ComposeFragment();
    }
    protected LetterWidget mCompose;



    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.compose_fragment, container, false);
        mCompose=v.findViewById(R.id.compose_word_view);
        if(!(getActivity() instanceof LetterWidget.LetterWidgetListener))
            throw new ClassCastException("Activity must implements LetterWidgetListener");
        mCompose.setListener((LetterWidget.LetterWidgetListener) getActivity());

        return v;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = ViewModelProviders.of(this).get(ComposeViewModel.class);
        // TODO: Use the ViewModel
    }



    public void setLetters(String s)
    {
        mViewModel.mLetters=s;
        mCompose.setLetters(s);
    }


    //TODO
    public static ComposeFragment newInstance(WordChecker c) {
        ComposeFragment f = new ComposeFragment();
        return f;
    }

}
