"use strict";

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

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

var _react = require("react");

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 = ["data", "onItemClick", "showProName", "showRate", "showProgress"];

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); Object.defineProperty(Constructor, "prototype", { writable: false }); 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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); 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; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } 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 React = require('react');

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", {});

    return _this;
  }

  _createClass(AComponent, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          data = _this$props.data,
          onItemClick = _this$props.onItemClick,
          showProName = _this$props.showProName,
          showRate = _this$props.showRate,
          showProgress = _this$props.showProgress,
          rest = _objectWithoutProperties(_this$props, _excluded);

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

      var promotions = (0, _businessUtil.getPromotionList)(data, _locale);
      var price = (0, _currencyUtil.formatCurrency)(data.salesPrice);
      /** 当是拼团时 显示价格 */

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

      var oldPrice = data.marketPrice !== null ? (0, _currencyUtil.formatCurrency)(data.marketPrice) : null;
      var discount = data.discountPercent || 0;
      var salePercent = Number(data.salePercent) / 100 || 0;
      return /*#__PURE__*/React.createElement("div", _extends({
        className: "m-product-item-wrap",
        onClick: function onClick() {
          return onItemClick(data);
        }
      }, rest), /*#__PURE__*/React.createElement("div", {
        className: "img-wrap"
      }, /*#__PURE__*/React.createElement(_NewImg["default"], {
        className: "product-img",
        src: (0, _commonUtil.convertImageUrl)(data.imgUrlContent || data.productImageUrlContent),
        lazy: true
      }), /*#__PURE__*/React.createElement(_ImageLabel["default"], {
        small: true,
        labels: data.labels
      })), /*#__PURE__*/React.createElement("div", {
        className: "content-wrap"
      }, /*#__PURE__*/React.createElement("div", {
        className: "promotions-wrap"
      }, promotions.map(function (promot) {
        return /*#__PURE__*/React.createElement("span", {
          className: "promotion-item"
        }, promot);
      })), showProName && /*#__PURE__*/React.createElement("div", {
        className: "product-name"
      }, data.offerName, " "), /*#__PURE__*/React.createElement("div", {
        className: "price-wrap"
      }, /*#__PURE__*/React.createElement("div", {
        className: "price"
      }, /*#__PURE__*/React.createElement(_NewPrice["default"], {
        price: price,
        color: "#CE1126",
        bold: 600
      })), oldPrice && /*#__PURE__*/React.createElement("div", {
        className: "old-price"
      }, !!discount && /*#__PURE__*/React.createElement("span", {
        className: "discount"
      }, "-", discount, "%"), /*#__PURE__*/React.createElement(_NewPrice["default"], {
        price: oldPrice,
        size: 10,
        color: "#929292",
        bold: 500,
        through: true
      }))), showRate && data.evaluationAvg && data.evaluationCnt && /*#__PURE__*/React.createElement("div", {
        className: "rate-wrap"
      }, /*#__PURE__*/React.createElement(_RatingText["default"], {
        text: (0, _currencyUtil.numberToFixed)(data.evaluationAvg || 5, 1)
      }), /*#__PURE__*/React.createElement("span", {
        className: "number"
      }, "(", data.evaluationCnt || 0, ")")), showProgress && /*#__PURE__*/React.createElement("div", {
        className: "progress-wrap"
      }, /*#__PURE__*/React.createElement("span", {
        className: "text"
      }, salePercent, "% ", _locale.SOLD), /*#__PURE__*/React.createElement(_Progress["default"], {
        percent: salePercent
      }))));
    }
  }]);

  return AComponent;
}(_react.Component);

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

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

  /** onItemClick */
  onItemClick: _propTypes["default"].func,
  showRate: _propTypes["default"].bool,
  showProgress: _propTypes["default"].bool
};
AComponent.defaultProps = {
  data: {},
  onItemClick: function onItemClick() {},
  showProName: true,
  showRate: false,
  showProgress: true
};
var _default = AComponent;
exports["default"] = _default;