package com.gh.gamecenter.adapter.viewholder

import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.gh.common.constant.Config
import com.gh.common.util.DirectUtils
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.core.utils.DisplayUtils
import com.gh.gamecenter.databinding.FragmentWebWarningBinding

class UnAvaliableWebviewViewHolder(val binding: FragmentWebWarningBinding) : RecyclerView.ViewHolder(binding.root) {

    fun bindView() {
        bindView(0f)
    }

    fun bindView(newHeight: Float) {
        if (newHeight > 0) {
            (binding.root.layoutParams as ViewGroup.LayoutParams).apply {
                height = newHeight.dip2px()
                binding.root.layoutParams = this
            }
        }
        val layoutParam = binding.reuseNoneData.reuseResetLoadTv.layoutParams
        layoutParam.width = DisplayUtils.dip2px(160F)
        binding.reuseNoneData.reuseResetLoadTv.layoutParams = layoutParam
        binding.reuseNoneData.reuseNoneDataTv.text = "暂时无法显示网页内容"
        binding.reuseNoneData.reuseNoneDataDescTv.text = "当前设备浏览器内核版本较低，无法展示内容，可前往更新版本或联系客服"
        binding.reuseNoneData.reuseResetLoadTv.text = "前往更新版本"
        binding.reuseNoneData.reuseResetLoadTv.visibility = View.VISIBLE
        binding.reuseNoneData.reuseResetLoadTv.setOnClickListener {
            val webviewDownloadUrl = Config.getSettings()?.webviewDownloadUrl
            if (!webviewDownloadUrl.isNullOrEmpty()) {
                DirectUtils.directToExternalBrowser(binding.root.context, webviewDownloadUrl)
            }
        }
    }
}