package com.gh.gamecenter.forum.home.follow.viewholder

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.gh.gamecenter.databinding.RecyclerFollowRecommendListBinding
import com.gh.gamecenter.eventbus.EBUserFollow
import com.gh.gamecenter.feature.entity.UserEntity
import com.gh.gamecenter.forum.home.follow.adapter.FollowRecommendListAdapter

class FollowRecommendListViewHolder(
    val binding: RecyclerFollowRecommendListBinding,

    listener: FollowRecommendListAdapter.OnChildEventListener
) :
    ViewHolder(binding.root) {

    private val adapter by lazy {
        FollowRecommendListAdapter(itemView.context, listener)
    }

    fun bindView(data: List<UserEntity>) {
        if (binding.rvRecommends.adapter == null) {
            binding.rvRecommends.layoutManager =
                LinearLayoutManager(itemView.context, RecyclerView.HORIZONTAL, false)
            binding.rvRecommends.adapter = adapter
        }
        adapter.submitList(data)

    }

    fun updateFollowed(change: EBUserFollow) {
        adapter.updateFollowed(change)
    }
}