"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _constants = require("../constants");

var _androidUtil = require("../utils/androidUtil");

var _businessUtil = require("../utils/businessUtil");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var __extends = void 0 && (void 0).__extends || function () {
  var _extendStatics = function extendStatics(d, b) {
    _extendStatics = Object.setPrototypeOf || {
      __proto__: []
    } instanceof Array && function (d, b) {
      d.__proto__ = b;
    } || function (d, b) {
      for (var p in b) {
        if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
      }
    };

    return _extendStatics(d, b);
  };

  return function (d, b) {
    if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");

    _extendStatics(d, b);

    function __() {
      this.constructor = d;
    }

    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  };
}();

var MBaseComponent =
/** @class */
function (_super) {
  __extends(MBaseComponent, _super);

  function MBaseComponent(props) {
    var _this = _super.call(this, props) || this;

    _this.getCoupon = function (couponId) {
      _this.receiveCoupons({
        couponId: Number(couponId)
      }).then(function (res) {})["catch"](function (_a) {
        var code = _a.code,
            message = _a.message;

        if (code === _constants.respCodeMap.NOT_LOGGED_IN) {
          return;
        }
      });
    };

    _this.goH5Page = function (url) {
      if (url.startsWith('/')) {
        window.MParams && window.MParams.history && window.MParams.history.push(url);
      } else {
        location.href = url;
      }
    };

    _this.clickItem = function (url) {
      var _a = _this.props,
          terminalType = _a.terminalType,
          mode = _a.mode;

      if (window.MParams.noClick || mode !== 'renderer' || !url) {
        return;
      }

      var _b = (0, _businessUtil.parseUrl)(url),
          h5Link = _b.h5Link,
          pcLink = _b.pcLink,
          params = _b.params;

      var type = params.type,
          data = params.data; // 锚点

      if (type === 'ANCHOR') {
        document.getElementById(data.id) && document.getElementById(data.id).scrollIntoView({
          behavior: 'smooth'
        });
        return;
      } // 领取优惠券


      if (type === 'GET_COUPON') {
        _this.getCoupon(data.couponId);

        return;
      }

      if (!(0, _androidUtil.browserVersion)().isApp) {
        terminalType === 'pc' ? window.open(pcLink) : _this.goH5Page(h5Link);
        return;
      }

      if ((0, _androidUtil.browserVersion)().android) {
        (0, _androidUtil.sendToAndroid)({
          type: 'jump',
          params: {
            url: h5Link
          }
        });
      } else if ((0, _androidUtil.browserVersion)().ios) {
        if (type === 'CUSTOMIZED') {
          // 适配ios 从首页跳转自定义页面
          _this.goH5Page(h5Link);
        }

        (0, _androidUtil.sendToIos)(params);
      }
    };

    return _this;
  }

  MBaseComponent.prototype.render = function () {
    return /*#__PURE__*/_react["default"].createElement("div", null, "MBaseComponent");
  };

  return MBaseComponent;
}(_react.Component);

var _default = MBaseComponent;
exports["default"] = _default;