import { createContext, useContext } from 'react';
import { createInstanceHostBridge } from "../hosts/createInstanceHostBridge";
import { createHolderConfirmBridge } from "../holderConfirm/createHolderConfirmBridge";
import { createGiftSelectBridge } from "../giftSelect/createGiftSelectBridge";

/** 单个 SalesSdkProvider 实例持有的全部 Host bridge */

/**
 * 为 SalesSdkProvider 创建一套实例级 Host bridge。
 *
 * @example
 * const bridgesRef = useRef(createSalesSdkHostBridges());
 */
export function createSalesSdkHostBridges() {
  return {
    normalProductDetail: createInstanceHostBridge(),
    bookingEdit: createInstanceHostBridge(),
    multiDay: createInstanceHostBridge(),
    holder: createInstanceHostBridge(),
    holderConfirm: createHolderConfirmBridge(),
    giftSelect: createGiftSelectBridge()
  };
}
export var SalesSdkHostBridgesContext = /*#__PURE__*/createContext(null);
SalesSdkHostBridgesContext.displayName = 'SalesSdkHostBridgesContext';

/**
 * 读取当前 SalesSdkProvider 实例的 Host bridge（须在 Provider 子树内）。
 *
 * @example
 * const bridges = useSalesSdkHostBridges();
 * await bridges.normalProductDetail.request({ mode: 'edit', cacheItem });
 */
export function useSalesSdkHostBridges() {
  var bridges = useContext(SalesSdkHostBridgesContext);
  if (!bridges) {
    throw new Error('[SalesSdk] useSalesSdkHostBridges 须在 SalesSdkProvider 子树内使用');
  }
  return bridges;
}