import React from 'react';
import classNames from 'classnames';
import { image as imageAli, formatAmount } from '@pisell/utils';
import Specs from "../specs";
import Holders from "../holders";
import { PREFIX } from "../../index";
import "./index.less";
var BasicInfo = function BasicInfo(props) {
  var isShowImage = props.isShowImage,
    _props$dataSource = props.dataSource,
    dataSource = _props$dataSource === void 0 ? {} : _props$dataSource,
    style = props.style,
    isMainProduct = props.isMainProduct,
    type = props.type;
  var image = dataSource.image,
    bundle = dataSource.bundle,
    options = dataSource.options,
    product_option_string = dataSource.product_option_string,
    name = dataSource.name,
    price = dataSource.price,
    symbol = dataSource.symbol,
    _dataSource$total = dataSource.total,
    total = _dataSource$total === void 0 ? 0 : _dataSource$total,
    _dataSource$origin_to = dataSource.origin_total,
    origin_total = _dataSource$origin_to === void 0 ? 0 : _dataSource$origin_to,
    _dataSource$num = dataSource.num,
    num = _dataSource$num === void 0 ? 1 : _dataSource$num,
    holder_id = dataSource.holder_id;
  var renderNumTag = function renderNumTag() {
    return /*#__PURE__*/React.createElement("div", {
      className: classNames("num-tag", {
        'is-main': isMainProduct
      })
    }, num < 100 ? num : '99+');
  };
  var hasSpecs = (bundle === null || bundle === void 0 ? void 0 : bundle.length) || (options === null || options === void 0 ? void 0 : options.length) || product_option_string;
  var renderImage = function renderImage() {
    if (!isShowImage) return null;
    if (image) {
      return /*#__PURE__*/React.createElement("img", {
        src: imageAli.ali(image, 64),
        className: "product-cover"
      });
    }

    // 如果没有图片，显示文字图片
    var displayText = name ? name.slice(0, 2) : '';
    return /*#__PURE__*/React.createElement("div", {
      className: "product-cover-text"
    }, displayText);
  };
  if (type === 'a5') {
    return /*#__PURE__*/React.createElement("div", {
      className: "".concat(PREFIX, "__basic-info"),
      style: style || {}
    }, renderNumTag(), renderImage(), !isShowImage || !image && !name ? /*#__PURE__*/React.createElement("div", {
      style: {
        width: 20
      }
    }) : null, /*#__PURE__*/React.createElement("div", {
      className: "product-info"
    }, /*#__PURE__*/React.createElement("div", {
      className: "product-name"
    }, name), !holder_id || !(holder_id !== null && holder_id !== void 0 && holder_id.length) ? /*#__PURE__*/React.createElement("div", {
      className: "product-price"
    }, formatAmount(price, 2, symbol)) : /*#__PURE__*/React.createElement(Holders, {
      dataSource: dataSource
    })));
  }
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__basic-info"),
    style: style || {}
  }, renderNumTag(), renderImage(), !isShowImage || !image && !name ? /*#__PURE__*/React.createElement("div", {
    style: {
      width: 20
    }
  }) : null, /*#__PURE__*/React.createElement("div", {
    className: "product-info"
  }, /*#__PURE__*/React.createElement("div", {
    className: "product-name"
  }, name), hasSpecs ? /*#__PURE__*/React.createElement(Specs, {
    dataSource: dataSource
  }) : /*#__PURE__*/React.createElement("div", {
    className: "product-price"
  }, formatAmount(price, 2, symbol))), /*#__PURE__*/React.createElement("div", {
    className: "product-amount"
  }, /*#__PURE__*/React.createElement("div", {
    className: "total-amont"
  }, formatAmount(total * num, 2, symbol)), origin_total && Number(total) !== Number(origin_total) ? /*#__PURE__*/React.createElement("div", {
    className: "origin-amount"
  }, formatAmount(origin_total * num, 2, symbol)) : null));
};
export default BasicInfo;