package com.cygnusa.hyperm.fragments;


import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.cygnusa.hyperm.R;
import com.cygnusa.hyperm.adapter.QuestionAdapter;
import com.cygnusa.hyperm.util.ApiService;
import com.cygnusa.hyperm.util.MainApplication;
import com.cygnusa.hyperm.wrappers.AssessmentQuestion;

public class QuestionFragment extends Fragment {

    View mainView;
    ApiService restService;
    String TRAINING_ID = "";
    String QUESTION_NO = "";
    AssessmentQuestion assessmentQuestion = new AssessmentQuestion();
    TextView questionNumber, questionText;
    ListView answerList;
    TextView isManatary;

    public QuestionFragment() {

    }

    public void onResumeFragment() {
    }

    public void setAssessmentQuestion(AssessmentQuestion assessmentQuestion) {
        this.assessmentQuestion = assessmentQuestion;
    }

    public void setTrainingId(String id) {
        this.TRAINING_ID = id;
    }

    public void setQuestionNo(String number) {
        this.QUESTION_NO = number;
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_question, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mainView = view;
        restService = ((MainApplication) getActivity().getApplication()).getClient();

        questionText = mainView.findViewById(R.id.questionText);
        answerList = mainView.findViewById(R.id.answerList);
        isManatary = mainView.findViewById(R.id.isManatary);

        if (assessmentQuestion.getIs_mandatory().trim().equalsIgnoreCase("1")) {
            isManatary.setVisibility(View.VISIBLE);
        } else {
            isManatary.setVisibility(View.GONE);
        }
        answerList.post(new Runnable() {
            @Override
            public void run() {

                questionText.setText(assessmentQuestion.getQuestiontext());
                answerList.setAdapter(new QuestionAdapter(getActivity(), assessmentQuestion.getOptions(), answerList, assessmentQuestion.getQuestiontypeid()));
            }
        });
    }

}
