package com.gh.gamecenter.gamecollection.publish

import android.content.Context
import android.view.ViewGroup
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.utils.ImageUtils
import com.gh.common.util.NewLogUtils
import com.gh.gamecenter.common.utils.toBinding
import com.gh.gamecenter.databinding.ItemGameCollectionDefaultCoverBinding
import com.gh.gamecenter.entity.GameCollectionCoverEntity
import com.lightgame.adapter.BaseRecyclerAdapter

class ChooseGameCollectionDefaultAdapter(context: Context, val callback: (GameCollectionCoverEntity) -> Unit) :
    BaseRecyclerAdapter<ChooseGameCollectionDefaultAdapter.GameCollectionDefaultCoverViewHolder>(context) {

    private var mDataList = ArrayList<GameCollectionCoverEntity>()

    fun submitList(updateData: List<GameCollectionCoverEntity>?) {
        mDataList.clear()
        if (updateData != null) {
            mDataList.addAll(updateData)
        }
        notifyItemRangeChanged(0, mDataList.size)
    }

    override fun getItemCount(): Int = mDataList.size

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GameCollectionDefaultCoverViewHolder {
        return GameCollectionDefaultCoverViewHolder(parent.toBinding())
    }

    override fun onBindViewHolder(holder: GameCollectionDefaultCoverViewHolder, position: Int) {
        val entity = mDataList[position]
        ImageUtils.display(holder.binding.coverImage, entity.url)
        holder.binding.root.setOnClickListener {
            callback.invoke(entity)
            NewLogUtils.logClickGameCollectionDefaultCoverDialog("图片")
        }
    }

    class GameCollectionDefaultCoverViewHolder(val binding: ItemGameCollectionDefaultCoverBinding) :
        BaseRecyclerViewHolder<GameCollectionCoverEntity>(binding.root)
}