"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _base = require("../../../api/base");
var _indexModule = _interopRequireDefault(require("./index.module.scss"));
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; }
var defaultShop = {
  mainImg: '//img.maimairen.com/low-code/components/shops/shop1.jpg',
  title: '商品标题',
  tagsList: ['标签'],
  salesWord: '促销描述',
  sellingPrice: 100,
  marketPrice: 200,
  unit: '份'
};
var shop2 = function shop2(shop2Props) {
  var _shopProperty$data;
  var shopProperty = shop2Props.shopProperty,
    handerShopChange = shop2Props.handerShopChange,
    ideaId = shop2Props.ideaId;
  var obj = shopProperty !== null && shopProperty !== void 0 && (_shopProperty$data = shopProperty.data) !== null && _shopProperty$data !== void 0 && _shopProperty$data.length ? shopProperty.data.map(function (item) {
    return (0, _extends2["default"])({}, item, {
      num: 0,
      total: 0
    });
  }) : [].concat(Array(2)).map(function () {
    return (0, _extends2["default"])({}, defaultShop);
  });
  var changeShopNumber = /*#__PURE__*/function () {
    var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
      var productId, _ref3, code;
      return _regenerator["default"].wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            productId = _ref.productId;
            if (ideaId) {
              _context.next = 3;
              break;
            }
            return _context.abrupt("return");
          case 3:
            _context.next = 5;
            return (0, _base.updateShop)({
              ideaId: ideaId,
              productId: productId,
              action: 'add'
            });
          case 5:
            _ref3 = _context.sent;
            code = _ref3.code;
            if (code === 10200) handerShopChange && handerShopChange();
          case 8:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function changeShopNumber(_x) {
      return _ref2.apply(this, arguments);
    };
  }();
  return /*#__PURE__*/React.createElement("div", {
    className: _indexModule["default"].shopContainer
  }, obj.map(function (item, index) {
    var _item$tagsList;
    return /*#__PURE__*/React.createElement("div", {
      key: index,
      className: _indexModule["default"].singShop
    }, /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].top
    }, /*#__PURE__*/React.createElement("img", {
      src: item === null || item === void 0 ? void 0 : item.mainImg
    }), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].tag
    }, item === null || item === void 0 ? void 0 : (_item$tagsList = item.tagsList) === null || _item$tagsList === void 0 ? void 0 : _item$tagsList.map(function (items, indexs) {
      return /*#__PURE__*/React.createElement("div", {
        key: indexs,
        className: _indexModule["default"].tags
      }, items + "\xA0");
    }))), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].title
    }, item === null || item === void 0 ? void 0 : item.title, index), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].describe
    }, item === null || item === void 0 ? void 0 : item.salesWord), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].price
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].shopSellPrice
    }, /*#__PURE__*/React.createElement("div", null, "\uFFE5"), /*#__PURE__*/React.createElement("div", null, item === null || item === void 0 ? void 0 : item.sellingPrice), /*#__PURE__*/React.createElement("div", null, "/", item === null || item === void 0 ? void 0 : item.unit)), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].shopMarketPrice
    }, /*#__PURE__*/React.createElement("s", null, "\uFFE5", item === null || item === void 0 ? void 0 : item.marketPrice))), /*#__PURE__*/React.createElement("div", {
      className: _indexModule["default"].link,
      onClick: item !== null && item !== void 0 && item.productId ? function () {
        return changeShopNumber(item);
      } : function () {}
    }, /*#__PURE__*/React.createElement("div", null, "\u62A2"))));
  }));
};
var _default = shop2;
exports["default"] = _default;