import { pmb } from "../bridge";

let _this = null;
class Router {
  actionName = "router";

  constructor() {
    _this = this;
  }

  default(params = {}, mergeParams = { action: this.actionName, ...params }) {
    if (!params) throw new Error("传入的params参数错误");
    return new Promise((resolve, reject) => pmb.publish(mergeParams, (e) => resolve(e)));
  }

  toTargetRouter(userParams = {}) {
    return new Promise((resolve, reject) => {
      this.$tab.openPage(userParams.title, userParams.url);
      console.log(userParams);
      resolve();
    });
  }

  iframeToTargetRouter(userParams = {}) {
    return _this.default({
      method: "toTargetUrl",
      params: { ...userParams }
    });
  }

  componentCreated(userParams = {}) {
    return new Promise(async (resolve, reject) => {
      return await this.loadedInit();
    });
  }

}

export default Router;