"use strict";

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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

var _out_of_stock = _interopRequireDefault(require("../../../../../assets/imgs/out_of_stock.png"));

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

var _commonUtil = require("../../../../../utils/commonUtil");

var _currencyUtil = require("../../../../../utils/currencyUtil");

var _getLocale = require("../../../../../utils/getLocale");

var _ImageLabel = _interopRequireDefault(require("../ImageLabel"));

var _NewImg = _interopRequireDefault(require("../NewImg"));

var _NewPrice = _interopRequireDefault(require("../NewPrice"));

var _Progress = _interopRequireDefault(require("../Progress"));

var _RatingText = _interopRequireDefault(require("../RatingText"));

require("./index.less");

var _excluded = ["showOutOfStock", "showStar", "hideRate", "hidePromotions", "orderPriceFixedHeight", "hideProName", "ProNameFixedHeight", "type", "data", "onItemClick", "unknownPrice"];

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

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

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

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, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var AComponent = /*#__PURE__*/function (_Component) {
  _inherits(AComponent, _Component);

  var _super = _createSuper(AComponent);

  function AComponent() {
    var _this;

    _classCallCheck(this, AComponent);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));

    _defineProperty(_assertThisInitialized(_this), "state", {});

    _defineProperty(_assertThisInitialized(_this), "isEmpty", function (val) {
      return val === null || undefined === val || val === '' || val === false;
    });

    return _this;
  }

  _createClass(AComponent, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          showOutOfStock = _this$props.showOutOfStock,
          showStar = _this$props.showStar,
          hideRate = _this$props.hideRate,
          hidePromotions = _this$props.hidePromotions,
          orderPriceFixedHeight = _this$props.orderPriceFixedHeight,
          hideProName = _this$props.hideProName,
          ProNameFixedHeight = _this$props.ProNameFixedHeight,
          type = _this$props.type,
          data = _this$props.data,
          onItemClick = _this$props.onItemClick,
          unknownPrice = _this$props.unknownPrice,
          rest = _objectWithoutProperties(_this$props, _excluded);

      var _locale = (0, _getLocale.getComponentLocale)(this.props, this.context, 'ProductItem', function () {
        return require('./locale/en_US');
      });

      var TERJUAL = _locale.TERJUAL;
      var promotionsTemp = (0, _businessUtil.getPromotionList)(data, _locale); // 标题只展示两条

      var promotions = promotionsTemp.slice(0, 2);
      var price = (0, _currencyUtil.formatCurrency)(data.salesPrice);
      var oldPrice = data.marketPrice !== null ? (0, _currencyUtil.formatCurrency)(data.marketPrice) : null;
      var discount = data.discountPercent || 0;
      /** 当是拼团时 显示价格 */

      if (data.sppType && promotions.length) {
        price = data.specialPrice !== null ? (0, _currencyUtil.formatCurrency)(data.specialPrice) : (0, _currencyUtil.formatCurrency)(data.salesPrice);
      }

      return /*#__PURE__*/_react["default"].createElement("div", _extends({
        className: "pro-container",
        onClick: function onClick() {
          onItemClick && onItemClick(data);
        }
      }, rest), /*#__PURE__*/_react["default"].createElement("div", {
        className: "img-wrap"
      }, showOutOfStock && data.salePercent === 100 && /*#__PURE__*/_react["default"].createElement("div", {
        className: "out-of-stock-img"
      }, /*#__PURE__*/_react["default"].createElement("img", {
        src: _out_of_stock["default"],
        alt: ""
      })), /*#__PURE__*/_react["default"].createElement(_NewImg["default"], {
        className: "product-img",
        src: (0, _commonUtil.convertImageUrl)(data.imgUrlContent || data.productImageUrlContent),
        lazy: true
      }), /*#__PURE__*/_react["default"].createElement(_ImageLabel["default"], {
        small: true,
        labels: data.labels
      })), /*#__PURE__*/_react["default"].createElement("div", {
        className: "product-content-wrap"
      }, !hidePromotions && promotions.length > 0 && /*#__PURE__*/_react["default"].createElement("div", {
        className: "label-wrap"
      }, promotions.map(function (promot) {
        return /*#__PURE__*/_react["default"].createElement("span", {
          className: "label-container"
        }, promot);
      })), !hideProName && /*#__PURE__*/_react["default"].createElement("div", {
        className: (0, _classnames["default"])('product-name', {
          'product-name-height': ProNameFixedHeight
        })
      }, data.offerName), /*#__PURE__*/_react["default"].createElement("div", {
        className: "price-wrap"
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: "price"
      }, /*#__PURE__*/_react["default"].createElement(_NewPrice["default"], {
        price: price,
        unknownPrice: unknownPrice
      })), (orderPriceFixedHeight || oldPrice) && /*#__PURE__*/_react["default"].createElement("div", {
        className: (0, _classnames["default"])('old-price', {
          'old-price-hieght': orderPriceFixedHeight
        }),
        style: {
          visibility: oldPrice ? 'visible' : 'hidden'
        }
      }, !!discount && /*#__PURE__*/_react["default"].createElement("span", {
        className: "discount label-container",
        style: {
          transform: 'translateY(-1px)'
        }
      }, -discount || 0, "%"), /*#__PURE__*/_react["default"].createElement(_NewPrice["default"], {
        unit: "",
        size: 10,
        color: "#7B7B7B",
        style: {
          fontFamily: 'var(--regular-font)',
          alignItems: 'center',
          fontWeight: 'unset',
          lineHeight: '12px',
          marginTop: '-3px'
        },
        through: true,
        price: oldPrice
      }))), !hideRate && (showStar ? data.evaluationCnt ? /*#__PURE__*/_react["default"].createElement("div", {
        className: "rate-wrap"
      }, /*#__PURE__*/_react["default"].createElement(_RatingText["default"], {
        text: (0, _currencyUtil.numberToFixed)(data.evaluationAvg, 1)
      }), /*#__PURE__*/_react["default"].createElement("span", {
        className: "rate-number"
      }, "(", data.evaluationCnt, ")")) : /*#__PURE__*/_react["default"].createElement("div", {
        className: "rate-wrap"
      }, /*#__PURE__*/_react["default"].createElement(_RatingText["default"], {
        text: (0, _currencyUtil.numberToFixed)(5, 1)
      }), /*#__PURE__*/_react["default"].createElement("span", {
        className: "rate-number"
      }, "(", 0, ")")) : data.evaluationCnt ? /*#__PURE__*/_react["default"].createElement("div", {
        className: "rate-wrap"
      }, /*#__PURE__*/_react["default"].createElement(_RatingText["default"], {
        text: (0, _currencyUtil.numberToFixed)(data.evaluationAvg, 1)
      }), /*#__PURE__*/_react["default"].createElement("span", {
        className: "rate-number"
      }, "(", data.evaluationCnt, ")")) : /*#__PURE__*/_react["default"].createElement("div", {
        className: "space"
      })), !this.isEmpty(data.salePercent) ? /*#__PURE__*/_react["default"].createElement("div", {
        className: "progress-box",
        style: {
          display: 'flex'
        }
      }, /*#__PURE__*/_react["default"].createElement("span", {
        className: "progress-txt"
      }, data.salePercent, "% ", TERJUAL), /*#__PURE__*/_react["default"].createElement(_Progress["default"], {
        percent: data.salePercent,
        position: "normal",
        className: "progress"
      })) : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null)));
    }
  }]);

  return AComponent;
}(_react.Component);

_defineProperty(AComponent, "contextTypes", {
  antLocale: _propTypes["default"].object
});

AComponent.propTypes = {
  /** type */
  type: _propTypes["default"].string,

  /** data */
  data: _propTypes["default"].string,

  /** onItemClick */
  onItemClick: _propTypes["default"].func
};
AComponent.defaultProps = {
  type: '',
  data: {},
  onItemClick: function onItemClick() {}
};
var _default = AComponent;
exports["default"] = _default;