package com.gh.gamecenter.forum.home

import android.content.Context
import android.view.ViewGroup
import com.gh.common.util.CheckLoginUtils
import com.gh.common.util.DirectUtils
import com.gh.common.util.NewLogUtils
import com.gh.gamecenter.InfoActivity
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.utils.toBinding
import com.gh.gamecenter.databinding.ForumWelfareItemBinding
import com.gh.gamecenter.toolbox.ToolBoxActivity
import com.lightgame.adapter.BaseRecyclerAdapter

class WelfaresAdapter(
    context: Context,
    private var mList: List<Triple<Int, String, String>>
) : BaseRecyclerAdapter<WelfaresAdapter.WelfareViewHolder>(context) {


    override fun getItemCount() = mList.size

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


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

            val entity = mList[position]
            welfareIv.setImageResource(entity.first)
            welfareName.text = entity.second
            welfareSecondName.text = entity.third

            root.setOnClickListener {
                when (entity.second) {
                    "游戏工具箱" -> {
                        NewLogUtils.logForumPageEvent("click_forum_toolbox")
                        mContext.startActivity(ToolBoxActivity.getIntent(mContext, "(社区-论坛:工具箱)"))
                    }

                    "礼包中心" -> {
                        NewLogUtils.logForumPageEvent("click_forum_gift_center")
                        DirectUtils.directToGift(mContext, "(社区-论坛:礼包中心)")
                    }

                    "游戏动态" -> {
                        NewLogUtils.logForumPageEvent("click_forum_game_general")
                        CheckLoginUtils.checkLogin(mContext, "社区-论坛:游戏动态") {
                            DirectUtils.directToConcernInfo(mContext, "社区-论坛:游戏动态")
                        }
                    }

                    "资讯中心" -> {
                        NewLogUtils.logForumPageEvent("click_forum_game_news")
                        mContext.startActivity(InfoActivity.getIntent(mContext))
                    }
                }
            }
        }
    }

    class WelfareViewHolder(val binding: ForumWelfareItemBinding) : BaseRecyclerViewHolder<Any>(binding.root)
}