package com.gh.gamecenter.home.amway

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.common.view.FixLinearLayoutManager
import com.gh.gamecenter.databinding.HomeAmwayListBinding
import com.gh.gamecenter.entity.AmwayCommentEntity

class HomeAmwayListViewHolder(val binding: HomeAmwayListBinding) : BaseRecyclerViewHolder<Any>(binding.root) {

    fun bindAmwayList(
        amwayList: List<AmwayCommentEntity>,
        itemClick: (View, position: Int, AmwayCommentEntity) -> Unit
    ) {
        val context = binding.recyclerView.context
        var adapter = binding.recyclerView.adapter
        if (adapter is HomeAmwayAdapter) {
            adapter.checkResetData(amwayList)
            return
        }
        adapter = HomeAmwayAdapter(context, amwayList, itemClick)
        binding.recyclerView.layoutManager =
            FixLinearLayoutManager(context, RecyclerView.HORIZONTAL, false)
        binding.recyclerView.adapter = adapter
        binding.recyclerView.onFlingListener = null
        binding.recyclerView.isNestedScrollingEnabled = false
        val snapHelper = LeftPagerSnapHelper(4F.dip2px())
        snapHelper.attachToRecyclerView(binding.recyclerView)
    }
}