package com.yidian.shenghuoquan.buserorder.app

import android.content.Intent
import com.yidian.bcommon.app.YdBaseApplication
import com.yidian.bcommon.constant.XRouterPathConstants
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

@YacModuleSpec
class BOrderApplication: YdBaseApplication() {

  override fun onCreate() {
    super.onCreate()
    if (ProcessUtil.isMainProcess(this)) {
      registerXPage()
      initService()
    }
  }

  private fun 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)
        }
      })
      XPageManager.registeredNode(node)
    }
  }
}
