package com.gh.gamecenter.home.custom.viewholder

import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.common.utils.ImageUtils
import com.gh.gamecenter.common.utils.goneIf
import com.gh.gamecenter.databinding.BigImageRecommendItemCustomBinding
import com.gh.gamecenter.home.custom.CustomPageViewModel
import com.gh.gamecenter.home.custom.eventlistener.OtherItemEventHelper
import com.gh.gamecenter.home.custom.model.CustomContentCardItem
import com.gh.gamecenter.home.custom.model.CustomPageItem

/**
 * 内容卡片
 * 提问、帖子、视频帖、文章
 */
class CustomBigImageRecommendViewHolder(
    viewModel: CustomPageViewModel,
    val binding: BigImageRecommendItemCustomBinding
) : BaseCustomViewHolder(viewModel, binding.root) {

    override val childEventHelper by lazy(LazyThreadSafetyMode.NONE) {
        OtherItemEventHelper(viewModel)
    }

    override fun bindView(item: CustomPageItem) {
        super.bindView(item)
        if (item is CustomContentCardItem) {
            val contentCard = item.data
            binding.run {
                ImageUtils.display(poster, contentCard.img)
                recommendTag.goneIf(contentCard.recommendTag.isEmpty())
                recommendTextTwo.goneIf(contentCard.secondLineRecommend.isEmpty())
                recommendTag.text = contentCard.recommendTag
                recommendTextOne.text = contentCard.firstLineRecommend
                recommendTextTwo.text = contentCard.secondLineRecommend
                root.setOnClickListener {
                    val linkEntity =
                        LinkEntity(
                            link = item.link.link,
                            type = item.link.type,
                            text = item.link.text
                        )
                    childEventHelper.directToLinkPage(linkEntity)
                }
            }
        }
    }
}