// 失败结果代码
var FAILED_RESULT_CODES = ['refused', 'cancelled', 'error'];

/**
 * 将三方支付返回码归一为落地页展示状态。
 * @param resultCode 支付渠道回跳 URL 中的 resultCode
 * @returns 页面展示状态
 */
export var getPaymentResultStatus = function getPaymentResultStatus(resultCode) {
  var normalizedResultCode = resultCode === null || resultCode === void 0 ? void 0 : resultCode.trim().toLowerCase();
  if (normalizedResultCode === 'authorised') {
    return 'success';
  }
  if (normalizedResultCode && FAILED_RESULT_CODES.includes(normalizedResultCode)) {
    return 'failed';
  }
  return 'querying';
};

/**
 * 从三方支付返回码中提取失败原因。
 * @param resultCode 支付渠道回跳 URL 中的 resultCode
 * @returns 页面展示用失败原因
 */
export var getPaymentResultFailReason = function getPaymentResultFailReason(resultCode) {
  var normalizedResultCode = resultCode === null || resultCode === void 0 ? void 0 : resultCode.trim().toLowerCase();
  if (normalizedResultCode && FAILED_RESULT_CODES.includes(normalizedResultCode)) {
    return normalizedResultCode;
  }
  return undefined;
};