import React, { useMemo } from 'react';
import { image, locales } from '@pisell/utils';
import classNames from 'classnames';
import { getDiscountTime } from "../../../utils";
import Decimal from 'decimal.js';
import PisellPriceText from "../../../../productSelect/components/pisellPriceText";
import "./index.less";
var ProductItem = function ProductItem(_ref) {
  var item = _ref.item,
    _onClick = _ref.onClick,
    amountSymbol = _ref.amountSymbol,
    style = _ref.style,
    className = _ref.className;
  var price = item.price,
    is_bundle = item.is_bundle,
    minimum_markup_price = item.minimum_markup_price;
  var _price = price;
  if (is_bundle) {
    _price = new Decimal(price).plus(new Decimal(minimum_markup_price)).toFixed(2);
  }
  var stockText = useMemo(function () {
    if (item.is_track === 0) {
      return false;
    }
    return "".concat(item.stock_quantity, " ").concat(locales.getText('pisell2.text.stock'));
  }, [item.stock_quantity, item.is_track]);
  return /*#__PURE__*/React.createElement("div", {
    style: style,
    className: classNames('server-product', className),
    onClick: function onClick() {
      _onClick(item, 'select');
    }
  }, item.cover ? /*#__PURE__*/React.createElement("img", {
    src: image.ali(item.cover, 100),
    className: "server-product-cover",
    loading: "lazy"
    // onClick={(e) => {
    // 	e.preventDefault();
    // 	e.stopPropagation();
    // 	onClick(item, "detail");
    // }}
  }) : null, /*#__PURE__*/React.createElement("div", {
    className: "server-product-content"
  }, /*#__PURE__*/React.createElement("span", {
    className: "server-product-title"
    // onClick={(e) => {
    // 	e.preventDefault();
    // 	e.stopPropagation();
    // 	onClick(item, "detail");
    // }}
  }, item.title), /*#__PURE__*/React.createElement("div", {
    className: "server-product-time"
  }, getDiscountTime(item.service_times)), stockText && /*#__PURE__*/React.createElement("div", {
    className: "server-product-time"
  }, stockText), /*#__PURE__*/React.createElement("div", {
    className: "server-product-price"
  }, /*#__PURE__*/React.createElement(PisellPriceText, {
    value: _price,
    isMini: is_bundle
  }))));
};
export default ProductItem;