var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/appointmentBooking/components/Form/utils.ts
var utils_exports = {};
__export(utils_exports, {
  updateRelationForms: () => updateRelationForms
});
module.exports = __toCommonJS(utils_exports);
var updateRelationForms = (carts, currentCart, values, currentStepKey) => {
  var _a;
  if (!(currentCart == null ? void 0 : currentCart.cart_id)) return [];
  const cartItem = carts == null ? void 0 : carts.find(
    (item) => (item == null ? void 0 : item._id) === (currentCart == null ? void 0 : currentCart.cart_id)
  );
  let oldLists = ((_a = cartItem == null ? void 0 : cartItem._origin) == null ? void 0 : _a.relation_forms) || [];
  const newData = { form_id: Number(values == null ? void 0 : values.form_id), form_record_ids: [values == null ? void 0 : values.form_record_id], cartId: currentCart == null ? 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;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  updateRelationForms
});
