"use strict";

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

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

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

var _group = _interopRequireDefault(require("../../../../assets/imgs/group.svg"));

var _Carousel = _interopRequireDefault(require("../../../../common/Carousel"));

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

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

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

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

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

var _avatarList = _interopRequireDefault(require("../common/avatar-list"));

require("./index.less");

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

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 Group = /*#__PURE__*/function (_React$Component) {
  _inherits(Group, _React$Component);

  var _super = _createSuper(Group);

  function Group(props) {
    var _this;

    _classCallCheck(this, Group);

    _this = _super.call(this, props);

    _defineProperty(_assertThisInitialized(_this), "splitArray", function (data) {
      var arr = [];

      for (var i = 0; i < data.length; i += 3) {
        arr.push(data.slice(i, i + 3));
      }

      setTimeout(function () {
        window.dispatchEvent(new Event('resize'));
      });
      return arr;
    });

    _this.state = {};
    return _this;
  }

  _createClass(Group, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          _this$props$data = _this$props.data,
          backgroundImage = _this$props$data.backgroundImage,
          link = _this$props$data.link,
          list = _this$props$data.list,
          onClickBgItem = _this$props.onClickBgItem,
          onClickItem = _this$props.onClickItem;

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

      return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
        className: "new-group-box"
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: "new-group"
      }, /*#__PURE__*/_react["default"].createElement("div", {
        // style={backgroundImage ? { backgroundImage: `url(${backgroundImage})` } : {}}
        className: "new-click-area",
        onClick: function onClick() {
          onClickBgItem(link);
        }
      }, /*#__PURE__*/_react["default"].createElement("img", {
        src: backgroundImage,
        alt: ""
      })), /*#__PURE__*/_react["default"].createElement(_Carousel["default"], {
        autoplay: true,
        infinite: true,
        autoplayInterval: 3000,
        dots: this.splitArray(list).length > 1
      }, this.splitArray(list).map(function (item) {
        return /*#__PURE__*/_react["default"].createElement("div", null, item.map(function (v, i) {
          return /*#__PURE__*/_react["default"].createElement("div", {
            className: "new-group-item",
            key: "group-".concat(i),
            onClick: function onClick() {
              onClickItem(v.url); // location.href = v.url
            }
          }, /*#__PURE__*/_react["default"].createElement("div", {
            className: "group-left"
          }, /*#__PURE__*/_react["default"].createElement(_ImageLabel["default"], {
            small: true,
            labels: v.labels
          }), /*#__PURE__*/_react["default"].createElement(_NewImg["default"], {
            src: (0, _commonUtil.convertImageUrl)(v.productImg),
            lazy: true
          })), /*#__PURE__*/_react["default"].createElement("div", {
            className: "group-right"
          }, /*#__PURE__*/_react["default"].createElement("div", {
            className: "title"
          }, v.title), /*#__PURE__*/_react["default"].createElement(_NewPrice["default"], {
            price: v.price
          }), v.originalPrice && /*#__PURE__*/_react["default"].createElement("div", {
            className: "old-price",
            style: {
              display: 'inline-block'
            }
          }, /*#__PURE__*/_react["default"].createElement(_NewPrice["default"], {
            size: 10,
            color: "#7B7B7B",
            unit: "",
            through: true,
            price: v.originalPrice,
            style: {
              fontFamily: 'var(--regular-font)',
              fontWeight: 'unset'
            }
          })), /*#__PURE__*/_react["default"].createElement("div", {
            className: "btn-box"
          }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
            className: "number-box"
          }, /*#__PURE__*/_react["default"].createElement("img", {
            src: _group["default"],
            alt: ""
          }), /*#__PURE__*/_react["default"].createElement("span", null, v.total)), /*#__PURE__*/_react["default"].createElement("div", {
            className: "text"
          }, v.sold || 0, " ", _locale.Sold)), /*#__PURE__*/_react["default"].createElement(_avatarList["default"], {
            list: v.member,
            num: 3
          }))));
        }));
      })))));
    }
  }]);

  return Group;
}(_react["default"].Component);

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

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