function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { addInlineLoading, createInlineBaseElement } from "../../../component/component.inline.style";
import { addPopupLoading, createBaseElement } from "../../../component/component.popup.style";
import { insertStyleSheet } from "../../../component/popupWindow.style";
import { closeImg, closeImgLight, COMPONENT_CLOSE_BLOCK_ID, COMPONENT_CLOSE_MASK_BLOCK_ID, COMPONENT_CONTAINER_ID, ERRORMESSAGE, EVENT, LOADING_ID, MOCKUP_ID, TIMEOUT_WEB_APP_HEART_BEAT, TIME_DELAY_SEND_HEART_BEAT } from "../../../constant";
import { DisplayTypeEnum, ProductSceneEnum } from "../../../types";
import { isEmpty } from "../../../util";
import { ServiceProvider } from "../index";
import { PopupManager } from "./popup";
import { createIframe, startSizeChangeAnim } from "./utils";

/**
 * @author 谦彧 <zhangmian.zm@alipay.com>
 * @date 2024/9/17
 */
var MAX_CLEAR_TIME = 10000;
export var ContainerService = /*#__PURE__*/function () {
  function ContainerService() {
    _classCallCheck(this, ContainerService);
    _defineProperty(this, "instanceId", void 0);
    _defineProperty(this, "sdkMetaData", void 0);
    _defineProperty(this, "initMessageEvent", void 0);
    _defineProperty(this, "clearTimerIdMapping", {});
    _defineProperty(this, "popupManager", void 0);
    _defineProperty(this, "eventCenter", void 0);
    _defineProperty(this, "logService", void 0);
    _defineProperty(this, "displayInfo", void 0);
    _defineProperty(this, "webApp", void 0);
    _defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
    _defineProperty(this, "clientHeight", void 0);
    _defineProperty(this, "boundFocusResizeChange", void 0);
    // if this variable is true, SDK will invoke listener instead of showing loading
    _defineProperty(this, "customizedLoadingListener", void 0);
  }
  _createClass(ContainerService, [{
    key: "destroy",
    value: function destroy() {}
  }, {
    key: "init",
    value: function init(initOptions, instanceId, sdkMetaData) {
      var _window;
      this.instanceId = instanceId;
      this.sdkMetaData = sdkMetaData;
      this.clientHeight = Math.max(window.innerHeight, ((_window = window) === null || _window === void 0 || (_window = _window.visualViewport) === null || _window === void 0 ? void 0 : _window.height) || 0);
      this.eventCenter = ServiceProvider.getInstance(instanceId).getService('EventCenter');
      this.logService = ServiceProvider.getInstance(instanceId).getService('Log');
      this.popupManager = new PopupManager();
      // element因涉及多组件联动，消息接受处理在产品层进行
      var notAddEventCenter = Boolean(Object.keys(initOptions).length) && sdkMetaData.productScene === ProductSceneEnum.ELEMENT_PAYMENT;
      if (!notAddEventCenter) {
        this.addCapabilityToEventCenter();
      }
      this.addCapabilityToApiBusManager();
      // bind会返回一个新的方法，init时记录上这个focus，不然window.addEventListener时this指向会变成window
      this.boundFocusResizeChange = this.focusResizeChange.bind(this);
    }
  }, {
    key: "update",
    value: function update() {}
  }, {
    key: "load",
    value: function load(displayInfo, url, closeBtnFunc) {
      var appendAliasContainerId = displayInfo.appendAliasContainerId,
        selector = displayInfo.selector,
        type = displayInfo.type,
        platform = displayInfo.platform;
      var webApp = createIframe('antom-sdk-web-app' + (displayInfo.appendAliasContainerId ? "-".concat(selector) : ''));
      if (!isEmpty(displayInfo === null || displayInfo === void 0 ? void 0 : displayInfo.iframeStyle)) {
        Object.keys(displayInfo === null || displayInfo === void 0 ? void 0 : displayInfo.iframeStyle).forEach(function (key) {
          var _displayInfo$iframeSt;
          webApp.style[key] = displayInfo === null || displayInfo === void 0 || (_displayInfo$iframeSt = displayInfo.iframeStyle) === null || _displayInfo$iframeSt === void 0 ? void 0 : _displayInfo$iframeSt[key];
        });
      }
      this.webApp = webApp;
      this.displayInfo = displayInfo;
      webApp.src = url;
      webApp.allow = 'payment';
      this.eventCenter.addIFrame(webApp);
      if (webApp.src.includes('?')) {
        this.popupManager.setPopupUrlQuery(webApp.src.split('?')[1]);
      }
      // TODO call ApiBusManager to add listener to iframe, componentApp line 979

      // create container and append web app
      var container = type === DisplayTypeEnum.inline ? createInlineBaseElement(selector, appendAliasContainerId ? "".concat(COMPONENT_CONTAINER_ID, "-").concat((selector === null || selector === void 0 ? void 0 : selector.indexOf('#')) === -1 ? selector : selector.slice(1)) : '') : createBaseElement(platform, closeBtnFunc);
      container.appendChild(webApp);
      return container;
    }
  }, {
    key: "cleanContainer",
    value: function cleanContainer(displayInfo) {
      var _document$getElementB;
      // selector and container
      var selector = (displayInfo === null || displayInfo === void 0 ? void 0 : displayInfo.type) === DisplayTypeEnum.inline ? displayInfo.selector : COMPONENT_CONTAINER_ID;
      var selectorDom = document.querySelector(selector);
      if (selectorDom) {
        selectorDom.innerHTML = '';
      }
      var container = document.getElementById(COMPONENT_CONTAINER_ID);
      if (container) container === null || container === void 0 || container.remove();
      this.webApp = null;
      this.eventCenter.cleanIFrames();

      // animation
      (_document$getElementB = document.getElementById("".concat(COMPONENT_CONTAINER_ID, "-").concat(displayInfo === null || displayInfo === void 0 ? void 0 : displayInfo.platform, "-animation-style"))) === null || _document$getElementB === void 0 || _document$getElementB.remove();
    }
  }, {
    key: "showLoading",
    value: function showLoading(container, displayInfo) {
      if (this.customizedLoadingListener) {
        this.customizedLoadingListener('SDK_START_OF_LOADING');
        return;
      }
      if (displayInfo.type === DisplayTypeEnum.inline) {
        addInlineLoading(container, displayInfo.platform);
      } else {
        var mockup = document.getElementById(MOCKUP_ID);
        if (mockup) mockup.style.display = 'block';
        addPopupLoading();
      }
    }
  }, {
    key: "dismissLoading",
    value: function dismissLoading() {
      var _document$getElementB2;
      var isKeepMockup = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
      if (this.customizedLoadingListener) {
        this.customizedLoadingListener('SDK_END_OF_LOADING');
        return;
      }
      var mockup = document.getElementById(MOCKUP_ID);
      if (mockup) {
        mockup.style.background = 'rgb(0, 0, 0, 0.6)';
        mockup.style.display = isKeepMockup ? 'block' : 'none';
      }
      (_document$getElementB2 = document.getElementById(LOADING_ID)) === null || _document$getElementB2 === void 0 || _document$getElementB2.remove();
    }
  }, {
    key: "customizeLoading",
    value: function customizeLoading(listener) {
      this.customizedLoadingListener = listener;
    }
  }, {
    key: "startHideAnim",
    value: function startHideAnim() {
      var _this$displayInfo;
      var container = document.getElementById(COMPONENT_CONTAINER_ID);
      if (this.webApp) this.webApp.style.height = container.style.height;
      if (container && (_this$displayInfo = this.displayInfo) !== null && _this$displayInfo !== void 0 && _this$displayInfo.platform) {
        // size变化动画取消
        container.style.transition = '';
        container === null || container === void 0 || container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.displayInfo.platform));
        container === null || container === void 0 || container.classList.remove("".concat(COMPONENT_CONTAINER_ID, "-").concat(this.displayInfo.platform, "-animation"));
        container === null || container === void 0 || container.classList.add("".concat(COMPONENT_CONTAINER_ID, "-hidden-").concat(this.displayInfo.platform));
      }
    }
  }, {
    key: "handleAccountFocus",
    value: function handleAccountFocus(focus) {
      var _window$visualViewpor, _window2;
      // 失焦时v2会走默认的sizeChange还原高度，这里仅移除监听
      (_window$visualViewpor = window.visualViewport) === null || _window$visualViewpor === void 0 || _window$visualViewpor.removeEventListener('resize', this.boundFocusResizeChange);
      (_window2 = window) === null || _window2 === void 0 || _window2.removeEventListener('resize', this.boundFocusResizeChange);
      // 只有聚焦才监听，失焦后移除，避免影响别的场景
      if (focus) {
        var _window$visualViewpor2;
        // 监听页面visualViewport的高度变化，适用于主流机型更精准获取当前页面高度
        (_window$visualViewpor2 = window.visualViewport) === null || _window$visualViewpor2 === void 0 || _window$visualViewpor2.addEventListener('resize', this.boundFocusResizeChange);
        // 兼容visualViewport处理不到的场景，一般存在于老版本浏览器
        window.addEventListener('resize', this.boundFocusResizeChange);
      }
    }
  }, {
    key: "addCapabilityToEventCenter",
    value: function addCapabilityToEventCenter() {
      var _this = this;
      this.eventCenter.listen(EVENT.dismissLoading.name, function () {
        _this.dismissLoading();
      });
      this.eventCenter.listen(EVENT.getUserAgentFromSdk.name, function (data, payload) {
        var _payload$context;
        _this.eventCenter.dispatchToApp({
          event: 'appEventCallback',
          eventCallbackId: (_payload$context = payload.context) === null || _payload$context === void 0 ? void 0 : _payload$context.eventCallbackId,
          data: {
            userAgent: window.navigator.userAgent
          }
        });
      });
      this.eventCenter.listen(EVENT.popupWindow.name, function (data) {
        _this.handlePopupWindow(data);
      });
      this.eventCenter.listen(EVENT.popWindow.name, function () {
        _this.popupManager.pop();
      });
      this.eventCenter.listen(EVENT.sizeChanged.name, function (data) {
        _this.handleSizeChanged(_objectSpread({}, data));
      });
      this.eventCenter.listen(EVENT.showCloseButton.name, function (data) {
        _this.handleCloseButtonTheme(data.style);
        _this.changeCloseBtnVisibility(true);
      });
      this.eventCenter.listen(EVENT.hideCloseButton.name, function () {
        _this.changeCloseBtnVisibility(false);
      });
      this.eventCenter.listen(EVENT.setMaskCloseButton.name, function (data) {
        _this.handleMaskCloseBtnShow(data);
      });
      this.eventCenter.listen(EVENT.appHeartBeat.name, function () {
        _this.handleAppHeartBeat();
      });
      this.eventCenter.listen(EVENT.canIUse.name, function (data, payload) {
        _this.handleCanIUse(data, payload);
      });
      /**
       * 目前仅用于ESP V2的 web sdk
       * 原因： 在账户输入页和OTP页面的h5场景下键盘弹起页面会有问题，iframe有固定高度，键盘弹起时应用层不会触发大小变化
       *   account账号输入页需要在sdk监听键盘弹起后高度变化并修改iframe及iframe外层容器，account需要按钮置底的放在键盘上面，必须修改高度而不是让容器定位
       *   otp页面需要在聚焦时给iframe及外层容器设置fixed定位，让页面不被弹起
       * 目的： esp页面输入框聚焦/失焦后给sdk发送消息
       */
      this.eventCenter.listen(EVENT.inputFocus.name, function (data) {
        // 账号输入页需要修改iframe高度
        if (data.source === 'ESP_V2' && data.type === 'account') {
          _this.handleAccountFocus(data.focus);
          // otp页面需要定位元素
        } else if (data.source === 'ESP_V2' && data.type === 'otp') {
          _this.focusScrollFixed(data.focus);
        }
      });
    }
  }, {
    key: "addCapabilityToApiBusManager",
    value: function addCapabilityToApiBusManager() {}
  }, {
    key: "updateMaskCloseBtn",
    value: function updateMaskCloseBtn(data) {
      var maskCloseBtn = document.getElementById("".concat(COMPONENT_CLOSE_MASK_BLOCK_ID));
      if (maskCloseBtn) {
        if (this.displayInfo.platform === 'desktop') {
          var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
          var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
          maskCloseBtn.style.top = "".concat((windowHeight - data.height) / 2 - 42, "px");
          maskCloseBtn.style.right = "".concat((windowWidth - data.width) / 2 + 18, "px");
        } else {
          maskCloseBtn.style.bottom = "".concat(data.height + 2, "px");
        }
      }
    }
  }, {
    key: "handleSizeChanged",
    value: function handleSizeChanged(data) {
      var _this$displayInfo2 = this.displayInfo,
        appendAliasContainerId = _this$displayInfo2.appendAliasContainerId,
        selector = _this$displayInfo2.selector;
      var cashierId = appendAliasContainerId ? "".concat(COMPONENT_CONTAINER_ID, "-").concat((selector === null || selector === void 0 ? void 0 : selector.indexOf('#')) === -1 ? selector : selector.slice(1)) : COMPONENT_CONTAINER_ID;
      if (!this.webApp || !this.displayInfo) {
        return;
      }
      var cashier = document.getElementById(cashierId);
      if (!cashier || (data === null || data === void 0 ? void 0 : data.height) <= 1 || data.height === parseInt(cashier.style.height)) return;
      cashier.style.height = "".concat(data.height, "px");
      this.webApp.style.opacity = '1';
      if (this.displayInfo.type === DisplayTypeEnum.popup) {
        if (this.displayInfo.platform === 'desktop') {
          if (data.width) cashier.style.width = "".concat(data.width, "px");
          cashier.classList.add("".concat(cashierId, "-").concat(this.displayInfo.platform, "-animation"));
          this.webApp.style.height = "".concat(data.height, "px");
        }
        if (this.displayInfo.platform === 'mobile') {
          cashier.classList.add("".concat(cashierId, "-").concat(this.displayInfo.platform, "-animation"));
          var animationStyleId = "".concat(cashierId, "-").concat(this.displayInfo.platform, "-animation-style");
          var animationStyle = document.getElementById(animationStyleId);
          if (animationStyle) animationStyle === null || animationStyle === void 0 || animationStyle.remove();

          // 此style用于弹窗出现和高度变化时动画，动画不同，属性不同
          this.webApp.style.height = parseInt(this.webApp.style.height) > 0 ? '100%' : "".concat(data.height, "px");
          startSizeChangeAnim(cashier, data.height, animationStyleId);
        }
        // 关闭loading，保留蒙层
        this.dismissLoading();
        // 更新弹窗关闭按钮位置
        this.updateMaskCloseBtn(data);
      }
      if (this.displayInfo.type === DisplayTypeEnum.inline) {
        var _document$getElementB3;
        (_document$getElementB3 = document.getElementById(LOADING_ID)) === null || _document$getElementB3 === void 0 || _document$getElementB3.remove();
        this.webApp.style.height = "".concat(data.height, "px");
      }
    }

    // 目前仅用于esp账号输入页聚焦
  }, {
    key: "focusResizeChange",
    value: function focusResizeChange() {
      var _window3;
      // 计算出当前iframe应有的高度，需要和顶部留有距离
      var webPageHeightRatio = 0.9;
      var browserPageHeightFocusRatio = 0.9;
      // sdk层才能拿到当前键盘弹起后页面的高度
      var height = ((_window3 = window) === null || _window3 === void 0 || (_window3 = _window3.visualViewport) === null || _window3 === void 0 ? void 0 : _window3.height) || window.innerHeight;
      height = height * webPageHeightRatio;
      height = height * browserPageHeightFocusRatio;
      // 调用handleSizeChanged修改iframe高度
      this.handleSizeChanged({
        width: 0,
        height: height
      });
    }

    // 目前仅用于esp otp页面账号聚焦
  }, {
    key: "focusScrollFixed",
    value: function focusScrollFixed(focus) {
      // 获取iframe dom元素
      var _this$displayInfo3 = this.displayInfo,
        appendAliasContainerId = _this$displayInfo3.appendAliasContainerId,
        selector = _this$displayInfo3.selector;
      var cashierId = appendAliasContainerId ? "".concat(COMPONENT_CONTAINER_ID, "-").concat((selector === null || selector === void 0 ? void 0 : selector.indexOf('#')) === -1 ? selector : selector.slice(1)) : COMPONENT_CONTAINER_ID;
      if (!this.webApp || !this.displayInfo) {
        return;
      }
      var cashier = document.getElementById(cashierId);
      if (!cashier) return;
      // 输入框聚焦时修改定位信息和top距离
      if (focus) {
        cashier.style.setProperty('position', 'fixed', 'important');
        cashier.style.setProperty('top', "".concat(this.clientHeight - cashier.clientHeight, "px"), 'important');
      } else {
        // 失焦时移除定位信息
        cashier.style.removeProperty('position');
        cashier.style.removeProperty('top');
      }
    }
  }, {
    key: "handleAppHeartBeat",
    value: function handleAppHeartBeat() {
      var _this2 = this;
      try {
        if (!this._webAppHeartBeatTimeoutFn) {
          this._webAppHeartBeatTimeoutFn = function () {
            if (_this2.webApp && _this2.displayInfo) {
              _this2.logService.logError({
                title: 'sdk_error_appHeartBeatTimeout'
              });
            }
          };
        }
        if (window._webAppHeartBeatTimeoutId) {
          clearTimeout(window._webAppHeartBeatTimeoutId);
          window._webAppHeartBeatTimeoutId = null;
        }
        if (this._webAppHeartBeatTimeoutFn) {
          window._webAppHeartBeatTimeoutId = setTimeout(this._webAppHeartBeatTimeoutFn, TIMEOUT_WEB_APP_HEART_BEAT);
        }
        setTimeout(function () {
          if (_this2.webApp && _this2.displayInfo) {
            _this2.eventCenter.dispatchToApp({
              event: 'sdkHeartBeat',
              data: {}
            });
          }
        }, TIME_DELAY_SEND_HEART_BEAT);
      } catch (error) {
        this.logService.logError({
          title: 'sdk_error_handleAppHeartBeat'
        }, {
          errorMessage: error.message
        });
      }
    }
  }, {
    key: "changeCloseBtnVisibility",
    value: function changeCloseBtnVisibility(isShow) {
      var closeBlock = document.getElementById(COMPONENT_CLOSE_BLOCK_ID);
      if (isShow) {
        closeBlock === null || closeBlock === void 0 || closeBlock.classList.remove("".concat(COMPONENT_CLOSE_BLOCK_ID, "-hidden"));
      } else if (isShow === false) {
        closeBlock === null || closeBlock === void 0 || closeBlock.classList.add("".concat(COMPONENT_CLOSE_BLOCK_ID, "-hidden"));
      }
    }
  }, {
    key: "handleMaskCloseBtnShow",
    value: function handleMaskCloseBtnShow(data) {
      var closeBlock = document.getElementById(COMPONENT_CLOSE_MASK_BLOCK_ID);
      if ((data === null || data === void 0 ? void 0 : data.status) === 'show') {
        closeBlock === null || closeBlock === void 0 || closeBlock.classList.remove("".concat(COMPONENT_CLOSE_MASK_BLOCK_ID, "-hidden"));
      } else {
        closeBlock === null || closeBlock === void 0 || closeBlock.classList.add("".concat(COMPONENT_CLOSE_MASK_BLOCK_ID, "-hidden"));
      }
    }
  }, {
    key: "handleCloseButtonTheme",
    value: function handleCloseButtonTheme(style) {
      if (!style) return;
      var closeBlock = document.getElementById(COMPONENT_CLOSE_BLOCK_ID);
      var closeButtonImg = closeBlock === null || closeBlock === void 0 ? void 0 : closeBlock.querySelector('img');
      var maskCloseBlock = document.getElementById(COMPONENT_CLOSE_MASK_BLOCK_ID);
      if (style === 'light') {
        closeButtonImg === null || closeButtonImg === void 0 || closeButtonImg.setAttribute('src', closeImgLight);
        closeBlock === null || closeBlock === void 0 || closeBlock.classList.add("".concat(COMPONENT_CLOSE_BLOCK_ID, "-light"));
        maskCloseBlock === null || maskCloseBlock === void 0 || maskCloseBlock.classList.add("".concat(COMPONENT_CLOSE_MASK_BLOCK_ID, "-light"));
      } else {
        closeButtonImg === null || closeButtonImg === void 0 || closeButtonImg.setAttribute('src', closeImg);
        closeBlock === null || closeBlock === void 0 || closeBlock.classList.remove("".concat(COMPONENT_CLOSE_BLOCK_ID, "-light"));
        maskCloseBlock === null || maskCloseBlock === void 0 || maskCloseBlock.classList.remove("".concat(COMPONENT_CLOSE_MASK_BLOCK_ID, "-light"));
      }
    }

    // SDK主动打开弹框
  }, {
    key: "handlePopupWindow",
    value: function handlePopupWindow(data) {
      var _this$displayInfo4,
        _this3 = this;
      if (data.paymentElementOldModel) return;
      insertStyleSheet();
      this.popupManager.popup(_objectSpread({
        platform: (_this$displayInfo4 = this.displayInfo) === null || _this$displayInfo4 === void 0 ? void 0 : _this$displayInfo4.platform,
        showCloseOnLoading: data.showCloseOnLoading,
        onCloseOnLoading: function onCloseOnLoading() {
          return _this3.handlePopWindow(data);
        }
      }, data)).then(function () {
        _this3.eventCenter.addIFrame(_this3.popupManager.popupApp);
      }).catch(function (error) {
        _this3.logService.logError({
          title: (error === null || error === void 0 ? void 0 : error.title) || 'sdk_error_create_pop_up'
        }, error);
        _this3.eventCenter.emit(EVENT.error.name, ERRORMESSAGE.CREATECOMPONENT_ERROR.LOAD_APP_TIMEOUT);
      });
    }

    // SDK主动关闭弹框
  }, {
    key: "handlePopWindow",
    value: function handlePopWindow(data) {
      this.popupManager.pop();
      this.eventCenter.dispatchToApp({
        event: EVENT.popWindow.name,
        data: data
      });
    }
  }, {
    key: "handleCanIUse",
    value: function handleCanIUse(data, payload) {
      var _payload$context3;
      // 前置校验
      var funcName = data === null || data === void 0 ? void 0 : data.funcName;
      if (!funcName || typeof funcName !== 'string') {
        var _payload$context2;
        this.eventCenter.dispatchToApp({
          event: 'appEventCallback',
          eventCallbackId: (_payload$context2 = payload.context) === null || _payload$context2 === void 0 ? void 0 : _payload$context2.eventCallbackId,
          data: {
            exist: false,
            success: false
          }
        });
        return;
      }
      var exist = this.eventCenter.isExist(funcName);
      this.eventCenter.dispatchToApp({
        event: 'appEventCallback',
        eventCallbackId: (_payload$context3 = payload.context) === null || _payload$context3 === void 0 ? void 0 : _payload$context3.eventCallbackId,
        data: {
          exist: exist,
          success: true
        }
      });
    }
  }, {
    key: "getWebApp",
    value: function getWebApp() {
      return this.webApp;
    }
  }]);
  return ContainerService;
}();