import { useSalesSdk } from "../../hooks/useSalesSdk.js";
import { useSalesSdkCustomer } from "../../hooks/useSalesSdkCustomer.js";
import dayjs from "dayjs";
import { useEffect } from "react";
//#region src/plus/salesSdk/demo/components/DemoHostRuntimeBridge.tsx
/**
* 将 Provider 子树内的客户 / 日期同步到 runtimeRef，供 legacy openProductDetail Host 读取。
*
* 必须在 SalesSdkProvider 内部挂载。
*/
const DemoHostRuntimeBridge = ({ runtimeRef }) => {
	var _customer$selected2;
	const sales = useSalesSdk();
	const customer = useSalesSdkCustomer();
	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 ? dayjs(rawDate).isValid() ? dayjs(rawDate).format("YYYY-MM-DD") : dayjs().format("YYYY-MM-DD") : dayjs().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
export { DemoHostRuntimeBridge };
