import React, { useMemo } from 'react';
import classNames from 'classnames';
import { Tag, Tooltip } from 'antd';
import { QuestionCircleOutlined } from '@ant-design/icons';
import { _formatAmount } from "../Packages/utils";
import Divider from "../Divider";
import "./index.less";
import { locales } from '@pisell/utils';
var prefix = 'pisell-lowcode-';
var Footer = function Footer(_ref) {
  var item = _ref.item,
    hideDivider = _ref.hideDivider,
    type = _ref.type,
    isOnlyTotal = _ref.isOnlyTotal;
  var total = item.total,
    origin_total = item.origin_total,
    symbol = item.symbol,
    tip = item.tip,
    num = item.num,
    discount_reason = item.discount_reason,
    _item$totalDifference = item.totalDifference,
    totalDifference = _item$totalDifference === void 0 ? 0 : _item$totalDifference;
  /**
   * @title: 折扣
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: WangHan
   * @Date: 2024-11-22 13:50
   */
  var isDiscount = useMemo(function () {
    // item中没有该属性则不展示
    if (!origin_total) return false;
    return Number(total) != Number(origin_total);
  }, [total, origin_total]);
  var renderDiscountReason = function renderDiscountReason() {
    if (isDiscount && discount_reason && type === 'total') {
      if (Array.isArray(discount_reason)) {
        return /*#__PURE__*/React.createElement("div", {
          className: "".concat(prefix, "product-item-discount-reason")
        }, discount_reason.map(function (reason, index) {
          return /*#__PURE__*/React.createElement(Tag, {
            key: index,
            color: "red"
          }, reason);
        }));
      }
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, null), /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefix, "product-item-discount-reason")
      }, /*#__PURE__*/React.createElement("span", null, "".concat(locales.getText('pisell2.product.card.discount.reason'), ": ").concat(discount_reason))));
    }
    return null;
  };
  return /*#__PURE__*/React.createElement(React.Fragment, null, !hideDivider ? /*#__PURE__*/React.createElement(Divider, {
    type: type !== 'total' ? 'inside' : ''
  }) : null, /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(prefix, "packages-product-footer"), hideDivider && "".concat(prefix, "packages-product-hide-divider-footer"), isOnlyTotal && "".concat(prefix, "packages-product-only-total-footer"))
  }, /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(prefix, "packages-product-footer-price-wrap"))
  }, !isOnlyTotal ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
    className: classNames("".concat(prefix, "packages-product-footer-price"))
  }, /*#__PURE__*/React.createElement("span", null, _formatAmount(total, symbol)), tip ? /*#__PURE__*/React.createElement(Tooltip, {
    title: locales.getText(tip),
    destroyTooltipOnHide: true
  }, /*#__PURE__*/React.createElement(QuestionCircleOutlined, {
    style: {
      fontSize: '16px',
      color: '#1570ef'
    }
  })) : null), /*#__PURE__*/React.createElement("span", null, "\xD7".concat(num))) : null, /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "packages-product-footer-total")
  }, isDiscount ? /*#__PURE__*/React.createElement("span", {
    className: "".concat(prefix, "packages-product-footer-origin-total")
  }, _formatAmount(origin_total * num, symbol, 2)) : null, /*#__PURE__*/React.createElement("span", null, _formatAmount(total * num - (totalDifference !== null && totalDifference !== void 0 ? totalDifference : 0), symbol))))), renderDiscountReason());
};
export default Footer;