"use strict";

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

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

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

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

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

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

var _components = require("../../../../meta-comp/components");

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

require("./index.less");

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

function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }

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 __assign = void 0 && (void 0).__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

var __rest = void 0 && (void 0).__rest || function (s, e) {
  var t = {};

  for (var p in s) {
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  }

  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
    if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  }
  return t;
};

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

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

    _this.state = {};
    return _this;
  }

  ProductItem.prototype.render = function () {
    var _a = this.props,
        data = _a.data,
        panelProps = _a.panelProps,
        onItemClick = _a.onItemClick,
        showProName = _a.showProName,
        showProgress = _a.showProgress,
        rest = __rest(_a, ["data", "panelProps", "onItemClick", "showProName", "showProgress"]);

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

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

    var oldPrice = data.marketPrice !== null ? (0, _currencyUtil.formatCurrencyWithSymbol)(data.marketPrice) : null;
    var discount = data.discountPercent || 0;
    var salePercent = Number(data.salePercent) / 100 || 0;
    return /*#__PURE__*/_react["default"].createElement("div", _extends({
      className: "m-product-item-wrap",
      onClick: function onClick() {
        return onItemClick();
      }
    }, rest), /*#__PURE__*/_react["default"].createElement("div", {
      className: "img-wrap"
    }, /*#__PURE__*/_react["default"].createElement(_NewImg["default"], {
      className: "product-img",
      lazy: true,
      src: (0, _commonUtil.convertImageUrl)(data.imgUrlContent || data.productImageUrlContent)
    }), /*#__PURE__*/_react["default"].createElement(_ImageLabel["default"], {
      labels: data.labels,
      small: true
    })), /*#__PURE__*/_react["default"].createElement("div", {
      className: "content-wrap"
    }, panelProps.label.open && /*#__PURE__*/_react["default"].createElement("div", {
      className: "promotions-wrap"
    }, promotions.map(function (promot, index) {
      return /*#__PURE__*/_react["default"].createElement(_components.MetaButton, {
        key: index,
        className: "promotion-item",
        data: __assign(__assign({}, panelProps.label), {
          text: promot
        }),
        readonly: true
      });
    })), showProName && panelProps.productName.open && /*#__PURE__*/_react["default"].createElement(_components.MetaText, {
      className: "product-name",
      data: __assign(__assign({}, panelProps.productName), {
        text: data.offerName
      }),
      readonly: true
    }), panelProps.activityPrice.open && /*#__PURE__*/_react["default"].createElement(_components.MetaText, {
      className: "price",
      data: __assign(__assign({}, panelProps.activityPrice), {
        text: price
      }),
      readonly: true
    }), oldPrice && panelProps.salesPrice.open && /*#__PURE__*/_react["default"].createElement("div", {
      className: "old-price-wrap"
    }, !!discount && /*#__PURE__*/_react["default"].createElement("span", {
      className: "discount"
    }, "-", discount, "%"), /*#__PURE__*/_react["default"].createElement(_components.MetaText, {
      className: "old-price",
      data: __assign(__assign({}, panelProps.salesPrice), {
        text: oldPrice
      }),
      readonly: true,
      style: {
        color: panelProps.salesPrice.content.color
      }
    })), showProgress && panelProps.salesProgressVisible.open && /*#__PURE__*/_react["default"].createElement("div", {
      className: "progress-wrap"
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "text"
    }, salePercent, "% Sold"), /*#__PURE__*/_react["default"].createElement("div", {
      className: "progress-container"
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "progress",
      style: {
        width: salePercent + "%"
      }
    })))));
  };

  ProductItem.defaultProps = {
    data: {},
    panelProps: {},
    showProName: true,
    showProgress: true
  };
  return ProductItem;
}(_react["default"].Component);

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