import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _extends from "@babel/runtime/helpers/extends";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import * as React from 'react';
import { updateShop } from "../../../api/base";
import styles from "./index.module.scss";
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 _extends({}, item, {
      num: 0,
      total: 0
    });
  }) : [].concat(Array(2)).map(function () {
    return _extends({}, defaultShop);
  });
  var changeShopNumber = /*#__PURE__*/function () {
    var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
      var productId, _ref3, code;
      return _regeneratorRuntime.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 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: styles.shopContainer
  }, obj.map(function (item, index) {
    var _item$tagsList;
    return /*#__PURE__*/React.createElement("div", {
      key: index,
      className: styles.singShop
    }, /*#__PURE__*/React.createElement("div", {
      className: styles.top
    }, /*#__PURE__*/React.createElement("img", {
      src: item === null || item === void 0 ? void 0 : item.mainImg
    }), /*#__PURE__*/React.createElement("div", {
      className: styles.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: styles.tags
      }, items + "\xA0");
    }))), /*#__PURE__*/React.createElement("div", {
      className: styles.title
    }, item === null || item === void 0 ? void 0 : item.title, index), /*#__PURE__*/React.createElement("div", {
      className: styles.describe
    }, item === null || item === void 0 ? void 0 : item.salesWord), /*#__PURE__*/React.createElement("div", {
      className: styles.price
    }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
      className: styles.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: styles.shopMarketPrice
    }, /*#__PURE__*/React.createElement("s", null, "\uFFE5", item === null || item === void 0 ? void 0 : item.marketPrice))), /*#__PURE__*/React.createElement("div", {
      className: styles.link,
      onClick: item !== null && item !== void 0 && item.productId ? function () {
        return changeShopNumber(item);
      } : function () {}
    }, /*#__PURE__*/React.createElement("div", null, "\u62A2"))));
  }));
};
export default shop2;