import React, { useMemo } from 'react';
import { Divider, Tag } from 'antd';
import { locales } from '@pisell/utils';
import { PREFIX } from "../../index";
var DiscountReason = function DiscountReason(props) {
  var _props$dataSource = props.dataSource,
    dataSource = _props$dataSource === void 0 ? {} : _props$dataSource,
    hideDivider = props.hideDivider;
  var total = dataSource.total,
    origin_total = dataSource.origin_total,
    symbol = dataSource.symbol,
    tip = dataSource.tip,
    num = dataSource.num,
    discount_reason = dataSource.discount_reason;
  var isDiscount = useMemo(function () {
    // item中没有该属性则不展示
    if (!origin_total) return false;
    return Number(total) != Number(origin_total);
  }, [total, origin_total]);
  var renderDivider = function renderDivider() {
    return isDiscount && discount_reason && !hideDivider ? /*#__PURE__*/React.createElement(Divider, {
      style: {
        margin: 0
      }
    }) : null;
  };
  var renderDiscountReason = function renderDiscountReason() {
    if (isDiscount && discount_reason) {
      if (Array.isArray(discount_reason)) {
        return /*#__PURE__*/React.createElement("div", {
          className: "".concat(PREFIX, "_discount-reason"),
          style: {
            display: 'flex',
            flexWrap: 'wrap',
            gap: '4px'
          }
        }, discount_reason.map(function (reason, index) {
          return /*#__PURE__*/React.createElement(Tag, {
            key: index,
            color: "red"
          }, reason);
        }));
      }
      return /*#__PURE__*/React.createElement("div", {
        className: "".concat(PREFIX, "_discount-reason")
      }, /*#__PURE__*/React.createElement("span", null, "".concat(locales.getText('pisell2.product.card.discount.reason'), ": ").concat(discount_reason)));
    }
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, renderDivider(), renderDiscountReason());
};
export default DiscountReason;