package com.duben.microtribe.ui.adapter

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.duben.microtribe.R
import com.duben.microtribe.mvp.model.EpisodeBean
import com.duben.microtribe.utils.LogUtil

/**
 *  @author Assen
 *  @date 2023/7/5
 *  @desc
 */
class VideoEpisodeAdapter :
    BaseQuickAdapter<List<EpisodeBean>, BaseViewHolder>(R.layout.item_video_epsiode) {

    override fun convert(holder: BaseViewHolder, item: List<EpisodeBean>) {
        val rv = holder.getView<RecyclerView>(R.id.item_rv)
        rv.layoutManager = GridLayoutManager(context, 6)
        val itemVideoEpisodeAdapter = ItemVideoEpisodeAdapter()
        rv.adapter = itemVideoEpisodeAdapter
        val list = mutableListOf<EpisodeBean>()
        itemVideoEpisodeAdapter.addChildClickViewIds(R.id.item_tv)
        itemVideoEpisodeAdapter.setOnItemClickListener { adapter, view, position ->
            val _position = position + (holder.adapterPosition * 30)
            mOnEpisodeClickListener?.onEpisodeClick(_position)
        }
        list.addAll(item)
        itemVideoEpisodeAdapter.setNewInstance(list)
    }

    override fun getItemCount(): Int {
        return data.size % 30
    }

    private var mOnEpisodeClickListener: OnEpisodeClickListener? = null

    fun setOnEpisodeClickListener(onEpisodeClickListener: OnEpisodeClickListener?) {
        mOnEpisodeClickListener = onEpisodeClickListener
    }

    interface OnEpisodeClickListener {
        fun onEpisodeClick(position: Int)
    }


}