package com.offline.music.playermp3.adapter;

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

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.offline.music.playermp3.databinding.ItemResultBinding;
import com.offline.music.playermp3.helper.CommonUtils;
import com.offline.music.playermp3.helper.ItemDecoration;
import com.offline.music.playermp3.javabean.response.ResponseResultList;

public class AdapterResult extends BaseAdapter<ResponseResultList, ItemResultBinding>{
    public AdapterResult(Context mContext) {
        super(mContext);
    }

    @Override
    protected ItemResultBinding getViewBinding(ViewGroup parent) {
        return ItemResultBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
    }



    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ResponseResultList resultList = data.get(position);

        VHolder<ItemResultBinding> itemHolder = (VHolder<ItemResultBinding>) holder;
        ItemResultBinding vb = itemHolder.getVb();
        String headerTitle = resultList.getHeaderTitle();
        vb.tvHeaderTitle.setText(headerTitle);

        CommonUtils.LogMsg("---------headerTitle="+headerTitle);

        ItemDecoration itemDecoration  ;

        if(position == 0){
            itemDecoration = new ItemDecoration(10,0,0);
            AdapterResultListSong adapterResultListSong = new AdapterResultListSong();
            adapterResultListSong.setData(resultList.getChildList());
            vb.listChild.setAdapter(adapterResultListSong);
            vb.listChild.setLayoutManager(new LinearLayoutManager(mContext));
            if(homeItemClickListener!= null)
                adapterResultListSong.setHomeItemClickListener(homeItemClickListener);
        }else {
            itemDecoration = new ItemDecoration(0,10,0);
            AdapterResultListAlbum adapterResultListAlbum = new AdapterResultListAlbum();
            adapterResultListAlbum.setData(resultList.getChildList());
            vb.listChild.setAdapter(adapterResultListAlbum);
            vb.listChild.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL,false));
            if(homeItemClickListener!= null)
                adapterResultListAlbum.setHomeItemClickListener(homeItemClickListener);
        }
//        vb.listChild.addItemDecoration(itemDecoration);

        if(position == data.size() - 1){
            vb.place.setVisibility(View.VISIBLE);
        }else {
            vb.place.setVisibility(View.GONE);
        }

    }
}
