package com.gh.gamecenter.forum.home

import android.content.Context
import android.view.ViewGroup
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.common.util.NewLogUtils
import com.gh.gamecenter.common.utils.toBinding
import com.gh.gamecenter.core.utils.NumberUtils
import com.gh.gamecenter.databinding.OfficialForumItemBinding
import com.gh.gamecenter.entity.ForumEntity
import com.gh.gamecenter.forum.detail.ForumDetailActivity
import com.lightgame.adapter.BaseRecyclerAdapter

class OfficialForumAdapter(
    context: Context,
    private val entrance: String,
    private var mList: List<ForumEntity>
) : BaseRecyclerAdapter<OfficialForumAdapter.OfficialForumViewHolder>(context) {


    override fun getItemCount() = mList.size

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = OfficialForumViewHolder(parent.toBinding())


    override fun onBindViewHolder(holder: OfficialForumViewHolder, position: Int) {
        holder.binding.run {

            val forumEntity = mList[position]
            forumName.text = forumEntity.name
            forumIv.displayGameIcon(forumEntity.icon, null)
            hotTv.text = NumberUtils.transSimpleCount(forumEntity.hot)

            root.setOnClickListener {
                val bbsType = if (forumEntity.type == "official_bbs") "综合论坛" else "游戏论坛"
                NewLogUtils.logForumClick("click_multiple_forum", "论坛页", forumEntity.id, bbsType)
                mContext.startActivity(ForumDetailActivity.getIntent(mContext, forumEntity.id, entrance))
            }
        }
    }

    class OfficialForumViewHolder(val binding: OfficialForumItemBinding) : BaseRecyclerViewHolder<Any>(binding.root)
}