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 _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 { ERRORMESSAGE } from "../../../../constant";
import { EnvironmentEnum, modeEnum, networkModeEnum, osTypeEnum, terminalTypeEnum } from "../../../../types";
import { device, queryParse } from "../../../../util/index";
var BaseElementProcessor = /*#__PURE__*/function () {
  function BaseElementProcessor(options) {
    _classCallCheck(this, BaseElementProcessor);
    _defineProperty(this, "elementContainer", void 0);
    _defineProperty(this, "instanceId", void 0);
    _defineProperty(this, "options", void 0);
    _defineProperty(this, "obtainDataRes", void 0);
    _defineProperty(this, "elementUrl", void 0);
    _defineProperty(this, "eventCenter", void 0);
    _defineProperty(this, "eventListener", {});
    this._setOptions(options);
  }
  _createClass(BaseElementProcessor, [{
    key: "_setOptions",
    value: function _setOptions(options) {
      var _this = this;
      var _setEnv = function _setEnv() {
        var _queryParse = queryParse(),
          _moreEnv = _queryParse._moreEnv;
        if (options !== null && options !== void 0 && options.environment && !((options === null || options === void 0 ? void 0 : options.environment) in EnvironmentEnum) && _moreEnv !== 'true') {
          console.warn(ERRORMESSAGE.INIT_PARAMETER_ERROR.ENVIRONMENT_ERROR.message);
          options.environment = 'prod';
        }
        _this.options.env = {
          terminalType: device.isMobile ? terminalTypeEnum.WAP : terminalTypeEnum.WEB,
          environment: (options === null || options === void 0 ? void 0 : options.environment) || 'prod'
        };
        if (_this.options.env.terminalType === terminalTypeEnum.WAP) {
          // eslint-disable-next-line no-nested-ternary
          _this.options.env.osType = device.iOS ? osTypeEnum.IOS : device.Android ? osTypeEnum.ANDROID : osTypeEnum.ELSE;
        }
      };
      var _setMode = function _setMode() {
        _this.options.mode = (options === null || options === void 0 ? void 0 : options.mode) || modeEnum.component;
        if (options !== null && options !== void 0 && options.mode && !((options === null || options === void 0 ? void 0 : options.mode) in modeEnum)) {
          console.warn(ERRORMESSAGE.INIT_PARAMETER_ERROR.MODE_ERROR.message);
          _this.options.mode = modeEnum.component;
        }
        _this.options.networkMode = (options === null || options === void 0 ? void 0 : options.networkMode) || networkModeEnum.session;
        if (options !== null && options !== void 0 && options.networkMode && !((options === null || options === void 0 ? void 0 : options.networkMode) in networkModeEnum)) {
          console.warn(ERRORMESSAGE.INIT_PARAMETER_ERROR.NET_MODE_NOT_SUPPORT.message);
          _this.options.networkMode = networkModeEnum.proxy;
        }
      };
      this.options = {};
      _setMode();
      _setEnv();
      this.options.locale = (options === null || options === void 0 ? void 0 : options.locale) || '';
      this.options.product = options === null || options === void 0 ? void 0 : options.product;
    }
  }, {
    key: "registerElementContainer",
    value:
    // 添加 update 方法的抽象声明
    function registerElementContainer(elementContainer) {
      this.elementContainer = elementContainer;
    }
  }, {
    key: "registerEventCenter",
    value: function registerEventCenter(eventCenter) {
      this.eventCenter = eventCenter;
    }
  }, {
    key: "registerEventListener",
    value: function registerEventListener(event, callback) {
      this.eventCenter[event] = callback;
    }
  }, {
    key: "setElementUrl",
    value: function setElementUrl(url) {
      this.elementUrl = url;
    }
  }, {
    key: "getElementUrl",
    value: function getElementUrl() {
      return this.elementUrl;
    }
  }, {
    key: "getObtainDataRes",
    value: function getObtainDataRes() {
      return this.obtainDataRes;
    }
  }]);
  return BaseElementProcessor;
}();
export default BaseElementProcessor;