package com.haircut.pranks.app.recyadapter;

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

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

import com.bumptech.glide.Glide;
import com.haircut.pranks.app.R;
import com.haircut.pranks.app.data.ChildData;
import com.haircut.pranks.app.databinding.ItemChildBinding;
import com.haircut.pranks.app.listener.ListenerSounds;
import com.haircut.pranks.app.manager.Tools;
import com.haircut.pranks.app.uiview.ActPlaySounds;

import java.util.List;


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

    private final List<ChildData> mValues;

    private Context mCon;
    private int type;
    private ListenerSounds mListener;


    public AdapterChild(Context context, List<ChildData> items, int mType,ListenerSounds listener) {
        mValues = items;
        this.mCon = context;
        type = mType;
        mListener = listener;

    }

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

        return new ViewHolder(ItemChildBinding.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.getRoot().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onClickSoundsListener(childData);
            }
        });

    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {

        private ItemChildBinding vb;

        public ViewHolder(ItemChildBinding binding) {
            super(binding.getRoot());
            vb = binding;
            ViewGroup.LayoutParams layoutParams = vb.relative.getLayoutParams();
            if(type == 0){
                layoutParams.width = RelativeLayout.LayoutParams.MATCH_PARENT;
                vb.relative.setBackground(ContextCompat.getDrawable(mCon, R.drawable.rect_main_gradient));
            }else {
                layoutParams.width = (int) Tools.dpToPx(130);
                vb.relative.setBackground(ContextCompat.getDrawable(mCon, R.drawable.rect_more));
            }
            vb.relative.setLayoutParams(layoutParams);





        }

    }
}