import React from 'react';
import { formatAmount } from '@pisell/utils';
/**
 * 格式化货币金额
 */
export var formatCurrency = function formatCurrency(amount) {
  var amountSymbol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '$';
  return formatAmount(amount, 2, amountSymbol);
};

/**
 * 根据支付状态计算标题
 */
export var calculateTitle = function calculateTitle(status, failureReason) {
  var getText = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
    return '';
  };
  switch (status) {
    case 'paid':
    case 'partially_paid':
      return getText('payment.result.success');
    case 'failed':
      var reason = failureReason ? " - ".concat(failureReason) : '';
      return "".concat(getText('payment.result.failed')).concat(reason);
    case 'wallet-pass-redemption-failed':
      return getText('pisell2.checkout.wallet-pass.redemption-failed') || 'Wallet pass redeem failed';
    default:
      return getText('payment.result.success');
  }
};

/**
 * 生成副标题CSS类名的辅助函数
 */
export var getSubtitleClassName = function getSubtitleClassName(colorClass) {
  return "payment-result-toast-subtitle-text ".concat(colorClass);
};

/**
 * 根据支付状态和金额计算副标题
 */
export var calculateSubtitle = function calculateSubtitle(status, amount, gapAmount) {
  var getText = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {
    return '';
  };
  var amountSymbol = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '$';
  var text;
  var colorClass;
  switch (status) {
    case 'paid':
      if (gapAmount) {
        // 找零金额不为0，显示找零金额
        text = "".concat(getText('payment.result.changeDue') || 'Change Due', " ").concat(formatCurrency(Math.abs(gapAmount), amountSymbol));
        colorClass = 'partially-paid'; // 橙色
      } else {
        text = "".concat(getText('payment.result.paid') || 'Paid', " ").concat(formatCurrency(amount, amountSymbol));
        colorClass = 'paid'; // 绿色
      }
      break;
    case 'partially_paid':
      var displayAmount = gapAmount !== null && gapAmount !== void 0 ? gapAmount : amount;
      text = "".concat(getText('payment.result.partiallyPaid') || 'Partially Paid', " ").concat(formatCurrency(displayAmount, amountSymbol));
      colorClass = 'partially-paid'; // 橙色
      break;
    case 'failed':
      text = "".concat(getText('payment.result.amountDue') || 'Amount Due', " ").concat(formatCurrency(amount, amountSymbol));
      colorClass = 'amount-due'; // 红色
      break;
    case 'wallet-pass-redemption-failed':
      var successAmount = gapAmount !== null && gapAmount !== void 0 ? gapAmount : amount;
      text = "".concat(getText('payment.result.partiallyPaid') || 'Partially Paid', " ").concat(formatCurrency(successAmount, amountSymbol));
      colorClass = 'partially-paid'; // 绿色
      break;
    default:
      return null;
  }

  // 返回带样式的JSX元素，包含完整的结构和样式
  return /*#__PURE__*/React.createElement('div', {
    className: 'payment-result-toast-subtitle'
  }, /*#__PURE__*/React.createElement('h1', {
    className: getSubtitleClassName(colorClass)
  }, text));
};

/**
 * 根据支付状态计算StatusClassName
 */
export var calculateStatusClassName = function calculateStatusClassName(status) {
  switch (status) {
    case 'paid':
    case 'partially_paid':
      return 'success';
    case 'failed':
      return 'failed';
    case 'wallet-pass-redemption-failed':
      return 'wallet-pass-failed';
    default:
      return 'success';
  }
};

/**
 * 根据支付状态计算自动关闭配置
 */
export var calculateAutoCloseConfig = function calculateAutoCloseConfig(status, hasChangeDue) {
  switch (status) {
    case 'paid':
      return {
        autoClose: true,
        autoCloseDelay: hasChangeDue ? 30 : 5,
        // 有找零30秒，无找零5秒
        maskClosable: true
      };
    case 'partially_paid':
      return {
        autoClose: true,
        autoCloseDelay: 5,
        maskClosable: true
      };
    case 'failed':
    case 'wallet-pass-redemption-failed':
      return {
        autoClose: false,
        autoCloseDelay: 0,
        maskClosable: false
      };
    default:
      return {
        autoClose: false,
        autoCloseDelay: 5,
        maskClosable: false
      };
  }
};