package xn.xxp.main.msds

import android.os.Bundle
import com.blankj.utilcode.util.ActivityUtils
import core.ui.activity.BaseCountDownActivity
import core.util.EscapeUnescape
import core.util.VideoFullScreenWebChromeClient
import core.util.WebViewHelper
import xn.xxp.HomeActivity
import xn.xxp.databinding.ActivityHtmlFullScreenBinding
import xn.xxp.widget.ITitleBar
import xn.xxp.widget.NavViewCompat

/**
 * Html全屏
 *
 * @author ReiChin_
 */
class HtmlFullScreenActivity :
    BaseCountDownActivity<ActivityHtmlFullScreenBinding>() {

    override fun createViewBinding() = ActivityHtmlFullScreenBinding.inflate(layoutInflater)


    private var htmlContent: String? = null
    private var name: String? = null
    private var onEboard: Boolean = false

    override fun initViews(savedInstanceState: Bundle?) {
        htmlContent = intent.getStringExtra("html_content")
        name = intent.getStringExtra("name")
        onEboard = intent.getBooleanExtra("onEboard", false)

        binding.homeLayout.setOnClickListener {
            if (onEboard) {
                logoutCountDownFinish()
            } else {
                ActivityUtils.finishToActivity(HomeActivity::class.java, false)
            }
        }
        binding.backLayout.setOnClickListener { finish() }

        val webViewHelper = WebViewHelper(binding.webView, binding.progressbar)
        webViewHelper.initWebView(webChromeClientProxy = VideoFullScreenWebChromeClient(binding.videoFullScreen))
    }

    override fun initData() {
        binding.titleText.text = name

        if (!htmlContent.isNullOrEmpty()) {
            val html = StringBuilder()
            html.append("<HTML><HEAD></HEAD><body>")
            html.append(EscapeUnescape.unescape(htmlContent))
            html.append("</body></HTML>")

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

    override fun getMTitleBar(): ITitleBar? {
        return null
    }

    override fun getMNavView(): NavViewCompat? {
        return null
    }

    override fun enabledBackCountDown() = true

}