package com.yidian.shenghuoquan.xbirdbusiness.app

import android.content.Intent
import com.yidian.common.XRouterPathConstants
import com.yidian.common.YdBaseApplication
import com.yidian.news.util.ProcessUtil
import com.yidian.xpage.XPageManager
import com.yidian.xpage.node.XPageHandler
import com.yidian.xpage.node.XPageNode
import com.yidian.xpage.node.XPageNodePageType
import com.yidian.yac.core.core.YacModuleSpec
import timber.log.Timber

@YacModuleSpec
class XBirdBusinessApplication : YdBaseApplication() {

  override fun onCreate() {
    super.onCreate()
    if (ProcessUtil.isMainProcess(this)) {
      Timber.tag("注册").e("开始注册")
      registerXPage()
      initService()
    }
  }

  private fun registerXPage() {
    ClassMapUtil.xPageNodeMap.forEach {
      val node = XPageNode(it.key, XPageNodePageType.NATIVE, object : XPageHandler {
        override fun handler(params: Map<String, Any?>?) {
          val intent = Intent()
          if (params != null) {
            intent.putExtra(XRouterPathConstants.ParamsKey, params as HashMap)
          }
          intent.setClass(context, it.value)
          intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
          context.startActivity(intent)
          Timber.e("startActivity 开启WebView ")
        }
      })
      XPageManager.registeredNode(node)
      Timber.e("注册XPage ${it.key}")
    }
  }

  private fun initService() {
  }

}
