const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_index = require("../../../../utils/index.js");
const require_locales = require("./locales.js");
const require_utils = require("./utils.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let ahooks = require("ahooks");
let react_dom = require("react-dom");
react_dom = require_runtime.__toESM(react_dom);
require("./index.less");
//#region src/plus/pisellReservation/components/bookingChangeModal/index.tsx
const CLOSE_ANIMATION_MS = 180;
const HOUR_SLOT_EPS = .001;
let activeInstance = null;
function initBookingChangeLocales(locale = "en") {
	_pisell_utils.locales.init(require_locales.default, locale || "en");
}
initBookingChangeLocales();
function getText(key) {
	return _pisell_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;
	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);
}
const BookingChangeModalRenderer = ({ options, onResolve, onReject }) => {
	var _context$engine, _context$appHelper, _ref, _options$firstTimelin, _options$endTimelineE, _availableHours$find, _availableHours$find2;
	const context = require_useEngineContext.default();
	initBookingChangeLocales((context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 || (_context$engine = _context$engine.props) === null || _context$engine === void 0 ? void 0 : _context$engine.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, react.useRef)(null);
	const closedRef = (0, react.useRef)(false);
	const timerRef = (0, react.useRef)(null);
	const [visible, setVisible] = (0, react.useState)(false);
	const [submitLoading, setSubmitLoading] = (0, react.useState)(false);
	const [submitError, setSubmitError] = (0, react.useState)("");
	const [draft, setDraft] = (0, react.useState)({
		targetCourtId: options.targetCourtId,
		targetDate: options.targetDate,
		targetHour: options.targetHour
	});
	const requestClient = context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 || (_context$appHelper = _context$appHelper.utils) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.request;
	/** Per-resource selected courtIds, indexed to match currentEventResources */
	const [resourceCourtIds, setResourceCourtIds] = (0, react.useState)([]);
	const orderId = (0, react.useMemo)(() => require_utils.getOrderId(item), [item]);
	const itemResources = (0, react.useMemo)(() => require_utils.getItemResourceRecords(item), [item]);
	(0, react.useEffect)(() => {
		if (requestClient) require_index.request.setRequest(requestClient);
	}, [requestClient]);
	const { data: orderDetail } = (0, ahooks.useRequest)(require_asyncToGenerator._asyncToGenerator(function* () {
		const response = yield require_index.request.getRequest().get(`/shop/order/appointment/${orderId}`, {});
		return require_utils.asRecord(response === null || response === void 0 ? void 0 : response.data);
	}), {
		ready: Boolean(requestClient && orderId),
		refreshDeps: [requestClient, orderId]
	});
	/**
	* Authoritative resource list for the current booking item, sourced from
	* orderDetail.bookings.list[n].event_resources (matched by listItem.id === item.raw.id).
	*/
	const currentEventResources = (0, react.useMemo)(() => {
		var _asRecord, _item$raw;
		if (!orderDetail) return [];
		const list = require_utils.asRecordList((_asRecord = require_utils.asRecord(orderDetail.bookings)) === null || _asRecord === void 0 ? void 0 : _asRecord.list);
		const itemId = String((_item$raw = item.raw) === null || _item$raw === void 0 ? void 0 : _item$raw.id);
		const matched = list.find((b) => String(b.id) === itemId);
		if (!matched) return [];
		return require_utils.asRecordList(matched.event_resources);
	}, [orderDetail, item]);
	/**
	* form_id → form_name lookup used when decorating schedule resource courts.
	* Seeded immediately from the item snapshot; upgraded with server-authoritative
	* names once orderDetail (and thus currentEventResources) has loaded.
	*/
	const resourceFormNameMap = (0, 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((require_utils.asRecord(res.metadata) || {}).form_name || "");
			if (formName) map.set(String(res.form_id), formName);
		}
		return map;
	}, [currentEventResources, itemResources]);
	/**
	* Initialize per-resource selections when the event resources first load.
	* The resource whose original relation_id matches item.courtId (the dragged resource)
	* starts with draft.targetCourtId; all others start with their own relation_id.
	*/
	(0, 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, 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, ahooks.useRequest)(require_asyncToGenerator._asyncToGenerator(function* () {
		const response = yield require_index.request.getRequest().get(`/shop/schedule/resource/list`, { date: draft.targetDate });
		return require_utils.getScheduleResourceList(response === null || response === void 0 ? void 0 : response.data).map((resource) => require_utils.buildScheduleResourceCourt(resource, resourceFormNameMap.get(String(resource.form_id)) || "")).filter(Boolean);
	}), {
		ready: Boolean(requestClient),
		refreshDeps: [requestClient, draft.targetDate]
	});
	const allCourts = (0, react.useMemo)(() => require_utils.mergeCourts([baseCourts, scheduleResourceCourts]), [baseCourts, scheduleResourceCourts]);
	const normalizedCourtMap = (0, react.useMemo)(() => new Map(allCourts.map((court) => [court.id, require_utils.normalizeCourt(court)])), [allCourts]);
	const currentCustomer = (0, react.useMemo)(() => require_utils.buildCustomer({
		orderDetail,
		selectedCustomer: initialCustomer,
		fallbackCustomerText: getText(`pisell-reservation.booking-change.fallback-customer`)
	}), [initialCustomer, orderDetail]);
	const hourSlots = (0, react.useMemo)(() => options.hourSlots && options.hourSlots.length > 0 ? options.hourSlots : require_utils.getFallbackHourSlots(), [options.hourSlots]);
	const formatHourLabel = options.formatHourLabel || require_utils.defaultFormatHourLabel;
	const isBusinessHour = options.isBusinessHour || (() => true);
	const availableHours = (0, react.useMemo)(() => {
		const filtered = hourSlots.filter((hour) => isBusinessHour(hour));
		return filtered.length > 0 ? filtered : hourSlots;
	}, [hourSlots, isBusinessHour]);
	const hourStep = (0, react.useMemo)(() => require_utils.getHourStep(hourSlots), [hourSlots]);
	const firstTimelineHour = (_ref = (_options$firstTimelin = options.firstTimelineHour) !== null && _options$firstTimelin !== void 0 ? _options$firstTimelin : Math.min(...hourSlots)) !== null && _ref !== void 0 ? _ref : 0;
	const endTimelineExclusive = (_options$endTimelineE = options.endTimelineExclusive) !== null && _options$endTimelineE !== void 0 ? _options$endTimelineE : Math.max(...hourSlots) + hourStep;
	/** 同一套「打开」参数只对齐一次，避免与用户在下拉里改时间打架 */
	const slotAlignOpenKeyRef = (0, react.useRef)(null);
	(0, 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 = require_utils.alignBookingDraftToSlots(options.targetHour, durHours, availableHours);
		slotAlignOpenKeyRef.current = openKey;
		if (Math.abs(aligned - options.targetHour) > HOUR_SLOT_EPS) setDraft((prev) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, 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;
	/** 受控 select 的 option.value 必须落在 hourSlots 上；接口/日历带来的浮点终点若不在栅格上会匹配失败 */
	const nextStartHourForSelect = (_availableHours$find = availableHours.find((h) => Math.abs(h - nextStartHour) < HOUR_SLOT_EPS)) !== null && _availableHours$find !== void 0 ? _availableHours$find : require_utils.nearestHourInSlots(nextStartHour, availableHours);
	const nextEndHourForSelect = (_availableHours$find2 = availableHours.find((h) => Math.abs(h - nextEndHour) < HOUR_SLOT_EPS)) !== null && _availableHours$find2 !== void 0 ? _availableHours$find2 : require_utils.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));
	/**
	* Once event_resources are loaded, anyResourceSelectionChanged is the authoritative
	* source of truth for resource changes.  Before that (loading period), fall back to
	* the coarser court-level comparison so the compare card still shows correctly when
	* the user dragged to a different court.
	*/
	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, 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 = function() {
		var _ref2 = require_asyncToGenerator._asyncToGenerator(function* () {
			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: require_utils.buildSubmitPayload({
					item,
					draft,
					duration,
					nextEndHour,
					currentEventResources,
					resourceCourtIds,
					resourceCourtMap: normalizedCourtMap,
					orderDetail
				})
			};
			if (!options.onSubmit) {
				finishClose("resolve", resultBase);
				return;
			}
			setSubmitLoading(true);
			try {
				const submitResult = yield options.onSubmit(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, resultBase), {}, { options }));
				finishClose("resolve", require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, resultBase), {}, { submitResult }));
			} catch (error) {
				setSubmitError((error === null || error === void 0 ? void 0 : error.message) || options.submitErrorMessage || getText(`pisell-reservation.booking-change.submit-failed`));
			} finally {
				setSubmitLoading(false);
			}
		});
		return function handleConfirm() {
			return _ref2.apply(this, arguments);
		};
	}();
	return /* @__PURE__ */ 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__ */ react.default.createElement("div", {
		ref: panelRef,
		className: "pisell-booking-change-modal__panel",
		onMouseDown: (event) => event.stopPropagation()
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__title" }, title), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__description" }, description), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__body" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__card" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__customer" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__customer-info" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__section-label" }, getText(`pisell-reservation.booking-change.customer`)), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__customer-name" }, currentCustomer.name), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__customer-meta" }, currentCustomer.phone || getText(`pisell-reservation.booking-change.no-phone`)), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__customer-meta" }, currentCustomer.email || getText(`pisell-reservation.booking-change.no-email`)), currentCustomer.memberId && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__customer-meta" }, currentCustomer.memberId)))), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__grid" }, /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-booking-change-modal__field",
		style: { gridColumn: "1 / -1" }
	}, /* @__PURE__ */ react.default.createElement("label", { className: "pisell-booking-change-modal__field-label" }, getText(`pisell-reservation.booking-change.new-date`)), /* @__PURE__ */ react.default.createElement("input", {
		type: "date",
		value: draft.targetDate,
		onChange: (event) => setDraft((prev) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, prev), {}, { targetDate: event.target.value })),
		className: "pisell-booking-change-modal__control"
	}))), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__grid" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__field" }, /* @__PURE__ */ react.default.createElement("label", { className: "pisell-booking-change-modal__field-label" }, getText(`pisell-reservation.booking-change.new-start-time`)), /* @__PURE__ */ react.default.createElement("select", {
		value: nextStartHourForSelect,
		onChange: (event) => setDraft((prev) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, 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__ */ react.default.createElement("option", {
			key: hour,
			value: hour,
			disabled
		}, disabled ? formatText(`pisell-reservation.booking-change.unavailable-time`, { time: formatHourLabel(hour) }) : formatHourLabel(hour));
	}))), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__field" }, /* @__PURE__ */ react.default.createElement("label", { className: "pisell-booking-change-modal__field-label" }, getText(`pisell-reservation.booking-change.new-end-time`)), /* @__PURE__ */ react.default.createElement("select", {
		value: nextEndHourForSelect,
		onChange: (event) => {
			const targetEndHour = Number(event.target.value);
			setDraft((prev) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, 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__ */ 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__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__grid" }, currentEventResources.map((resource, index) => {
		var _resourceCourtIds$ind;
		const resourceMeta = require_utils.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__ */ react.default.createElement("div", {
			key: index,
			className: "pisell-booking-change-modal__field"
		}, /* @__PURE__ */ react.default.createElement("label", { className: "pisell-booking-change-modal__field-label" }, formName), /* @__PURE__ */ react.default.createElement("select", {
			value: (_resourceCourtIds$ind = resourceCourtIds[index]) !== null && _resourceCourtIds$ind !== void 0 ? _resourceCourtIds$ind : 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__ */ react.default.createElement("option", { value: originalId }, originalName), courtOptions.map((court) => /* @__PURE__ */ react.default.createElement("option", {
			key: court.id,
			value: court.id
		}, court.name))));
	})), changed && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__card" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__section-label" }, getText(`pisell-reservation.booking-change.previous-booking-info`)), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__compare-grid" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__compare-card" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__compare-title" }, getText(`pisell-reservation.booking-change.original`)), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__compare-value" }, originalDate), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__compare-value" }, originalStart, " - ", originalEnd), currentEventResources.length > 0 && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__resource-list" }, currentEventResources.map((res, i) => /* @__PURE__ */ react.default.createElement("div", {
		key: i,
		className: "pisell-booking-change-modal__resource-item"
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__resource-name" }, String((require_utils.asRecord(res.metadata) || {}).resource_name || res.relation_id)))))), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__compare-card is-highlighted" }, /* @__PURE__ */ 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__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__compare-value" }, draft.targetDate), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__compare-value" }, formatHourLabel(nextStartHour), " - ", formatHourLabel(nextEndHour)), currentEventResources.length > 0 && /* @__PURE__ */ 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((require_utils.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__ */ react.default.createElement("div", {
			key: i,
			className: "pisell-booking-change-modal__resource-item"
		}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__resource-name" }, name));
	})))))), conflict && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__error" }, getText(`pisell-reservation.booking-change.conflict`)), !conflict && submitError && /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__error" }, submitError), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-booking-change-modal__footer" }, /* @__PURE__ */ react.default.createElement("button", {
		type: "button",
		onClick: () => handleCancel("cancel"),
		disabled: submitLoading,
		className: "pisell-booking-change-modal__ghost-button"
	}, cancelText), /* @__PURE__ */ 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))));
};
/**
* Open the booking change modal as a Promise-based singleton.
*/
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);
		};
		react_dom.default.render(/* @__PURE__ */ react.default.createElement(BookingChangeModalRenderer, {
			options,
			onResolve: handleResolve,
			onReject: handleReject
		}), container);
	});
}
function close(reason) {
	closeActiveInstance(reason || { type: "programmatic-close" });
}
const bookingChangeModal = {
	open,
	close
};
//#endregion
exports.default = bookingChangeModal;
