function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import { useRef } from 'react';
import { sendWarningLog } from '@pisell/utils';
import { useMemoizedFn } from 'ahooks';
/**
 * @title: 支付日志记录器 Hook
 * @description: 用于记录支付过程中的关键信息
 * @param {UsePaymentLoggerOptions} options - 配置选项
 * @return {object} 返回日志记录相关方法
 * @Author: AI Assistant
 */
var usePaymentLogger = function usePaymentLogger(options) {
  var orderId = options.orderId,
    _options$step = options.step,
    step = _options$step === void 0 ? 'unknown' : _options$step;
  var logs = useRef([]);

  /**
   * @title: 添加日志条目
   * @description: 向日志列表中添加一条记录
   * @param {LogData} logData - 日志数据 { key: '描述', value: '值' }
   * @return {void}
   */
  var addLog = useMemoizedFn(function (logData) {
    logs.current.push({
      key: logData.key,
      value: logData.value
    });
  });

  /**
   * @title: 发送当前日志
   * @description: 发送当前所有日志到 sendWarningLog
   * @param {string} title - 日志标题
   * @return {void}
   */
  var sendLogs = useMemoizedFn(function () {
    var title = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '支付日志';
    var err = arguments.length > 1 ? arguments[1] : undefined;
    var content = [{
      key: 'title',
      value: title
    }].concat(_toConsumableArray(logs.current));
    if (err) {
      content.push.apply(content, [{
        key: '错误信息',
        value: (err === null || err === void 0 ? void 0 : err.message) || '未知错误'
      }, {
        key: '错误堆栈',
        value: (err === null || err === void 0 ? void 0 : err.stack) || '无堆栈信息'
      }, {
        key: '错误类型',
        value: (err === null || err === void 0 ? void 0 : err.name) || '未知错误类型'
      }]);
    }
    var formatLogs = content.map(function (item) {
      return {
        key: item.key,
        value: JSON.stringify(item.value)
      };
    });
    sendWarningLog({
      title: "h5\u652F\u4ED8step".concat(step, ":").concat(orderId),
      content: formatLogs
    });
  });
  return {
    logs: logs,
    addLog: addLog,
    sendLogs: sendLogs
  };
};
export default usePaymentLogger;