import React, { useSyncExternalStore } from 'react';
import { useMemoizedFn } from 'ahooks';
import { useSalesSdkHostBridges } from "../context/SalesSdkHostBridgesContext";
import { GiftSelectModal } from "./GiftSelectModal";

/**
 * 挂载在 SalesSdkProvider 子树内，承接 GiftSelect Host 的弹窗渲染。
 * 同一 Provider 实例只响应自身 bridge，避免多实例冲突。
 */
export var GiftSelectHostRenderer = function GiftSelectHostRenderer() {
  var _pending$payload;
  var bridges = useSalesSdkHostBridges();
  var bridge = bridges.giftSelect;
  var pending = useSyncExternalStore(bridge.subscribe, bridge.getSnapshot, function () {
    return null;
  });
  var handleConfirm = useMemoizedFn(function (choices) {
    bridge.complete(choices);
  });
  var handleCancel = useMemoizedFn(function () {
    bridge.complete(null);
  });
  return /*#__PURE__*/React.createElement(GiftSelectModal, {
    context: (_pending$payload = pending === null || pending === void 0 ? void 0 : pending.payload) !== null && _pending$payload !== void 0 ? _pending$payload : null,
    onConfirm: handleConfirm,
    onCancel: handleCancel
  });
};
export default GiftSelectHostRenderer;