var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/eventBooking/components/Provider/SelectHolderModal.tsx
var SelectHolderModal_exports = {};
__export(SelectHolderModal_exports, {
  default: () => SelectHolderModal_default
});
module.exports = __toCommonJS(SelectHolderModal_exports);
var import_react = __toESM(require("react"));
var import_selectHolder = __toESM(require("../selectHolder"));
var import_utils = require("@pisell/utils");
var import_Sales = require("../../../Sales");
var SelectHolderModal = (props) => {
  var _a;
  const { open } = props;
  const { data } = (0, import_Sales.useSales)();
  const {
    onHolderClose,
    onOpenCreateHolder,
    selectHolder,
    holderData,
    updateHolderList,
    defaultSelectedHolder
  } = (0, import_Sales.useHolder)();
  const { nextStep, prevStep, currentStepData } = (0, import_Sales.useStep)();
  const [selectedHolder, setSelectedHolder] = (0, import_react.useState)(defaultSelectedHolder);
  const { onCloseCart } = (0, import_Sales.useCart)();
  (0, import_react.useEffect)(() => {
    setSelectedHolder(defaultSelectedHolder);
  }, [defaultSelectedHolder]);
  const handleHolder = (e) => {
    var _a2, _b, _c, _d, _e;
    if (!(e == null ? void 0 : e.isAddCard)) {
      setSelectedHolder(e);
      return;
    }
    onOpenCreateHolder({
      form_id: (_e = (_d = (_c = (_b = (_a2 = data.initData) == null ? void 0 : _a2.boardSetting) == null ? void 0 : _b.config) == null ? void 0 : _c.basic) == null ? void 0 : _d.appointment_subject) == null ? void 0 : _e.form_id,
      form_title: import_utils.locales.getText("pisell2.event.create.form"),
      callback: (res) => {
        updateHolderList(res == null ? void 0 : res.values);
      }
    });
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_selectHolder.default,
    {
      open,
      options: (holderData == null ? void 0 : holderData.holderList) || [],
      onCancel: () => onHolderClose(),
      value: selectedHolder == null ? void 0 : selectedHolder.id,
      title: import_utils.locales.getText("pisell2.event.holder.modal.title"),
      okText: import_utils.locales.getText("pisell2.event.confirm"),
      onClick: (e) => handleHolder(e),
      disabled: !((_a = holderData == null ? void 0 : holderData.holderList) == null ? void 0 : _a.length) || !(selectedHolder == null ? void 0 : selectedHolder.id),
      errorTipText: import_utils.locales.getText("pisell2.event.error.holder"),
      onOk: () => {
        onCloseCart();
        const isEvent = (currentStepData == null ? void 0 : currentStepData.key) === "select-event";
        selectHolder(selectedHolder, isEvent ? "addToCart" : "createCartItem");
        if (isEvent) {
          nextStep();
        } else {
          prevStep();
        }
        onHolderClose();
      }
    }
  );
};
var SelectHolderModal_default = SelectHolderModal;
