package com.prank.simulator.sounds.recycler;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.prank.simulator.sounds.actfrag.PlayActivity;
import com.prank.simulator.sounds.data.ChildData;
import com.prank.simulator.sounds.databinding.ItemSecordBinding;
import com.prank.simulator.sounds.helper.Static;

import java.util.List;


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

    private final List<ChildData> mValues;

    private Context mCon;
    private int i;

    public SecondAdapter(Context context, List<ChildData> items, int colorIndex) {
        mValues = items;
        this.mCon = context;
        i = colorIndex;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new ViewHolder(ItemSecordBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));

    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        ChildData childData = mValues.get(position);
        String covert = childData.getCovert();
        Glide.with(mCon).load(covert).into(holder.vb.image);
        holder.vb.name.setText(childData.getName());
        holder.vb.frameIm.setBackground(ContextCompat.getDrawable(mCon, Static.bgs[i]));
        holder.vb.getRoot().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mCon, PlayActivity.class);
                intent.putExtra(Static.KEY_PLAY_DATA, childData);
                intent.putExtra(Static.KEY_PLAY_COLOR_POS, i);
                mCon.startActivity(intent);
            }
        });

    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        private ItemSecordBinding vb;

        public ViewHolder(ItemSecordBinding binding) {
            super(binding.getRoot());
            vb = binding;

        }

    }
}