package com.yidian.bcommon.services

import com.yidian.xarc.xrouter.ResultResolver
import com.yidian.xpage.XPageManager
import com.yidian.yac.core.zap.ZapService

/**
 * @description: xpage服务类
 * @author: huyajun
 * @date:  2020/9/27
 **/

class XPageService : ZapService() {
  companion object {
    const val SERVICE_NAME: String = "xpage"
  }

  override fun onAction(
    path: String,
    action: String,
    params: Any,
    options: Any,
    resolver: ResultResolver
  ) {
    params as Map<String, Any>
    val name = params["pageName"] as String
    val pageParams = params["pageParams"] as Map<String, Any>
    when (action) {
      "push" -> {
        XPageManager.push(name, pageParams)
      }
      "pop" -> {
        XPageManager.pop(pageParams)
      }
      "popTo" -> {
        XPageManager.popTo(name, pageParams)
      }
      "popToRoot" -> {
        XPageManager.popToRoot(pageParams)
      }
    }
  }

  override fun onInit() {
  }

  override fun onExit() {
  }


}
