/**
 * @title: 更新表单数据
 * @description: 
 * @return {*}
 * @Author: WangHan
 * @Date: 2025-05-26 16:58
 */
export var updateRelationForms = function updateRelationForms(carts, currentCart, values) {
  var _cartItem$_origin;
  if (!(currentCart !== null && currentCart !== void 0 && currentCart.cart_id)) return [];
  var cartItem = carts === null || carts === void 0 ? void 0 : carts.find(function (item) {
    return (item === null || item === void 0 ? void 0 : item._id) === (currentCart === null || currentCart === void 0 ? void 0 : currentCart.cart_id);
  });
  var oldLists = (cartItem === null || cartItem === void 0 || (_cartItem$_origin = cartItem._origin) === null || _cartItem$_origin === void 0 ? void 0 : _cartItem$_origin.relation_forms) || [];
  var newData = {
    form_id: Number(values === null || values === void 0 ? void 0 : values.form_id),
    form_record_id: values === null || values === void 0 ? void 0 : values.form_record_id
  };
  var exist = oldLists.find(function (item) {
    return item.form_id === (newData === null || newData === void 0 ? void 0 : newData.form_id);
  });

  // 如果在目前的数组中找到form_id相同的，则更新form_record_ids参数，否则新增一条数据
  if (exist) {
    var _exist$form_record_id;
    if (!(exist !== null && exist !== void 0 && (_exist$form_record_id = exist.form_record_ids) !== null && _exist$form_record_id !== void 0 && _exist$form_record_id.includes(newData.form_record_id))) {
      exist.form_record_ids.push(newData.form_record_id);
    }
  } else {
    oldLists.push({
      form_id: newData.form_id,
      form_record_ids: [newData.form_record_id]
    });
  }
  return oldLists;
};