package macampcorp.macamp.activities.fragments;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import macampcorp.macamp.activities.HostActivity;
import macampcorp.macamp.activities.R;
import macampcorp.macamp.game.challenges.BombDefuse;
import macampcorp.macamp.game.challenges.Challenge;
import macampcorp.macamp.game.challenges.Question;


public class BombFragment extends ChallengeFragment implements View.OnClickListener {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER

    protected ImageView mUIImage;
    protected Button mUIDefuse;
    protected TextView  mUIQuestion;
    protected BombDefuse mBomb;


    public BombFragment() {
    }



    public void onDefuse(View v)
    {
        Activity act = getActivity();
        if(act instanceof  HostActivity)
        {
            HostActivity a = (HostActivity)act;
            a.onTryDisarm(null);
            return;
        }
        throw  new RuntimeException("Erreur: L'activite n'est pas de type HostActivity");

    }



    public static BombFragment newInstance() {
        BombFragment fragment = new BombFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int check() {
        return Challenge.FAIL;
    }

    @Override
    protected void onResetUi() {
        getHostActivity().setVisibilityView(R.id.btn_valid, View.INVISIBLE);
    }


    @Override
    public void onInitChallenge(Challenge c) {
        super.onInitChallenge(c);

        if(c instanceof BombDefuse)
        {
            mBomb=(BombDefuse) c;
            mUIQuestion.setText(mBomb.getmText());
        }
        else
        {
            Toast.makeText(getActivity(), "Error l'entrée n'est pas une question ! ", Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = super.onCreateView(inflater, container, R.layout.fragment_bomb);

        mUIImage = (ImageView) v.findViewById(R.id.iv_img);
        mUIQuestion = (TextView) v.findViewById(R.id.tv_question);
        mUIDefuse = (Button) v.findViewById(R.id.btn_ok);
        mUIDefuse.setOnClickListener(this);
        return v;
    }


    @Override
    public void onClick(View v) {
        onDefuse(v);
    }
}
