/**
 * 格式化账户到购物车
 * @param account 账户
 * @returns 格式化后的账户
 */
export var formatAccountToCartItem = function formatAccountToCartItem(params) {
  var cartItem = params.cartItem,
    account = params.account;
  if (account) {
    cartItem.holder_id = account.id;
    cartItem.holder_title = account.username;
  }
  var oringin = formatAccountToCartItemOrigin(params);
  cartItem._origin = oringin;
  return cartItem;
};
export var formatAccountToCartItemOrigin = function formatAccountToCartItemOrigin(params) {
  var cartItem = params.cartItem,
    account = params.account;
  var origin = cartItem._origin;
  if (account) {
    if ((account === null || account === void 0 ? void 0 : account.type) === 'holder') {
      var _ref = (account === null || account === void 0 ? void 0 : account._origin) || {},
        customer_id = _ref.customer_id,
        form_id = _ref.form_id,
        form_record_id = _ref.form_record_id;
      origin.holder = {
        customer_id: customer_id,
        form_id: form_id,
        form_record: form_record_id ? [form_record_id] : null
      };
    } else {
      origin.metadata.account = account;
    }
  }
  return origin;
};

/**
 * 从购物车中删除账户信息
 * @param cartItem 购物车
 * @returns 删除后的购物车
 */
export var deleteHolderFromCartItem = function deleteHolderFromCartItem(cartItem) {
  // 删除UI层的数据
  cartItem.holder_id = undefined;
  cartItem.holder_title = undefined;

  // 删除原始数据
  cartItem._origin.holder = null;
  return cartItem;
};