const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_useSalesSdk = require("../../hooks/useSalesSdk.js");
const require_useSalesSdkCustomer = require("../../hooks/useSalesSdkCustomer.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
let react = require("react");
//#region src/plus/salesSdk/demo/components/DemoHostRuntimeBridge.tsx
/**
* 将 Provider 子树内的客户 / 日期同步到 runtimeRef，供 legacy openProductDetail Host 读取。
*
* 必须在 SalesSdkProvider 内部挂载。
*/
const DemoHostRuntimeBridge = ({ runtimeRef }) => {
	var _customer$selected2;
	const sales = require_useSalesSdk.useSalesSdk();
	const customer = require_useSalesSdkCustomer.useSalesSdkCustomer();
	(0, react.useEffect)(() => {
		var _sales$bookingTicket, _sales$bookingTicket$, _customer$selected;
		const bookingCtx = (_sales$bookingTicket = sales.bookingTicket) === null || _sales$bookingTicket === void 0 || (_sales$bookingTicket = _sales$bookingTicket.store) === null || _sales$bookingTicket === void 0 || (_sales$bookingTicket = _sales$bookingTicket.bookingContext) === null || _sales$bookingTicket === void 0 || (_sales$bookingTicket$ = _sales$bookingTicket.getState) === null || _sales$bookingTicket$ === void 0 ? void 0 : _sales$bookingTicket$.call(_sales$bookingTicket);
		const rawDate = bookingCtx === null || bookingCtx === void 0 ? void 0 : bookingCtx.date;
		const dateFromOs = rawDate ? (0, dayjs.default)(rawDate).isValid() ? (0, dayjs.default)(rawDate).format("YYYY-MM-DD") : (0, dayjs.default)().format("YYYY-MM-DD") : (0, dayjs.default)().format("YYYY-MM-DD");
		runtimeRef.current = {
			customerId: (_customer$selected = customer.selected) === null || _customer$selected === void 0 ? void 0 : _customer$selected.id,
			date: dateFromOs
		};
	}, [
		sales.bookingTicket,
		(_customer$selected2 = customer.selected) === null || _customer$selected2 === void 0 ? void 0 : _customer$selected2.id,
		runtimeRef
	]);
	return null;
};
//#endregion
exports.DemoHostRuntimeBridge = DemoHostRuntimeBridge;
