import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import * as React from 'react';
import { useState, useEffect } from 'react';
import styles from "./index.module.scss";
import { getShopById } from "../../../api/base";
// import LineCharts from '../../../reuseComponents/LineChart/index';

var shop2 = function shop2(shop2Props) {
  var _obj$;
  var shopProperty = shop2Props.shopProperty;
  // eslint-disable-next-line react-hooks/rules-of-hooks
  var _useState = useState([{
      shopStatusA: 1,
      companyName: '进取投资',
      shopImg: ['//img.maimairen.com/low-code/components/shops/shop1.jpg'],
      shopTitle: '商品标题',
      shopTag: ['标签'],
      shopDescribe: '促销描述',
      // shopTag: ['高原蓝莓'],
      shopSellPrice: 100,
      shopMarketPrice: 200,
      // 金融相关 1 是正数  2 是负数
      shopStockStatus: 2,
      // 金融 涨幅日期范围
      shopUpdate: '近一年涨幅',
      shopUnit: '份',
      shopLink: 'www.baidu.com'
    }, {
      shopStatusA: 1,
      companyName: '进取投资',
      shopImg: ['//img.maimairen.com/low-code/components/shops/shop1.jpg'],
      shopTitle: '商品标题',
      shopTag: ['标签'],
      shopDescribe: '促销描述',
      // shopTag: ['高原蓝莓'],
      shopSellPrice: 100,
      shopMarketPrice: 200,
      // 金融相关 1 是正数  2 是负数
      shopStockStatus: 2,
      // 金融 涨幅日期范围
      shopUpdate: '近一年涨幅',
      shopUnit: '份',
      shopLink: 'www.baidu.com'
    }]),
    obj = _useState[0],
    setObj = _useState[1];
  // eslint-disable-next-line react-hooks/rules-of-hooks
  useEffect(function () {
    getMoreMessage();
  }, [shopProperty, (_obj$ = obj[0]) === null || _obj$ === void 0 ? void 0 : _obj$.shopStatusA]);
  var getMoreMessage = /*#__PURE__*/function () {
    var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
      var _shopProperty$data;
      var idArray;
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            idArray = shopProperty === null || shopProperty === void 0 ? void 0 : (_shopProperty$data = shopProperty.data) === null || _shopProperty$data === void 0 ? void 0 : _shopProperty$data.shopIDarray;
            if (!(!idArray[0] && !idArray[1])) {
              _context.next = 3;
              break;
            }
            return _context.abrupt("return");
          case 3:
            obj.length = 0;
            _context.next = 6;
            return getDetailMessage(idArray[0]);
          case 6:
            _context.next = 8;
            return getDetailMessage(idArray[1]);
          case 8:
            _context.next = 10;
            return getDetailMessage(idArray[2]);
          case 10:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function getMoreMessage() {
      return _ref.apply(this, arguments);
    };
  }();
  var getDetailMessage = /*#__PURE__*/function () {
    var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(x) {
      var dataArray, objs, M;
      return _regeneratorRuntime.wrap(function _callee2$(_context2) {
        while (1) switch (_context2.prev = _context2.next) {
          case 0:
            dataArray = [];
            objs = {}; // const img = [] as any
            if (!x) {
              _context2.next = 10;
              break;
            }
            _context2.next = 5;
            return getShopById(x);
          case 5:
            dataArray = _context2.sent;
            M = dataArray.data; // M.xc.map(item => {
            //     img.push(item.c)
            //     return img
            // })
            objs = {
              shopStatusA: M.f,
              companyName: '进取投资',
              shopImg: M.xc[0].c,
              // shopImg: '//img.maimairen.com/low-code/components/shops/shop1.jpg',
              shopTitle: M.b,
              shopTag: M.xb.map(function (item) {
                return (item === null || item === void 0 ? void 0 : item.b).slice(0, 4);
              }),
              shopDescribe: M.xa[0].l,
              // shopTag: ['高原蓝莓'],
              shopSellPrice: M.xa[0].n,
              shopMarketPrice: M.xa[0].p,
              // 金融相关 1 是正数  2 是负数
              shopStockStatus: 2,
              // 金融 涨幅日期范围
              shopUpdate: M.xa[0].l,
              shopUnit: M.i,
              shopLink: returnUrl(JSON.parse(M.n1))
            };
            obj.push(objs);
            setObj([].concat(obj));
          case 10:
          case "end":
            return _context2.stop();
        }
      }, _callee2);
    }));
    return function getDetailMessage(_x) {
      return _ref2.apply(this, arguments);
    };
  }();
  var returnUrl = function returnUrl(x) {
    if (x[0].status === '1') {
      return x[0].url;
    } else if (x[0].status === '2') {
      return x[1].url;
    } else if (x[0].status === '3') {
      return x[2].url;
    }
  };
  var jumpUrl = function jumpUrl(x) {
    window.location.href = x;
  };
  return /*#__PURE__*/React.createElement("div", null, obj[0] && obj[0].shopStatusA === 1 ? /*#__PURE__*/React.createElement("div", {
    className: styles.shopContainer
  }, obj.slice(0, 2).map(function (item, index) {
    var _item$shopTag;
    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.shopImg
    }), /*#__PURE__*/React.createElement("div", {
      className: styles.tag
    }, item === null || item === void 0 ? void 0 : (_item$shopTag = item.shopTag) === null || _item$shopTag === void 0 ? void 0 : _item$shopTag.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.shopTitle), /*#__PURE__*/React.createElement("div", {
      className: styles.describe
    }, item === null || item === void 0 ? void 0 : item.shopDescribe), /*#__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.shopSellPrice), /*#__PURE__*/React.createElement("div", null, "/", item === null || item === void 0 ? void 0 : item.shopUnit)), /*#__PURE__*/React.createElement("div", {
      className: styles.shopMarketPrice
    }, /*#__PURE__*/React.createElement("s", null, "\uFFE5", item === null || item === void 0 ? void 0 : item.shopMarketPrice))), /*#__PURE__*/React.createElement("div", {
      className: styles.link,
      onClick: function onClick() {
        jumpUrl(item === null || item === void 0 ? void 0 : item.shopLink);
      }
    }, /*#__PURE__*/React.createElement("div", null, "\u62A2"))));
  })) : /*#__PURE__*/React.createElement("div", {
    className: styles.financialContainer
  }, obj.slice(0, 2).map(function (item, index) {
    var _item$shopTag2;
    return /*#__PURE__*/React.createElement("div", {
      key: index,
      className: styles.financial,
      onClick: function onClick() {
        jumpUrl(item === null || item === void 0 ? void 0 : item.shopLink);
      }
    }, /*#__PURE__*/React.createElement("div", {
      className: styles.tag
    }, item === null || item === void 0 ? void 0 : (_item$shopTag2 = item.shopTag) === null || _item$shopTag2 === void 0 ? void 0 : _item$shopTag2.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.shopTitle), /*#__PURE__*/React.createElement("div", {
      className: styles.bottom
    }, /*#__PURE__*/React.createElement("div", {
      className: styles.img
    }, /*#__PURE__*/React.createElement("img", {
      src: item === null || item === void 0 ? void 0 : item.shopImg
    })), /*#__PURE__*/React.createElement("div", {
      className: styles.price
    }, /*#__PURE__*/React.createElement("div", {
      className: styles.exchange
    }, /*#__PURE__*/React.createElement("div", {
      className: Number(item === null || item === void 0 ? void 0 : item.shopSellPrice) > 0 ? styles.red : styles.green
    }, Number(item === null || item === void 0 ? void 0 : item.shopSellPrice) > 0 ? /*#__PURE__*/React.createElement("div", {
      className: styles.text
    }, "+", item === null || item === void 0 ? void 0 : item.shopSellPrice, /*#__PURE__*/React.createElement("sup", null, "%")) : /*#__PURE__*/React.createElement("div", {
      className: styles.text
    }, "-", item === null || item === void 0 ? void 0 : item.shopSellPrice, /*#__PURE__*/React.createElement("sup", null, "%")))), /*#__PURE__*/React.createElement("div", {
      className: styles.shopDescribe
    }, item === null || item === void 0 ? void 0 : item.shopDescribe))));
  })));
};
export default shop2;