//#region src/components/appointmentBooking/components/Form/utils.ts
/**
* @title: 更新表单数据
* @description: 
* @return {*}
* @Author: WangHan
* @Date: 2025-05-26 16:58
*/
const updateRelationForms = (carts, currentCart, values, currentStepKey) => {
	var _cartItem$_origin;
	if (!(currentCart === null || currentCart === void 0 ? void 0 : currentCart.cart_id)) return [];
	const cartItem = carts === null || carts === void 0 ? void 0 : carts.find((item) => (item === null || item === void 0 ? void 0 : item._id) === (currentCart === null || currentCart === void 0 ? void 0 : currentCart.cart_id));
	let oldLists = (cartItem === null || cartItem === void 0 || (_cartItem$_origin = cartItem._origin) === null || _cartItem$_origin === void 0 ? void 0 : _cartItem$_origin.relation_forms) || [];
	const newData = {
		form_id: Number(values === null || values === void 0 ? void 0 : values.form_id),
		form_record_ids: [values === null || values === void 0 ? void 0 : values.form_record_id],
		cartId: currentCart === null || currentCart === void 0 ? void 0 : currentCart.cart_id,
		currentStepKey
	};
	const existIndex = oldLists.findIndex((item) => item.cartId === newData.cartId && item.form_id === newData.form_id && item.currentStepKey === newData.currentStepKey);
	if (existIndex > -1) oldLists[existIndex].form_record_ids = newData.form_record_ids;
	else oldLists = oldLists.concat(newData);
	return oldLists;
};
//#endregion
exports.updateRelationForms = updateRelationForms;
