import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _extends from "@babel/runtime/helpers/extends";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import 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 bigPicture = function bigPicture(bigPictureProps) {
  var _shopProperty$data;
  var shopProperty = bigPictureProps.shopProperty,
    handerShopChange = bigPictureProps.handerShopChange,
    ideaId = bigPictureProps.ideaId;
  var obj = shopProperty !== null && shopProperty !== void 0 && (_shopProperty$data = shopProperty.data) !== null && _shopProperty$data !== void 0 && _shopProperty$data.length ? shopProperty.data : [].concat(Array(1)).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 === null || styles === void 0 ? void 0 : styles.shop
  }, obj.map(function (item, index) {
    return /*#__PURE__*/React.createElement("div", {
      key: index,
      className: styles.shopContent
    }, /*#__PURE__*/React.createElement("img", {
      src: item.mainImg
    }), /*#__PURE__*/React.createElement("div", {
      className: styles.shopTitle
    }, item.title), /*#__PURE__*/React.createElement("div", {
      className: styles.shopTag
    }, item.salesWord), /*#__PURE__*/React.createElement("div", {
      className: styles.shopBottom
    }, /*#__PURE__*/React.createElement("div", {
      className: styles.price
    }, /*#__PURE__*/React.createElement("span", null, "\uFFE5"), /*#__PURE__*/React.createElement("span", null, item.sellingPrice), /*#__PURE__*/React.createElement("div", null, "/", item.unit), /*#__PURE__*/React.createElement("s", null, "\uFFE5", item.marketPrice)), /*#__PURE__*/React.createElement("div", {
      className: styles.link
    }, /*#__PURE__*/React.createElement("div", {
      onClick: item !== null && item !== void 0 && item.productId ? function () {
        return changeShopNumber(item);
      } : function () {}
    }, "\u62A2"))));
  }));
};
export default bigPicture;