package com.team.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.team.app.R;

public class FAQAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private final Context context;
    private final String[] desc;
    public int num = 0;
    private final String[] title;

    public FAQAdapter(Context context2, String[] strArr, String[] strArr2) {
        this.context = context2;
        this.title = strArr;
        this.desc = strArr2;
    }

    @NonNull
    @Override
    public FAVViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new FAVViewHolder(LayoutInflater.from(this.context).inflate(R.layout.faq_list, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        FAVViewHolder fAVViewHolder = (FAVViewHolder) holder;
        fAVViewHolder.qus.setText(this.title[position]);
        fAVViewHolder.ans.setText(this.desc[position]);
        fAVViewHolder.crd.setOnClickListener(view -> {
            if (FAQAdapter.this.num == 0) {
                fAVViewHolder.ans.setVisibility(View.VISIBLE);
                FAQAdapter.this.num = 1;
            } else if (FAQAdapter.this.num == 1) {
                fAVViewHolder.ans.setVisibility(View.GONE);
                FAQAdapter.this.num = 0;
            }
        });
    }

    @Override
    public int getItemCount() {
        return this.title.length;
    }

    public static class FAVViewHolder extends RecyclerView.ViewHolder {
        TextView ans;
        CardView crd;
        TextView qus;

        FAVViewHolder(View view) {
            super(view);
            this.crd = view.findViewById(R.id.crd);
            this.qus = view.findViewById(R.id.qus);
            this.ans = view.findViewById(R.id.ans);
        }
    }
}
