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

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

/* eslint-disable no-nested-ternary */
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import outOfStockImg from '../../../../../assets/imgs/out_of_stock.png';
import { getPromotionList } from '../../../../../utils/businessUtil';
import { convertImageUrl } from '../../../../../utils/commonUtil';
import { formatCurrency, numberToFixed } from '../../../../../utils/currencyUtil';
import { getComponentLocale } from '../../../../../utils/getLocale';
import ImageLabel from '../ImageLabel';
import NewImg from '../NewImg';
import NewPrice from '../NewPrice';
import Progress from '../Progress';
import RatingText from '../RatingText';
import './index.less';

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 = getComponentLocale(this.props, this.context, 'ProductItem', function () {
        return require('./locale/en_US');
      });

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

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

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

      return /*#__PURE__*/React.createElement("div", _extends({
        className: "pro-container",
        onClick: function onClick() {
          onItemClick && onItemClick(data);
        }
      }, rest), /*#__PURE__*/React.createElement("div", {
        className: "img-wrap"
      }, showOutOfStock && data.salePercent === 100 && /*#__PURE__*/React.createElement("div", {
        className: "out-of-stock-img"
      }, /*#__PURE__*/React.createElement("img", {
        src: outOfStockImg,
        alt: ""
      })), /*#__PURE__*/React.createElement(NewImg, {
        className: "product-img",
        src: convertImageUrl(data.productImg || data.productImageUrlContent || data.imgUrlContent),
        lazy: true
      }), /*#__PURE__*/React.createElement(ImageLabel, {
        small: true,
        labels: data.labels
      })), /*#__PURE__*/React.createElement("div", {
        className: "product-content-wrap"
      }, !hidePromotions && promotions.length > 0 && /*#__PURE__*/React.createElement("div", {
        className: "label-wrap"
      }, promotions.map(function (promot) {
        return /*#__PURE__*/React.createElement("span", {
          className: "label-container"
        }, promot);
      })), !hideProName && /*#__PURE__*/React.createElement("div", {
        className: classNames('product-name', {
          'product-name-height': ProNameFixedHeight
        })
      }, data.offerName), /*#__PURE__*/React.createElement("div", {
        className: "price-wrap"
      }, /*#__PURE__*/React.createElement("div", {
        className: "price"
      }, /*#__PURE__*/React.createElement(NewPrice, {
        price: price,
        unknownPrice: unknownPrice
      })), (orderPriceFixedHeight || oldPrice) && /*#__PURE__*/React.createElement("div", {
        className: classNames('old-price', {
          'old-price-hieght': orderPriceFixedHeight
        }),
        style: {
          visibility: oldPrice ? 'visible' : 'hidden'
        }
      }, !!discount && /*#__PURE__*/React.createElement("span", {
        className: "discount label-container",
        style: {
          transform: 'translateY(-1px)'
        }
      }, -discount || 0, "%"), /*#__PURE__*/React.createElement(NewPrice, {
        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.createElement("div", {
        className: "rate-wrap"
      }, /*#__PURE__*/React.createElement(RatingText, {
        text: numberToFixed(data.evaluationAvg, 1)
      }), /*#__PURE__*/React.createElement("span", {
        className: "rate-number"
      }, "(", data.evaluationCnt, ")")) : /*#__PURE__*/React.createElement("div", {
        className: "rate-wrap"
      }, /*#__PURE__*/React.createElement(RatingText, {
        text: numberToFixed(5, 1)
      }), /*#__PURE__*/React.createElement("span", {
        className: "rate-number"
      }, "(", 0, ")")) : data.evaluationCnt ? /*#__PURE__*/React.createElement("div", {
        className: "rate-wrap"
      }, /*#__PURE__*/React.createElement(RatingText, {
        text: numberToFixed(data.evaluationAvg, 1)
      }), /*#__PURE__*/React.createElement("span", {
        className: "rate-number"
      }, "(", data.evaluationCnt, ")")) : /*#__PURE__*/React.createElement("div", {
        className: "space"
      })), !this.isEmpty(data.salePercent) ? /*#__PURE__*/React.createElement("div", {
        className: "progress-box",
        style: {
          display: 'flex'
        }
      }, /*#__PURE__*/React.createElement("span", {
        className: "progress-txt"
      }, data.salePercent, "% ", TERJUAL), /*#__PURE__*/React.createElement(Progress, {
        percent: data.salePercent,
        position: "normal",
        className: "progress"
      })) : /*#__PURE__*/React.createElement(React.Fragment, null)));
    }
  }]);

  return AComponent;
}(Component);

_defineProperty(AComponent, "contextTypes", {
  antLocale: PropTypes.object
});

AComponent.propTypes = {
  /** type */
  type: PropTypes.string,

  /** data */
  data: PropTypes.string,

  /** onItemClick */
  onItemClick: PropTypes.func
};
AComponent.defaultProps = {
  type: '',
  data: {},
  onItemClick: function onItemClick() {}
};
export default AComponent;