package com.ttiglobal.inttilectgpchat.adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ttiglobal.inttilectgpchat.R;
import com.ttiglobal.inttilectgpchat.smilerating.SmileRating;
import com.ttiglobal.inttilectgpchat.wrappers.FeedbackAnswerArrayModel;
import com.ttiglobal.inttilectgpchat.wrappers.ProductFeedback;

import java.util.ArrayList;
import java.util.List;

public class ProductFeedbackListAdapter extends RecyclerView.Adapter<ProductFeedbackListAdapter.ViewHolder> implements SmileRating.OnSmileySelectionListener {
    private ArrayList<ProductFeedback> Questions;
    private Context context;
    String TAG = "Smiley";
    //public static ArrayList<SmileyRatingAnswer> ratingAnswerArrayList;
    private FeedbackAnswerArrayModel answerArrayModels;
    public  static  List<FeedbackAnswerArrayModel> feedbackAnsArr;


    public ProductFeedbackListAdapter(Context context, ArrayList<ProductFeedback> items) {
        this.context = context;
        this.Questions = items;
        answerArrayModels = new FeedbackAnswerArrayModel();
        feedbackAnsArr = new ArrayList<>();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_smiley_feedback, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        ProductFeedback item = Questions.get(position);
        holder.view.setTag(item);
        holder.feedBackQuestionsId.setText(item.getQid() + ".");
        holder.feedBackQuestions.setText(item.getQuestiontext());
        holder.smileRating.setOnSmileySelectionListener(new SmileRating.OnSmileySelectionListener() {
            @Override
            public void onSmileySelected(int smiley, boolean reselected) {

                answerArrayModels = new FeedbackAnswerArrayModel();

                answerArrayModels.setQid(Questions.get(position).getQid());
                answerArrayModels.setSurveyRating(Integer.valueOf(Questions.get(position).getRating_options().get(smiley).getRating_text()));
                feedbackAnsArr.add(answerArrayModels);
            }
        });
    }

    @Override
    public int getItemCount() {
        return Questions.size();
    }

    @Override
    public void onSmileySelected(int smiley, boolean reselected) {

    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView feedBackQuestionsId, feedBackQuestions;
        View view;
        SmileRating smileRating;

        private ViewHolder(View itemView) {
            super(itemView);
            view = itemView;
            smileRating = view.findViewById(R.id.smiley_rating);
            feedBackQuestions = view.findViewById(R.id.feedbackQuestion);
            feedBackQuestionsId = view.findViewById(R.id.feedbackQuestionId);
        }

    }
}
