package com.gh.gamecenter.feedback.view.suggest

import android.content.Context
import android.view.ViewGroup
import com.alibaba.android.arouter.launcher.ARouter
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.core.utils.MtaHelper
import com.gh.gamecenter.feature.databinding.GameItemBinding
import com.gh.gamecenter.feature.entity.GameEntity
import com.gh.gamecenter.feature.game.GameItemViewHolder
import com.gh.gamecenter.feature.provider.IGameDetailProvider
import com.gh.gamecenter.feedback.R
import com.lightgame.adapter.BaseRecyclerAdapter

class SuggestGameCollectAdapter(
    context: Context,
    private val mGameList: List<GameEntity>
) : BaseRecyclerAdapter<GameItemViewHolder>(context) {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GameItemViewHolder {
        return GameItemViewHolder(GameItemBinding.bind(mLayoutInflater.inflate(R.layout.game_item, parent, false)))
    }

    override fun getItemCount(): Int {
        return mGameList.size
    }

    override fun onBindViewHolder(holder: GameItemViewHolder, position: Int) {
        holder.itemView.setPadding(8F.dip2px(), 4F.dip2px(), 12F.dip2px(), 4F.dip2px())

        val gameEntity = mGameList[position]
        holder.bindGameItem(gameEntity)
        holder.initServerType(gameEntity)
        holder.binding.downloadBtn.text = "查看"
        holder.binding.root.setOnClickListener {
            val provider = ARouter.getInstance().build(RouteConsts.provider.gameDetail).navigation() as? IGameDetailProvider
            provider?.startGameDetailActivity(mContext, gameEntity, "(意见反馈-收录提示)")
            MtaHelper.onEvent("意见反馈", "意见反馈-游戏收录-查看游戏", gameEntity.name)
        }
    }
}