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/plus/pisellReservation/components/bookingChangeModal/index.tsx
var bookingChangeModal_exports = {};
__export(bookingChangeModal_exports, {
  closeBookingChangeModal: () => close,
  default: () => bookingChangeModal_default,
  openBookingChangeModal: () => open
});
module.exports = __toCommonJS(bookingChangeModal_exports);
var import_react = __toESM(require("react"));
var import_react_dom = __toESM(require("react-dom"));
var import_ahooks = require("ahooks");
var import_utils = require("@pisell/utils");
var import_utils2 = require("../../../../utils");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_locales = __toESM(require("./locales"));
var import_utils3 = require("./utils");
var import_index = require("./index.less");
var CLOSE_ANIMATION_MS = 180;
var HOUR_SLOT_EPS = 1e-3;
var activeInstance = null;
function initBookingChangeLocales(locale = "en") {
  import_utils.locales.init(import_locales.default, locale || "en");
}
initBookingChangeLocales();
function getText(key) {
  return import_utils.locales.getText(key);
}
function formatText(id, params) {
  return Object.keys(params).reduce((text, key) => {
    return text.replace(new RegExp(`\\{${key}\\}`, "g"), String(params[key]));
  }, getText(id));
}
function destroyActiveInstance() {
  if (!activeInstance) {
    return;
  }
  const { container } = activeInstance;
  activeInstance = null;
  import_react_dom.default.unmountComponentAtNode(container);
  if (document.body.contains(container)) {
    document.body.removeChild(container);
  }
}
function closeActiveInstance(reason) {
  if (!activeInstance) {
    return;
  }
  const { reject } = activeInstance;
  destroyActiveInstance();
  reject(reason);
}
var BookingChangeModalRenderer = ({
  options,
  onResolve,
  onReject
}) => {
  var _a, _b, _c, _d;
  const context = (0, import_useEngineContext.default)();
  initBookingChangeLocales(((_b = (_a = context == null ? void 0 : context.engine) == null ? void 0 : _a.props) == null ? void 0 : _b.locale) || "en");
  const {
    item,
    courts = [],
    visibleCourts,
    bookings = [],
    selectedCustomer: initialCustomer = null,
    title = getText(`pisell-reservation.booking-change.title`),
    description = getText(`pisell-reservation.booking-change.description`),
    confirmText = getText(`pisell-reservation.booking-change.confirm`),
    cancelText = getText(`pisell-reservation.booking-change.cancel`),
    closeOnBackdrop = true,
    zIndex = 1072,
    theme = "dark"
  } = options;
  const panelRef = (0, import_react.useRef)(null);
  const closedRef = (0, import_react.useRef)(false);
  const timerRef = (0, import_react.useRef)(null);
  const [visible, setVisible] = (0, import_react.useState)(false);
  const [submitLoading, setSubmitLoading] = (0, import_react.useState)(false);
  const [submitError, setSubmitError] = (0, import_react.useState)("");
  const [draft, setDraft] = (0, import_react.useState)({
    targetCourtId: options.targetCourtId,
    targetDate: options.targetDate,
    targetHour: options.targetHour
  });
  const requestClient = (_d = (_c = context == null ? void 0 : context.appHelper) == null ? void 0 : _c.utils) == null ? void 0 : _d.request;
  const [resourceCourtIds, setResourceCourtIds] = (0, import_react.useState)([]);
  const orderId = (0, import_react.useMemo)(() => (0, import_utils3.getOrderId)(item), [item]);
  const itemResources = (0, import_react.useMemo)(() => (0, import_utils3.getItemResourceRecords)(item), [item]);
  (0, import_react.useEffect)(() => {
    if (requestClient) {
      import_utils2.request.setRequest(requestClient);
    }
  }, [requestClient]);
  const { data: orderDetail } = (0, import_ahooks.useRequest)(
    async () => {
      const response = await import_utils2.request.getRequest().get(`/shop/order/appointment/${orderId}`, {});
      return (0, import_utils3.asRecord)(response == null ? void 0 : response.data);
    },
    {
      ready: Boolean(requestClient && orderId),
      refreshDeps: [requestClient, orderId]
    }
  );
  const currentEventResources = (0, import_react.useMemo)(() => {
    var _a2, _b2;
    if (!orderDetail) return [];
    const list = (0, import_utils3.asRecordList)((_a2 = (0, import_utils3.asRecord)(orderDetail.bookings)) == null ? void 0 : _a2.list);
    const itemId = String((_b2 = item.raw) == null ? void 0 : _b2.id);
    const matched = list.find((b) => String(b.id) === itemId);
    if (!matched) return [];
    return (0, import_utils3.asRecordList)(matched.event_resources);
  }, [orderDetail, item]);
  const resourceFormNameMap = (0, import_react.useMemo)(() => {
    const map = new Map(
      itemResources.map((r) => [
        String(r.form_id),
        r.metadata.form_name || ""
      ])
    );
    for (const res of currentEventResources) {
      const formName = String(((0, import_utils3.asRecord)(res.metadata) || {}).form_name || "");
      if (formName) {
        map.set(String(res.form_id), formName);
      }
    }
    return map;
  }, [currentEventResources, itemResources]);
  (0, import_react.useEffect)(() => {
    if (currentEventResources.length === 0) return;
    setResourceCourtIds(
      currentEventResources.map(
        (res) => String(res.relation_id) === item.courtId ? draft.targetCourtId : String(res.relation_id)
      )
    );
  }, [currentEventResources]);
  const baseCourts = (0, import_react.useMemo)(() => {
    const source = (visibleCourts && visibleCourts.length > 0 ? visibleCourts : courts) || [];
    if (source.length > 0) {
      return source;
    }
    return Array.from(new Set([item.courtId, options.targetCourtId].filter(Boolean))).map((courtId) => ({ id: courtId, name: courtId }));
  }, [courts, item.courtId, options.targetCourtId, visibleCourts]);
  const { data: scheduleResourceCourts = [], loading: resourceRequestLoading } = (0, import_ahooks.useRequest)(
    async () => {
      const response = await import_utils2.request.getRequest().get(`/shop/schedule/resource/list`, {
        date: draft.targetDate
      });
      return (0, import_utils3.getScheduleResourceList)(response == null ? void 0 : response.data).map(
        (resource) => (0, import_utils3.buildScheduleResourceCourt)(
          resource,
          resourceFormNameMap.get(String(resource.form_id)) || ""
        )
      ).filter(Boolean);
    },
    {
      ready: Boolean(requestClient),
      refreshDeps: [requestClient, draft.targetDate]
    }
  );
  const allCourts = (0, import_react.useMemo)(
    () => (0, import_utils3.mergeCourts)([baseCourts, scheduleResourceCourts]),
    [baseCourts, scheduleResourceCourts]
  );
  const normalizedCourtMap = (0, import_react.useMemo)(
    () => new Map(allCourts.map((court) => [court.id, (0, import_utils3.normalizeCourt)(court)])),
    [allCourts]
  );
  const currentCustomer = (0, import_react.useMemo)(
    () => (0, import_utils3.buildCustomer)({
      orderDetail,
      selectedCustomer: initialCustomer,
      fallbackCustomerText: getText(`pisell-reservation.booking-change.fallback-customer`)
    }),
    [initialCustomer, orderDetail]
  );
  const hourSlots = (0, import_react.useMemo)(
    () => options.hourSlots && options.hourSlots.length > 0 ? options.hourSlots : (0, import_utils3.getFallbackHourSlots)(),
    [options.hourSlots]
  );
  const formatHourLabel = options.formatHourLabel || import_utils3.defaultFormatHourLabel;
  const isBusinessHour = options.isBusinessHour || (() => true);
  const availableHours = (0, import_react.useMemo)(() => {
    const filtered = hourSlots.filter((hour) => isBusinessHour(hour));
    return filtered.length > 0 ? filtered : hourSlots;
  }, [hourSlots, isBusinessHour]);
  const hourStep = (0, import_react.useMemo)(() => (0, import_utils3.getHourStep)(hourSlots), [hourSlots]);
  const firstTimelineHour = options.firstTimelineHour ?? Math.min(...hourSlots) ?? 0;
  const endTimelineExclusive = options.endTimelineExclusive ?? Math.max(...hourSlots) + hourStep;
  const slotAlignOpenKeyRef = (0, import_react.useRef)(null);
  (0, import_react.useLayoutEffect)(() => {
    if (availableHours.length === 0) return;
    const openKey = `${item.id}|${options.targetDate}|${options.targetCourtId}|${options.targetHour}|${availableHours.join(",")}`;
    if (slotAlignOpenKeyRef.current === openKey) return;
    const durHours = item.endHour - item.startHour;
    if (!Number.isFinite(durHours) || durHours < 0) {
      slotAlignOpenKeyRef.current = openKey;
      return;
    }
    const aligned = (0, import_utils3.alignBookingDraftToSlots)(options.targetHour, durHours, availableHours);
    slotAlignOpenKeyRef.current = openKey;
    if (Math.abs(aligned - options.targetHour) > HOUR_SLOT_EPS) {
      setDraft((prev) => ({ ...prev, targetHour: aligned }));
    }
  }, [
    availableHours,
    item.endHour,
    item.id,
    item.startHour,
    options.targetCourtId,
    options.targetDate,
    options.targetHour
  ]);
  const duration = item.endHour - item.startHour;
  const nextStartHour = draft.targetHour;
  const nextEndHour = nextStartHour + duration;
  const nextStartHourForSelect = availableHours.find((h) => Math.abs(h - nextStartHour) < HOUR_SLOT_EPS) ?? (0, import_utils3.nearestHourInSlots)(nextStartHour, availableHours);
  const nextEndHourForSelect = availableHours.find((h) => Math.abs(h - nextEndHour) < HOUR_SLOT_EPS) ?? (0, import_utils3.nearestHourInSlots)(nextEndHour, availableHours);
  const originalDate = item.date;
  const originalStart = formatHourLabel(item.startHour);
  const originalEnd = formatHourLabel(item.endHour);
  const anyResourceSelectionChanged = currentEventResources.some(
    (res, i) => resourceCourtIds[i] !== void 0 && resourceCourtIds[i] !== String(res.relation_id)
  );
  const resourceChanged = currentEventResources.length > 0 ? anyResourceSelectionChanged : item.courtId !== draft.targetCourtId;
  const changed = originalDate !== draft.targetDate || item.startHour !== nextStartHour || resourceChanged;
  const isDragScenario = item.date !== options.targetDate || item.startHour !== options.targetHour || item.courtId !== options.targetCourtId;
  const hasConflict = options.hasConflict || (() => {
    return false;
  });
  const conflict = hasConflict(
    bookings,
    draft.targetCourtId,
    draft.targetDate,
    nextStartHour,
    nextEndHour,
    item.id
  );
  const isLight = theme === "light";
  const finishClose = (type, payload) => {
    if (closedRef.current) {
      return;
    }
    closedRef.current = true;
    setVisible(false);
    timerRef.current = window.setTimeout(() => {
      if (type === "resolve") {
        onResolve(payload);
      } else {
        onReject(payload);
      }
    }, CLOSE_ANIMATION_MS);
  };
  const handleCancel = (reasonType) => {
    if (submitLoading) {
      return;
    }
    finishClose("reject", { type: reasonType });
  };
  (0, import_react.useEffect)(() => {
    const rafId = window.requestAnimationFrame(() => {
      setVisible(true);
    });
    const previousOverflow = document.body.style.overflow;
    document.body.style.overflow = "hidden";
    const onKeyDown = (event) => {
      if (event.key === "Escape") {
        handleCancel("escape");
      }
    };
    window.addEventListener("keydown", onKeyDown);
    return () => {
      window.cancelAnimationFrame(rafId);
      window.removeEventListener("keydown", onKeyDown);
      document.body.style.overflow = previousOverflow;
      if (timerRef.current) {
        window.clearTimeout(timerRef.current);
      }
    };
  }, []);
  const handleConfirm = async () => {
    if (conflict || submitLoading) {
      return;
    }
    setSubmitError("");
    const resultBase = {
      item,
      original: {
        targetCourtId: options.targetCourtId,
        targetDate: options.targetDate,
        targetHour: options.targetHour
      },
      draft,
      customer: currentCustomer,
      duration,
      nextEndHour,
      changed,
      submitPayload: (0, import_utils3.buildSubmitPayload)({
        item,
        draft,
        duration,
        nextEndHour,
        currentEventResources,
        resourceCourtIds,
        resourceCourtMap: normalizedCourtMap,
        orderDetail
      })
    };
    if (!options.onSubmit) {
      finishClose("resolve", resultBase);
      return;
    }
    setSubmitLoading(true);
    try {
      const submitResult = await options.onSubmit({
        ...resultBase,
        options
      });
      finishClose("resolve", {
        ...resultBase,
        submitResult
      });
    } catch (error) {
      const message = (error == null ? void 0 : error.message) || options.submitErrorMessage || getText(`pisell-reservation.booking-change.submit-failed`);
      setSubmitError(message);
    } finally {
      setSubmitLoading(false);
    }
  };
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: [
        "pisell-booking-change-modal",
        visible ? "is-visible" : "",
        isLight ? "is-light" : "is-dark"
      ].filter(Boolean).join(" "),
      style: { zIndex },
      onMouseDown: (event) => {
        if (event.target === event.currentTarget && closeOnBackdrop) {
          handleCancel("backdrop");
        }
      }
    },
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        ref: panelRef,
        className: "pisell-booking-change-modal__panel",
        onMouseDown: (event) => event.stopPropagation()
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__title" }, title),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__description" }, description),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__body" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__card" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__customer" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__customer-info" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__section-label" }, getText(`pisell-reservation.booking-change.customer`)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__customer-name" }, currentCustomer.name), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__customer-meta" }, currentCustomer.phone || getText(`pisell-reservation.booking-change.no-phone`)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__customer-meta" }, currentCustomer.email || getText(`pisell-reservation.booking-change.no-email`)), currentCustomer.memberId && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__customer-meta" }, currentCustomer.memberId)))), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__grid" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__field", style: { gridColumn: "1 / -1" } }, /* @__PURE__ */ import_react.default.createElement("label", { className: "pisell-booking-change-modal__field-label" }, getText(`pisell-reservation.booking-change.new-date`)), /* @__PURE__ */ import_react.default.createElement(
        "input",
        {
          type: "date",
          value: draft.targetDate,
          onChange: (event) => setDraft((prev) => ({
            ...prev,
            targetDate: event.target.value
          })),
          className: "pisell-booking-change-modal__control"
        }
      ))), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__grid" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__field" }, /* @__PURE__ */ import_react.default.createElement("label", { className: "pisell-booking-change-modal__field-label" }, getText(`pisell-reservation.booking-change.new-start-time`)), /* @__PURE__ */ import_react.default.createElement(
        "select",
        {
          value: nextStartHourForSelect,
          onChange: (event) => setDraft((prev) => ({
            ...prev,
            targetHour: Number(event.target.value)
          })),
          className: "pisell-booking-change-modal__control"
        },
        availableHours.map((hour) => {
          const disabled = hour + duration > endTimelineExclusive || hasConflict(
            bookings,
            draft.targetCourtId,
            draft.targetDate,
            hour,
            hour + duration,
            item.id
          );
          return /* @__PURE__ */ import_react.default.createElement("option", { key: hour, value: hour, disabled }, disabled ? formatText(
            `pisell-reservation.booking-change.unavailable-time`,
            { time: formatHourLabel(hour) }
          ) : formatHourLabel(hour));
        })
      )), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__field" }, /* @__PURE__ */ import_react.default.createElement("label", { className: "pisell-booking-change-modal__field-label" }, getText(`pisell-reservation.booking-change.new-end-time`)), /* @__PURE__ */ import_react.default.createElement(
        "select",
        {
          value: nextEndHourForSelect,
          onChange: (event) => {
            const targetEndHour = Number(event.target.value);
            setDraft((prev) => ({
              ...prev,
              targetHour: targetEndHour - duration
            }));
          },
          className: "pisell-booking-change-modal__control"
        },
        availableHours.map((hour) => {
          const startHour = hour - duration;
          const disabled = startHour < firstTimelineHour || hasConflict(
            bookings,
            draft.targetCourtId,
            draft.targetDate,
            startHour,
            hour,
            item.id
          );
          return /* @__PURE__ */ import_react.default.createElement("option", { key: `end-${hour}`, value: hour, disabled }, disabled ? formatText(
            `pisell-reservation.booking-change.unavailable-time`,
            { time: formatHourLabel(hour) }
          ) : formatHourLabel(hour));
        })
      ))), currentEventResources.length > 0 && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__grid" }, currentEventResources.map((resource, index) => {
        const resourceMeta = (0, import_utils3.asRecord)(resource.metadata) || {};
        const formName = String(resourceMeta.form_name || resource.form_id);
        const originalId = String(resource.relation_id);
        const originalName = String(resourceMeta.resource_name || originalId);
        const courtOptions = scheduleResourceCourts.filter(
          (c) => String(c.form_id) === String(resource.form_id)
        );
        const hasOriginal = courtOptions.some((c) => c.id === originalId);
        return /* @__PURE__ */ import_react.default.createElement("div", { key: index, className: "pisell-booking-change-modal__field" }, /* @__PURE__ */ import_react.default.createElement("label", { className: "pisell-booking-change-modal__field-label" }, formName), /* @__PURE__ */ import_react.default.createElement(
          "select",
          {
            value: resourceCourtIds[index] ?? originalId,
            onChange: (event) => {
              const value = event.target.value;
              setResourceCourtIds((prev) => {
                const next = [...prev];
                next[index] = value;
                return next;
              });
            },
            disabled: resourceRequestLoading,
            className: "pisell-booking-change-modal__control"
          },
          !hasOriginal && /* @__PURE__ */ import_react.default.createElement("option", { value: originalId }, originalName),
          courtOptions.map((court) => /* @__PURE__ */ import_react.default.createElement("option", { key: court.id, value: court.id }, court.name))
        ));
      })), changed && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__card" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__section-label" }, getText(`pisell-reservation.booking-change.previous-booking-info`)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__compare-grid" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__compare-card" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__compare-title" }, getText(`pisell-reservation.booking-change.original`)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__compare-value" }, originalDate), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__compare-value" }, originalStart, " - ", originalEnd), currentEventResources.length > 0 && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__resource-list" }, currentEventResources.map((res, i) => /* @__PURE__ */ import_react.default.createElement("div", { key: i, className: "pisell-booking-change-modal__resource-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__resource-name" }, String(((0, import_utils3.asRecord)(res.metadata) || {}).resource_name || res.relation_id)))))), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__compare-card is-highlighted" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__compare-title" }, isDragScenario ? getText(`pisell-reservation.booking-change.drop-target`) : getText(`pisell-reservation.booking-change.updated`)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__compare-value" }, draft.targetDate), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__compare-value" }, formatHourLabel(nextStartHour), " - ", formatHourLabel(nextEndHour)), currentEventResources.length > 0 && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__resource-list" }, currentEventResources.map((res, i) => {
        const selectedId = resourceCourtIds[i];
        const originalId = String(res.relation_id);
        let name = String(((0, import_utils3.asRecord)(res.metadata) || {}).resource_name || originalId);
        if (selectedId && selectedId !== originalId) {
          const court = normalizedCourtMap.get(selectedId);
          if (court) {
            name = String(court.metadata.resource_name || court.name);
          }
        }
        return /* @__PURE__ */ import_react.default.createElement("div", { key: i, className: "pisell-booking-change-modal__resource-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__resource-name" }, name));
      })))))),
      conflict && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__error" }, getText(`pisell-reservation.booking-change.conflict`)),
      !conflict && submitError && /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__error" }, submitError),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-booking-change-modal__footer" }, /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          type: "button",
          onClick: () => handleCancel("cancel"),
          disabled: submitLoading,
          className: "pisell-booking-change-modal__ghost-button"
        },
        cancelText
      ), /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          type: "button",
          disabled: conflict || submitLoading || resourceRequestLoading,
          onClick: handleConfirm,
          className: "pisell-booking-change-modal__primary-button"
        },
        submitLoading ? getText(`pisell-reservation.booking-change.submitting`) : confirmText
      ))
    )
  );
};
function open(options) {
  if (typeof window === "undefined" || typeof document === "undefined") {
    return Promise.reject({
      type: "programmatic-close",
      message: getText(`pisell-reservation.booking-change.browser-only`)
    });
  }
  if (activeInstance) {
    closeActiveInstance({
      type: "replaced",
      message: getText(`pisell-reservation.booking-change.replaced`)
    });
  }
  const container = document.createElement("div");
  document.body.appendChild(container);
  return new Promise((resolve, reject) => {
    activeInstance = {
      container,
      reject
    };
    const handleResolve = (result) => {
      destroyActiveInstance();
      resolve(result);
    };
    const handleReject = (reason) => {
      destroyActiveInstance();
      reject(reason);
    };
    import_react_dom.default.render(
      /* @__PURE__ */ import_react.default.createElement(
        BookingChangeModalRenderer,
        {
          options,
          onResolve: handleResolve,
          onReject: handleReject
        }
      ),
      container
    );
  });
}
function close(reason) {
  closeActiveInstance(
    reason || {
      type: "programmatic-close"
    }
  );
}
var bookingChangeModal = {
  open,
  close
};
var bookingChangeModal_default = bookingChangeModal;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  closeBookingChangeModal,
  openBookingChangeModal
});
