"use strict";

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

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

var _classnames = _interopRequireDefault(require("classnames"));

require("./index.less");

var _coreUtil = require("../../../utils/coreUtil");

var _decorator = require("../../../decorator");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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); }

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 (b.hasOwnProperty(p)) d[p] = b[p];
      }
    };

    return _extendStatics(d, b);
  };

  return function (d, b) {
    _extendStatics(d, b);

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

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

var __decorate = void 0 && (void 0).__decorate || function (decorators, target, key, desc) {
  var c = arguments.length,
      r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
      d;
  if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
    if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  }
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};

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

  function Image() {
    var _this = _super !== null && _super.apply(this, arguments) || this;

    _this.state = {
      // 当仅作为一个图片时，鼠标移上去，hover状态
      hoverImgSrc: false
    };

    _this.getStyle = function () {
      var _a = _this.props,
          data = _a.data,
          hoverState = _a.hoverState,
          maxHeight = _a.maxHeight;
      var hoverImgSrc = _this.state.hoverImgSrc;
      var obj = {};

      if (data.hover.open && data.hover.backgroundType === 'enlarge' && (hoverState || hoverImgSrc)) {
        // return { transform: `scale(${data.hover.magnification})` };
        obj.transform = "scale(" + data.hover.magnification + ")";
      }

      if (maxHeight) {
        obj.maxHeight = maxHeight;
      }

      return obj;
    };

    _this.mouseEnterImg = function () {
      var _a = _this.props,
          data = _a.data,
          isBackground = _a.isBackground;

      if (data.hover.open && !isBackground) {
        _this.setState({
          hoverImgSrc: true
        });
      }
    };

    _this.mouseLeaveImg = function () {
      var _a = _this.props,
          data = _a.data,
          isBackground = _a.isBackground;

      if (data.hover.open && !isBackground) {
        _this.setState({
          hoverImgSrc: false
        });
      }
    };

    return _this;
  }

  Image.prototype.render = function () {
    var _a, _b;

    var _c = this.props,
        data = _c.data,
        isBackground = _c.isBackground,
        hoverState = _c.hoverState;
    var hoverImgSrc = this.state.hoverImgSrc; // const { hoverSrc } = this.state;
    // console.log('--metaImage ', this.props);

    var srcImg = (0, _coreUtil.isPc)() ? (_a = data.content) === null || _a === void 0 ? void 0 : _a.pcImgSrc : (_b = data.content) === null || _b === void 0 ? void 0 : _b.h5ImgSrc;

    if (data.hover.open && data.hover.backgroundType === 'new' && (hoverState || hoverImgSrc)) {
      srcImg = (0, _coreUtil.isPc)() ? data.hover.pcImgHoverUrl : data.hover.h5ImgHoverUrl;
    }

    if (window.magicDesign.isShop && (srcImg === null || srcImg === void 0 ? void 0 : srcImg.includes('ecommerce/static'))) {
      srcImg = srcImg.replace('ecommerce/static', 'static');
    }

    return /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])('m-meta-image', {
        backgroundImg: isBackground
      }),
      onClick: function onClick() {
        (0, _coreUtil.clickUrl)(data.content.clickUrl);
      }
    }, srcImg && /*#__PURE__*/_react["default"].createElement("img", {
      onMouseEnter: this.mouseEnterImg,
      onMouseLeave: this.mouseLeaveImg,
      src: srcImg,
      style: this.getStyle()
    }));
  };

  Image.defaultProps = {
    data: {
      content: {},
      hover: {}
    },
    isBackground: false,
    hoverState: false
  };
  Image = __decorate([_decorator.metaDecorator], Image);
  return Image;
}(_react["default"].Component);

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