import React, { useMemo } from 'react';
import { locales } from '@pisell/utils';
import PisellPriceText from "../../../../components/pisellPriceText";
import { PREFIX, productCardDefault } from "../../status";
import "./index.less";
var Price = function Price(_ref) {
  var _productCardDefault$s;
  var props = _ref.props;
  var dataSource = props.dataSource,
    skuTextConfig = props.skuTextConfig;
  var _ref2 = (skuTextConfig === null || skuTextConfig === void 0 ? void 0 : skuTextConfig.skuPriceConfig) || (productCardDefault === null || productCardDefault === void 0 || (_productCardDefault$s = productCardDefault.skuTextConfig) === null || _productCardDefault$s === void 0 ? void 0 : _productCardDefault$s.skuPriceConfig) || {},
    isOpen = _ref2.isOpen,
    isOriginPrice = _ref2.isOriginPrice,
    isPrice = _ref2.isPrice,
    isTaxPrice = _ref2.isTaxPrice,
    originPriceFontSize = _ref2.originPriceFontSize,
    originPriceFontWeight = _ref2.originPriceFontWeight,
    originPriceColor = _ref2.originPriceColor,
    priceFontSize = _ref2.priceFontSize,
    priceFontWeight = _ref2.priceFontWeight,
    priceColor = _ref2.priceColor,
    isCustomText = _ref2.isCustomText,
    customTextType = _ref2.customTextType,
    customTextValue = _ref2.customTextValue,
    customTextMinValue = _ref2.customTextMinValue,
    customTextMaxValue = _ref2.customTextMaxValue,
    isShowZeroPrice = _ref2.isShowZeroPrice,
    isShowFreePrice = _ref2.isShowFreePrice,
    isMiniPrice = _ref2.isMiniPrice;

  // 不开启
  if (!isOpen) return null;

  // 自定义文本
  // if (customText) return customText;

  var isShowPrice = useMemo(function () {
    if (!isPrice) return false;

    // 0元不显示
    if (Number(dataSource === null || dataSource === void 0 ? void 0 : dataSource.price) === 0 && !isShowZeroPrice) return false;
    return true;
  }, [isPrice, isShowZeroPrice, dataSource === null || dataSource === void 0 ? void 0 : dataSource.price]);

  /**
   * @title: 价格文本
   * @description:
   * @param {*} useMemo
   * @return {*}
   * @Author: WangHan
   * @Date: 2025-09-18 16:23
   */
  var priceText = useMemo(function () {
    if (!isShowPrice) return null;

    // 免费
    if (Number(dataSource === null || dataSource === void 0 ? void 0 : dataSource.price) === 0 && isShowFreePrice) {
      return locales.getText('pisell2.sku-card.free');
    }

    // 自定义文本
    if (isCustomText) {
      // 从起点
      if (customTextType === 'from') {
        return /*#__PURE__*/React.createElement(PisellPriceText, {
          value: customTextValue || 0,
          isMini: true
        });
      }

      // 终点
      if (customTextType === 'end') {
        return /*#__PURE__*/React.createElement(PisellPriceText, {
          value: customTextValue || 0,
          isMini: true,
          customPrefixText: locales.getText('pisell2.sku-card.max'),
          customSuffixText: locales.getText('pisell2.sku-card.max')
        });
      }

      // 区间
      if (customTextType === 'range') {
        return /*#__PURE__*/React.createElement("div", {
          className: "".concat(PREFIX, "__card-price-range")
        }, /*#__PURE__*/React.createElement(PisellPriceText, {
          value: customTextMinValue || 0
        }), "~", /*#__PURE__*/React.createElement(PisellPriceText, {
          value: customTextMaxValue || 0
        }));
      }
    }
    return /*#__PURE__*/React.createElement(PisellPriceText, {
      isMini: dataSource === null || dataSource === void 0 ? void 0 : dataSource.isMini,
      value: (dataSource === null || dataSource === void 0 ? void 0 : dataSource.price) || 0
    });
  }, [isShowPrice, dataSource === null || dataSource === void 0 ? void 0 : dataSource.price, dataSource === null || dataSource === void 0 ? void 0 : dataSource.isMini, isShowFreePrice, isCustomText, customTextType, customTextValue, customTextMinValue, customTextMaxValue]);
  var isShowOriginalPrice = useMemo(function () {
    if (!isOriginPrice) return false;
    var originalPrice = parseFloat(String((dataSource === null || dataSource === void 0 ? void 0 : dataSource.original_price) || 0));
    var price = parseFloat(String((dataSource === null || dataSource === void 0 ? void 0 : dataSource.price) || 0));
    if (isNaN(originalPrice) || isNaN(price)) return false;
    return originalPrice !== 0 && originalPrice !== price;
  }, [isOriginPrice, dataSource === null || dataSource === void 0 ? void 0 : dataSource.original_price, dataSource === null || dataSource === void 0 ? void 0 : dataSource.price]);
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__card-price-wrap")
  }, isShowPrice ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__card-price"),
    style: {
      fontSize: priceFontSize,
      fontWeight: priceFontWeight,
      color: priceColor
    }
  }, priceText) : null, isTaxPrice && parseFloat(String((dataSource === null || dataSource === void 0 ? void 0 : dataSource.tax_fee) || 0)) > 0 ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__card-tax-price")
  }, "(".concat(locales.getText('pisell2.sku-card.gst'), " : "), /*#__PURE__*/React.createElement(PisellPriceText, {
    value: (dataSource === null || dataSource === void 0 ? void 0 : dataSource.tax_fee) || 0,
    isMini: isMiniPrice || (dataSource === null || dataSource === void 0 ? void 0 : dataSource.isMini)
  }), ")") : null, isShowOriginalPrice ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__card-original-price"),
    style: {
      fontSize: originPriceFontSize,
      fontWeight: originPriceFontWeight,
      color: originPriceColor
    }
  }, /*#__PURE__*/React.createElement(PisellPriceText, {
    value: (dataSource === null || dataSource === void 0 ? void 0 : dataSource.original_price) || 0,
    isMini: isMiniPrice || (dataSource === null || dataSource === void 0 ? void 0 : dataSource.isMini)
  })) : null);
};
export default Price;