package com.za.base

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.Composable
import com.tencent.smtt.sdk.QbSdk
import com.za.base.BaseVm.Companion.showTipDialog
import com.za.base.theme.DealerTheme
import com.za.base.view.CommonDialog
import com.za.base.view.LoadingManager
import com.za.common.log.LogUtil

abstract class BaseActivity : PushMessageActivity() {
	protected val TAG by lazy { javaClass.simpleName }

	override fun onCreate(savedInstanceState : Bundle?) {
		super.onCreate(savedInstanceState)
		enableEdgeToEdge()
		setContent {
			DealerTheme {
				ContentView()
				if (LoadingManager.showLoading.value) {
					LoadingManager.LoadingView()
				}

				if (showTipDialog.value != null) {
					CommonDialog(message = showTipDialog.value ?: "",
						title = "提示",
						confirmText = "我已了解",
						confirm = { BaseVm.hideTipDialog() },
						cancel = { BaseVm.hideTipDialog() },
						dismiss = { BaseVm.hideTipDialog() },
						cancelEnable = true)
				}
			}
		}

		QbSdk.initX5Environment(this.application, object : QbSdk.PreInitCallback {
			override fun onCoreInitFinished() { // 内核初始化完成，可能为系统内核，也可能为系统内核
				LogUtil.print("initX5Environment ", "finish")

			}

			/**
			 * 预初始化结束
			 * 由于X5内核体积较大，需要依赖网络动态下发，所以当内核不存在的时候，默认会回调false，此时将会使用系统内核代替
			 * @param isX5 是否使用X5内核
			 */
			override fun onViewInitFinished(isX5 : Boolean) {
				LogUtil.print("onViewInitFinished ", "isX5=$isX5")
			}
		})
	}

	@Composable
	abstract fun ContentView()

}

