package com.gh.gamecenter.message.view.concern

import androidx.viewbinding.ViewBinding
import com.therouter.TheRouter
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.constant.RouteConsts
import com.gh.gamecenter.core.provider.IConcernGiftPackUtilsProvider
import com.gh.gamecenter.feature.entity.ConcernEntity
import com.gh.gamecenter.feature.provider.ICommentUtilsProvider
import com.gh.gamecenter.feature.view.GameIconView

class ConcernGiftPackViewHolder(
    private val binding: ViewBinding,
    private val provider: IConcernGiftPackUtilsProvider,
    private val listener: OnConcernContentEventListener
) :
    BaseRecyclerViewHolder<ConcernEntity>(binding.root) {

    fun bind(concernEntity: ConcernEntity, position: Int) {
        provider.initStyle(binding)
        val game = concernEntity.game
        if (game != null) {
            (provider.getIvGameIcon(binding) as? GameIconView)?.displayGameIcon(
                game.getIcon(),
                game.iconSubscript,
                game.iconFloat
            )
        } else {
            (provider.getIvGameIcon(binding) as? GameIconView)?.displayGameIcon(
                concernEntity.gameIcon,
                null,
                null
            )
        }

        provider.getTvGameName(binding).text = game?.name ?: ""
        val commentUtils = TheRouter.get(ICommentUtilsProvider::class.java)
        commentUtils?.setCommentTime(provider.getTvTime(binding), concernEntity.time)
        provider.getTvGiftPackName(binding).text = concernEntity.name
        provider.getTvGiftPackContent(binding).text = concernEntity.content


        arrayOf(provider.getIvGameIcon(binding), provider.getTvGameName(binding)).forEach {
            it.setOnClickListener {
                listener.onGameCLick(position, game?.toGameEntity())
            }
        }

        itemView.setOnClickListener {
            listener.onGiftPackageClick(position, concernEntity)
        }
    }
}