package com.example.chemical.ui.still

import android.graphics.Bitmap
import android.os.Bundle
import android.view.LayoutInflater
import com.example.chemical.ChemicalApp
import com.example.chemical.databinding.ActivityMsdsScreenBinding
import com.example.chemical.ui.common.BaseCountDownActivity
import com.king.zxing.util.CodeUtils
import com.rc.core.log.RcLog
import com.rc.core.ui.activity.RcBaseActivity
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 : RcBaseActivity<ActivityMsdsScreenBinding>() {


    override fun createViewBinding() = ActivityMsdsScreenBinding.inflate(LayoutInflater.from(this))
    override fun initViews(savedInstanceState: Bundle?) {
        super.initViews(savedInstanceState)
        viewBinding.closeScreen.setOnClickListener {
            finish()
        }
    }

    override fun initData() {
        super.initData()
        val stringExtra1 = intent.getStringExtra("mCont")
        val stringExtra2 = intent.getStringExtra("mName")
        val stringExtra = intent.getStringExtra("mId")
        val qrCode: Bitmap = CodeUtils.createQRCode(
            "${HttpConfig.API_BASE_QC_URL}?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"
//        RcLog.info("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
        )

    }
}