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/Cart/utils.ts
var utils_exports = {};
__export(utils_exports, {
  checkHolder: () => checkHolder,
  checkLogin: () => checkLogin,
  checkResource: () => checkResource,
  handleAddHolder: () => handleAddHolder
});
module.exports = __toCommonJS(utils_exports);
var checkLogin = async ({
  isLogin,
  openLoginModal,
  isFormSubject,
  utils,
  accountLists,
  appointmentBooking,
  getHolders
}) => {
  if (!isLogin) {
    openLoginModal({
      callback: (status) => {
        if (status === "success") {
        }
      }
    });
    return false;
  }
  return true;
};
var checkHolder = ({ isFormSubject, checkAccount, carts }) => {
  if (isFormSubject && !checkAccount("holder")) {
    const newCarts = carts == null ? void 0 : carts.map((item) => {
      return {
        ...item,
        isErrorHolder: !(item == null ? void 0 : item.holder_id)
      };
    });
    return newCarts;
  }
  return false;
};
var checkResource = ({ carts, resources }) => {
  const isEmptyResourceId = carts == null ? void 0 : carts.some((item) => !(item == null ? void 0 : item.resource_id));
  if (isEmptyResourceId) {
    const newCarts = carts == null ? void 0 : carts.map((item) => {
      var _a;
      let errorText = "";
      if (!(item == null ? void 0 : item.resource_id)) {
        const currentCart = resources == null ? void 0 : resources.find((d) => (d == null ? void 0 : d._id) === (item == null ? void 0 : item._id));
        const currentResources = (currentCart == null ? void 0 : currentCart.resources) || [];
        errorText = ((_a = currentResources == null ? void 0 : currentResources[0]) == null ? void 0 : _a.title) || "";
      }
      return {
        ...item,
        isErrorResource: !(item == null ? void 0 : item.resource_id),
        resourceErrorText: errorText
      };
    });
    return newCarts;
  }
  return false;
};
var handleAddHolder = async ({ res, bookingSubject, accountLists, cartItem, getHolders, appointmentBooking }) => {
  var _a;
  try {
    let result = void 0;
    const relationShipForms = ((_a = res == null ? void 0 : res.values) == null ? void 0 : _a.form_to_form_value) || [];
    const currentForm = relationShipForms.find(
      (item) => item.form_id === (bookingSubject == null ? void 0 : bookingSubject.form_id)
    );
    const form_record_id = Math.max(
      ...(currentForm == null ? void 0 : currentForm.form_data_value) || []
    );
    const oldAccount = accountLists.find(
      (item) => item.id === form_record_id
    );
    await getHolders();
    const newAccountLists = await appointmentBooking.getAccounts();
    if (oldAccount) {
      result = !(cartItem == null ? void 0 : cartItem.holder_id) ? { ...accountLists == null ? void 0 : accountLists[0] } : void 0;
    } else {
      const newAccount = newAccountLists.find(
        (item) => item.id === form_record_id
      );
      result = { ...newAccount || (newAccountLists == null ? void 0 : newAccountLists[0]) };
    }
    return result;
  } catch (error) {
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  checkHolder,
  checkLogin,
  checkResource,
  handleAddHolder
});
