import { SalesSdkMultiDayTimeSelectModal } from "../components/SalesSdkMultiDayTimeSelectModal.js";
import { completeMultiDayHost, getMultiDayHostPending, subscribeMultiDayHost } from "../addProductFlow/multiDayHostController.js";
import dayjs from "dayjs";
import React, { useSyncExternalStore } from "react";
import { locales } from "@pisell/utils";
//#region src/plus/salesSdk/hosts/MultiDayHostRenderer.tsx
/**
* 承接 `openMultiDaySelect` Promise Host 的跨日弹窗渲染。
*/
const MultiDayHostRenderer = () => {
	const pending = useSyncExternalStore(subscribeMultiDayHost, getMultiDayHostPending, () => null);
	const open = !!pending;
	const payload = pending === null || pending === void 0 ? void 0 : pending.payload;
	const defaultStartDate = (payload === null || payload === void 0 ? void 0 : payload.defaultStartDate) ? dayjs(payload.defaultStartDate) : dayjs();
	if (!open) return null;
	return /* @__PURE__ */ React.createElement(SalesSdkMultiDayTimeSelectModal, {
		open,
		productName: payload === null || payload === void 0 ? void 0 : payload.productName,
		locale: locales.locale,
		defaultStartDate: defaultStartDate.isValid() ? defaultStartDate : dayjs(),
		onCancel: () => completeMultiDayHost(null),
		onConfirm: (startDate, endDate, duration) => {
			completeMultiDayHost({
				startDate: startDate.format("YYYY-MM-DD"),
				endDate: endDate.format("YYYY-MM-DD"),
				duration
			});
		}
	});
};
//#endregion
export { MultiDayHostRenderer };
