function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
import { EventCallbackCode } from "../type";
export function adaptSubmitResult(result) {
  return {
    status: result.status || 'FAIL',
    error: result.error ? {
      code: result.error.code,
      message: result.error.message
    } : undefined,
    userCanceled3D: result.userCanceled3D,
    session: result.paymentSession ? {
      nextAction: {
        applinkUrl: result.paymentSession.returnAppUrl,
        normalUrl: result.paymentSession.returnUrl,
        schemeUrl: result.paymentSession.returnAppScheme
      }
    } : undefined
  };
}
export function adaptErrorToEventCallback(error) {
  return {
    code: error.code || EventCallbackCode.SDK_PAYMENT_ERROR,
    message: error.message || ''
  };
}

/**
 * 将老架构的 appearance 格式转换为新架构格式
 *
 * 转换规则：
 * 1. theme: kebab-case → camelCase（如 'nostalgic-gray' → 'nostalgicGray'），其余保持不变
 * 2. variables: 直接透传（kebab-case CSS 变量 key-value）
 * 3. card.showBrandIcon → displaySetting.showCardBrandIcon
 * 4. layout: 直接透传
 */
export function adaptAppearance(appearance, merchantAppointParam) {
  var _appearance$card, _merchantAppointParam, _appearance$accordion, _appearance$card2;
  if (!appearance) return undefined;
  var result = {};

  // Theme mapping: kebab-case → camelCase
  if (appearance.theme) {
    result.theme = appearance.theme;
  }

  // Variables: 直接透传
  if (appearance.variables && _typeof(appearance.variables) === 'object') {
    var filtered = _objectSpread({}, appearance.variables);
    if (Object.keys(filtered).length > 0) {
      result.variables = filtered;
    }
  }
  result.displaySetting = {
    showCardBrandIcon: !!((_appearance$card = appearance.card) !== null && _appearance$card !== void 0 && _appearance$card.showBrandIcon),
    showCardCVV: !!(merchantAppointParam !== null && merchantAppointParam !== void 0 && (_merchantAppointParam = merchantAppointParam.storedCard) !== null && _merchantAppointParam !== void 0 && _merchantAppointParam.needCVV),
    showPaymentMethodListWhenSingleOption: (merchantAppointParam === null || merchantAppointParam === void 0 ? void 0 : merchantAppointParam.singleOption) === 'list',
    showRadioWhenAccordionLayout: !!((_appearance$accordion = appearance.accordion) !== null && _appearance$accordion !== void 0 && _appearance$accordion.showRadio)
  };

  // card.showBrandIcon → displaySetting.showCardBrandIcon
  if (((_appearance$card2 = appearance.card) === null || _appearance$card2 === void 0 ? void 0 : _appearance$card2.showBrandIcon) !== undefined) {
    result.displaySetting = {
      showCardBrandIcon: appearance.card.showBrandIcon
    };
  }

  // Layout: 直接透传
  if (appearance.layout) {
    var _appearance$layout$ty;
    result.layout = ((_appearance$layout$ty = appearance.layout.type) === null || _appearance$layout$ty === void 0 ? void 0 : _appearance$layout$ty.toLowerCase()) || 'accordion';
  }
  return Object.keys(result).length > 0 ? result : undefined;
}