package xn.hxp.ui.still

import android.graphics.Bitmap
import android.os.Bundle
import android.view.LayoutInflater
import androidx.viewbinding.ViewBinding
import xn.hxp.app.ChemicalApp
import xn.hxp.databinding.ActivityMsdsScreenBinding
import com.king.zxing.util.CodeUtils
import com.blankj.utilcode.util.LogUtils
import com.rc.core.ui.activity.BaseActivity
import com.rc.core.util.EscapeUnescape
import com.rc.core.util.VideoFullScreenWebChromeClient
import com.rc.core.util.WebViewHelper
import com.rc.httpcore.HttpConfig
import java.net.URLEncoder

//全屏展示
class MsdsScreenActivity : BaseActivity() {


    lateinit var viewBinding: ActivityMsdsScreenBinding
    override fun setViewBinding(): ViewBinding {
        viewBinding = ActivityMsdsScreenBinding.inflate(layoutInflater)
        return viewBinding
    }

    override fun onInit() {
        viewBinding.closeScreen.setOnClickListener {
            finish()
        }
        val stringExtra1 = intent.getStringExtra("mCont")
        val stringExtra2 = intent.getStringExtra("mName")
        val stringExtra = intent.getStringExtra("mId")
        val qrCode: Bitmap = CodeUtils.createQRCode(
            "https://labcontrol.nwafu.edu.cn/api/?code=$stringExtra&type=1",
            200,
            null
        )

        viewBinding.imgSign.setImageBitmap(qrCode)
        viewBinding.name.text = stringExtra2
        val webViewHelper = WebViewHelper(viewBinding.webView, viewBinding.progressbar)
        webViewHelper.initWebView(
            webChromeClientProxy = VideoFullScreenWebChromeClient(
                viewBinding.videoFullScreen
            )
        )

//        val encodedParam1 = URLEncoder.encode(param1, "UTF-8")
//        val urlWithParams = "$b?url=$encodedParam1"
//        LogUtils.i("fileBrowsers_s:${urlWithParams}")
//        viewBinding.webView.loadUrl(urlWithParams)
        val html = StringBuilder()
        html.append("<HTML><HEAD><LINK href=\"simple_table.css\" type=\"text/css\" rel=\"stylesheet\"/></HEAD><body>")
        html.append(EscapeUnescape.unescape(stringExtra1))
        html.append("</body></HTML>")

        viewBinding.webView.loadDataWithBaseURL(
            "file:///android_asset/",
            html.toString(),
            "text/html",
            "utf-8",
            null
        )
    }

    override fun cdFinish() {
        finish()
    }

    override fun cdTime(cd: Int) {
    }
}