function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
import { Segmented } from 'antd';
// @ts-ignore
import { locales } from '@pisell/utils';
import useEngineContext from "../../hooks/useEngineContext";
import { request, setOsQueryWebPos } from "../../utils";
import { withResponsive } from "../../responsive";
import SaleDetail from "../saleDetail";
import GlobalSearchFind from "./components/GlobalSearchFind";
import { ALL_TAB_KEY } from "./types";
import { useProviderSearch, useResizablePane } from "./hooks";
import GroupedResults from "./components/GroupedResults";
import SingleProviderResults from "./components/SingleProviderResults";
import ScopeBar from "./components/ScopeBar";
import "./components/ScopeBar.less";
import { getLocaleLabel } from "./utils/getLocaleLabel";
import { getGlobalSearchText, normalizeGlobalSearchLocale } from "./utils/i18nText";
import localeTexts from "./locales";
import "./PisellGlobalSearch.less";

/** 选中、要内联（桌面右栏）/抽屉（手机）展示详情的记录 */

/**
 * PisellGlobalSearch 全局搜索（聚合编排层）
 *
 * - 以 PisellLookup 为壳，复用其触发器 / 容器 / 历史 / 联想 能力；
 * - 通过 providers 注册各业务搜索能力，PisellGlobalSearch 不感知业务字段；
 * - All 模式分组展示，单 Tab 模式聚焦展示；
 * - 取消请求、错误兜底、空态分别处理。
 */
var PisellGlobalSearchInner = /*#__PURE__*/forwardRef(function (props, ref) {
  var _locales$getLocale, _ctx$appHelper, _enabledProviders$0$k, _enabledProviders$, _enabledProviders$0$k2, _enabledProviders$2;
  var providers = props.providers,
    permissionContext = props.permissionContext,
    activeTabProp = props.activeTab,
    onActiveTabChange = props.onActiveTabChange,
    _props$allModePageSiz = props.allModePageSize,
    allModePageSize = _props$allModePageSiz === void 0 ? 5 : _props$allModePageSiz,
    _props$singleModePage = props.singleModePageSize,
    singleModePageSize = _props$singleModePage === void 0 ? 20 : _props$singleModePage,
    allTabLabel = props.allTabLabel,
    navigate = props.navigate,
    _props$defaultMode = props.defaultMode,
    defaultMode = _props$defaultMode === void 0 ? 'business' : _props$defaultMode,
    modeProp = props.mode,
    onModeChange = props.onModeChange,
    _props$showModeSwitch = props.showModeSwitch,
    showModeSwitch = _props$showModeSwitch === void 0 ? true : _props$showModeSwitch,
    modeOptions = props.modeOptions,
    _props$submitMode = props.submitMode,
    submitMode = _props$submitMode === void 0 ? 'submit' : _props$submitMode,
    lookupProps = props.lookupProps,
    variant = props.variant,
    className = props.className,
    style = props.style;

  // 初始化多语言（参考 ComprehensiveSearch / PisellTopology 的写法）
  var ctx = useEngineContext();
  var locale = normalizeGlobalSearchLocale((_locales$getLocale = locales.getLocale) === null || _locales$getLocale === void 0 ? void 0 : _locales$getLocale.call(locales));
  locales.init(localeTexts, locale);

  // 注入 engine 的 request，供真实 Provider（salesProvider → ES 接口）使用。
  // 同步注入 isWebPos：ES 搜索的退订仅在 WebPOS 才真正发请求（见 unsubscribeOsQuery）。
  if (ctx !== null && ctx !== void 0 && (_ctx$appHelper = ctx.appHelper) !== null && _ctx$appHelper !== void 0 && (_ctx$appHelper = _ctx$appHelper.utils) !== null && _ctx$appHelper !== void 0 && _ctx$appHelper.request) {
    request.setRequest(ctx.appHelper.utils.request);
    setOsQueryWebPos(ctx.appHelper.utils.isWebPos);
  }

  // 计算 enabled providers
  //
  // 防御性处理：lowcode 画布拖入时、或调用方未传 providers 时，
  // providers 可能是 undefined / null / 非数组；这里统一回退成空数组，
  // 避免画布崩溃，由下面的"无 provider"占位文案兜底提示。
  var enabledProviders = useMemo(function () {
    var safeProviders = Array.isArray(providers) ? providers : [];
    var list = safeProviders.filter(function (p) {
      return p && p.enabledWhen ? p.enabledWhen(permissionContext !== null && permissionContext !== void 0 ? permissionContext : {}) : Boolean(p);
    });
    return _toConsumableArray(list).sort(function (a, b) {
      var _a$order, _b$order;
      return ((_a$order = a.order) !== null && _a$order !== void 0 ? _a$order : Number.MAX_SAFE_INTEGER) - ((_b$order = b.order) !== null && _b$order !== void 0 ? _b$order : Number.MAX_SAFE_INTEGER);
    });
  }, [providers, permissionContext]);

  /**
   * keyword: 真正参与搜索调度的关键词（喂给 useProviderSearch）；
   * inputValue: PisellLookup input 的展示值（受控）。
   *
   * - `submitMode='instant'`：onChange 同时更新二者 → 输入即搜（旧行为）；
   * - `submitMode='submit'`：onChange 只更新 inputValue，
   *   只有 onSearch（回车 / 搜索按钮）才把 inputValue 提交到 keyword 触发搜索。
   */
  var _useState = useState(''),
    _useState2 = _slicedToArray(_useState, 2),
    keyword = _useState2[0],
    _setKeyword = _useState2[1];
  var _useState3 = useState(''),
    _useState4 = _slicedToArray(_useState3, 2),
    inputValue = _useState4[0],
    setInputValue = _useState4[1];

  // ---------- 选中详情（仅桌面/大屏：行点击 → 右侧内联详情） ----------
  // 大屏（pos / desktop）：右侧可拖拽栏内联展示详情；
  // 中小屏（手机 / iPad）：不接管行点击，交还给表格自身的订单详情抽屉
  //   （useOrderPerspective 未拿到 onOpenDetail 时走引擎 action pisell1.handleOpenSaleDetail），
  //   不再自绘抽屉。
  var useDrawerDetail = variant === 'phone' || variant === 'smallTablet' || variant === 'tablet';
  var _useState5 = useState(null),
    _useState6 = _slicedToArray(_useState5, 2),
    selectedDetail = _useState6[0],
    setSelectedDetail = _useState6[1];
  var handleOpenDetail = useCallback(function (_ref) {
    var providerKey = _ref.providerKey,
      id = _ref.id;
    if (id === undefined || id === null || id === '') return;
    setSelectedDetail({
      providerKey: providerKey,
      id: id
    });
  }, []);
  // 仅大屏接管行点击做右侧内联详情；中小屏传 undefined，让表格走原生订单详情抽屉。
  var effectiveOpenDetail = useDrawerDetail ? undefined : handleOpenDetail;
  // 关键词变化（重新搜索）时清掉旧详情
  useEffect(function () {
    setSelectedDetail(null);
  }, [keyword]);
  // 左结果 / 右详情两栏可拖拽宽度
  var _useResizablePane = useResizablePane({
      initialRatio: 0.38
    }),
    rightWidth = _useResizablePane.rightWidth,
    contentRef = _useResizablePane.containerRef,
    onResizerMouseDown = _useResizablePane.onResizerMouseDown,
    resizing = _useResizablePane.resizing;

  /**
   * 是否展示 All 范围。
   *
   * 始终展示（只要有 provider）—— `showAllTab` prop 已 deprecated 被忽略，
   * 把搜索范围（All / Orders ...）永远露出来，告诉用户当前作用域。
   * 只有完全没有 provider（=0）时才隐藏（避免一个孤零零的 All 点了什么都没有）。
   */
  var effectiveShowAllTab = enabledProviders.length >= 1;

  // activeTab（受控/非受控）
  var _useState7 = useState(
    // 初始 Tab 固定为 All（只要展示 All）；不再受外部 defaultActiveTab 控制，
    // 避免 lowcode schema 里固化的旧值（如 order）覆盖默认。受控 activeTab 仍优先生效。
    effectiveShowAllTab ? ALL_TAB_KEY : (_enabledProviders$0$k = (_enabledProviders$ = enabledProviders[0]) === null || _enabledProviders$ === void 0 ? void 0 : _enabledProviders$.key) !== null && _enabledProviders$0$k !== void 0 ? _enabledProviders$0$k : ALL_TAB_KEY),
    _useState8 = _slicedToArray(_useState7, 2),
    innerActiveTab = _useState8[0],
    setInnerActiveTab = _useState8[1];
  // effectiveShowAllTab=false 但 innerActiveTab 还是 ALL_TAB_KEY 时回落到第一个 provider，
  // 避免 single tab 模式下 activeTab 落不到任何 provider
  var resolvedInnerActiveTab = !effectiveShowAllTab && innerActiveTab === ALL_TAB_KEY ? (_enabledProviders$0$k2 = (_enabledProviders$2 = enabledProviders[0]) === null || _enabledProviders$2 === void 0 ? void 0 : _enabledProviders$2.key) !== null && _enabledProviders$0$k2 !== void 0 ? _enabledProviders$0$k2 : ALL_TAB_KEY : innerActiveTab;
  var activeTab = activeTabProp !== null && activeTabProp !== void 0 ? activeTabProp : resolvedInnerActiveTab;
  var handleActiveTabChange = useCallback(function (next) {
    if (activeTabProp === undefined) setInnerActiveTab(next);
    onActiveTabChange === null || onActiveTabChange === void 0 || onActiveTabChange(next);
  }, [activeTabProp, onActiveTabChange]);

  // mode（受控/非受控）：仅作为参数透传给 provider.search，不做任何额外逻辑
  var _useState9 = useState(defaultMode),
    _useState10 = _slicedToArray(_useState9, 2),
    innerMode = _useState10[0],
    setInnerMode = _useState10[1];
  var mode = modeProp !== null && modeProp !== void 0 ? modeProp : innerMode;
  var handleModeChange = useCallback(function (next) {
    if (modeProp === undefined) setInnerMode(next);
    onModeChange === null || onModeChange === void 0 || onModeChange(next);
  }, [modeProp, onModeChange]);

  // 搜索调度
  var _useProviderSearch = useProviderSearch({
      keyword: keyword,
      activeTab: activeTab,
      providers: enabledProviders,
      allModePageSize: allModePageSize,
      singleModePageSize: singleModePageSize,
      mode: mode
    }),
    stateMap = _useProviderSearch.stateMap,
    refresh = _useProviderSearch.refresh,
    reportProviderTotal = _useProviderSearch.reportProviderTotal;

  // 透传给 PisellLookup 的 ref
  var lookupRef = useRef(null);
  useImperativeHandle(ref, function () {
    return {
      open: function open() {
        var _lookupRef$current;
        return (_lookupRef$current = lookupRef.current) === null || _lookupRef$current === void 0 ? void 0 : _lookupRef$current.open();
      },
      close: function close() {
        var _lookupRef$current2;
        return (_lookupRef$current2 = lookupRef.current) === null || _lookupRef$current2 === void 0 ? void 0 : _lookupRef$current2.close();
      },
      setKeyword: function setKeyword(k) {
        var _lookupRef$current3;
        (_lookupRef$current3 = lookupRef.current) === null || _lookupRef$current3 === void 0 || _lookupRef$current3.setKeyword(k);
        setInputValue(k);
        _setKeyword(k);
      },
      getKeyword: function getKeyword() {
        return keyword;
      },
      setActiveTab: handleActiveTabChange,
      setMode: handleModeChange,
      getMode: function getMode() {
        return mode;
      },
      refresh: refresh
    };
  }, [keyword, handleActiveTabChange, handleModeChange, mode, refresh]);

  /**
   * 搜索范围选项（共享 ScopeBar 用）。
   *
   * 形态：`{ value, label }`，label 含可选 icon；value 即 provider.key（或 __all__）。
   * className 与 FullPage 共用 `pisell-global-search-scope-bar__option`，保证视觉一致。
   */
  var scopeOptions = useMemo(function () {
    var items = enabledProviders.map(function (p) {
      return {
        value: p.key,
        label: /*#__PURE__*/React.createElement("span", {
          className: "pisell-global-search-scope-bar__option"
        }, p.icon, getLocaleLabel(p.label, locale))
      };
    });
    if (effectiveShowAllTab) {
      items.unshift({
        value: ALL_TAB_KEY,
        label: /*#__PURE__*/React.createElement("span", {
          className: "pisell-global-search-scope-bar__option"
        }, allTabLabel ? getLocaleLabel(allTabLabel, locale) : getGlobalSearchText('pisell-global-search.tab.all'))
      });
    }
    return items;
  }, [enabledProviders, effectiveShowAllTab, allTabLabel, locale]);

  // 模式 Segmented 选项（业务 / 管理）
  var modeSegmentOptions = useMemo(function () {
    var adminLabel = modeOptions !== null && modeOptions !== void 0 && modeOptions.admin ? getLocaleLabel(modeOptions.admin, locale) : getGlobalSearchText('pisell-global-search.mode.admin');
    var businessLabel = modeOptions !== null && modeOptions !== void 0 && modeOptions.business ? getLocaleLabel(modeOptions.business, locale) : getGlobalSearchText('pisell-global-search.mode.business');
    return [{
      label: businessLabel,
      value: 'business'
    }, {
      label: adminLabel,
      value: 'admin'
    }];
  }, [modeOptions, locale]);

  /**
   * Mode Segmented 控件本体，渲染两次复用同一个节点：
   * - 当 Tabs 存在时，作为 Tabs 的 tabBarExtraContent.right（贴在 tabs 行右侧）；
   * - 当 Tabs 不存在时，作为独立的极简一行（无背景、无 label、与 body 对齐）。
   */
  var modeSwitchNode = showModeSwitch ? /*#__PURE__*/React.createElement(Segmented, {
    className: "pisell-global-search__mode-segmented",
    options: modeSegmentOptions,
    value: mode,
    onChange: function onChange(v) {
      return handleModeChange(v);
    }
  }) : null;

  // 结果渲染
  var renderResults = useCallback(function (currentKeyword, onClose) {
    var close = onClose !== null && onClose !== void 0 ? onClose : function () {
      var _lookupRef$current4;
      return (_lookupRef$current4 = lookupRef.current) === null || _lookupRef$current4 === void 0 ? void 0 : _lookupRef$current4.close();
    };
    var isAll = activeTab === ALL_TAB_KEY;

    /**
     * 详情内容（目前仅 order 域 → SaleDetail 内联）。
     * 用独立 osKey 与宿主抽屉隔离；未选中显示占位。
     */
    var detailContent = !selectedDetail ? /*#__PURE__*/React.createElement("div", {
      className: "pisell-global-search__detail-idle"
    }, getGlobalSearchText('pisell-global-search.detail.idle')) : selectedDetail.providerKey === 'order' ? /*#__PURE__*/React.createElement(SaleDetail, {
      renderType: "current"
      // 显式对齐宿主表格抽屉内层：固定模板 A + 平板变体（覆盖 withResponsive 注入的 desktop）。
      ,
      tmpl: "A",
      variant: "tablet",
      osProps: {
        osKey: 'global-search-order-detail',
        orderId: Number(selectedDetail.id),
        autoBootstrap: true,
        destroyOnUnmount: true
      }
    }) : null;
    // 右栏内联详情仅在「桌面/大屏 + 管理模式（表格）」生效；
    // 中小屏（手机 / iPad）点行走表格自身的订单详情抽屉；业务模式内容区直接是详情
    var showDetailAside = !useDrawerDetail && !!currentKeyword && mode === 'admin';

    // 无 providers 兜底（lowcode 画布拖入后未注入 / 调用方忘传）
    if (enabledProviders.length === 0) {
      return /*#__PURE__*/React.createElement("div", {
        className: "pisell-global-search ".concat(className !== null && className !== void 0 ? className : '').trim(),
        style: style
      }, /*#__PURE__*/React.createElement("div", {
        className: "pisell-global-search__empty"
      }, /*#__PURE__*/React.createElement("div", {
        style: {
          marginBottom: 8,
          fontWeight: 600
        }
      }, getGlobalSearchText('pisell-global-search.providers-missing.title')), /*#__PURE__*/React.createElement("div", {
        style: {
          fontSize: 12,
          lineHeight: 1.6
        }
      }, getGlobalSearchText('pisell-global-search.providers-missing.description'), /*#__PURE__*/React.createElement("br", null), /*#__PURE__*/React.createElement("code", {
        style: {
          background: '#f3f4f6',
          padding: '0 4px'
        }
      }, "<PisellGlobalSearch providers={allProviders} />"))));
    }
    return /*#__PURE__*/React.createElement("div", {
      className: "pisell-global-search pisell-global-search--".concat(variant || 'desktop', " ").concat(className !== null && className !== void 0 ? className : '').trim(),
      style: style
    }, (scopeOptions.length >= 1 || modeSwitchNode) && /*#__PURE__*/React.createElement("div", {
      className: "pisell-global-search__scope-wrap"
    }, /*#__PURE__*/React.createElement(ScopeBar, {
      options: scopeOptions,
      value: activeTab,
      onChange: function onChange(v) {
        return handleActiveTabChange(v);
      },
      extra: modeSwitchNode
    })), /*#__PURE__*/React.createElement("div", {
      className: "pisell-global-search__content".concat(resizing ? ' pisell-global-search__content--resizing' : ''),
      ref: contentRef
    }, /*#__PURE__*/React.createElement("div", {
      className: "pisell-global-search__body"
    }, isAll ? /*#__PURE__*/React.createElement(GroupedResults, {
      providers: enabledProviders,
      stateMap: stateMap,
      keyword: currentKeyword,
      mode: mode,
      locale: locale,
      onJumpTab: handleActiveTabChange,
      onClose: close,
      navigate: navigate,
      onOpenDetail: effectiveOpenDetail,
      onReportTotal: reportProviderTotal
    }) : function (_stateMap$provider$ke) {
      var provider = enabledProviders.find(function (p) {
        return p.key === activeTab;
      });
      if (!provider) return null;
      var state = (_stateMap$provider$ke = stateMap[provider.key]) !== null && _stateMap$provider$ke !== void 0 ? _stateMap$provider$ke : {
        loading: false,
        list: [],
        total: 0
      };
      return /*#__PURE__*/React.createElement(SingleProviderResults, {
        provider: provider,
        state: state,
        keyword: currentKeyword,
        mode: mode,
        onClose: close,
        navigate: navigate,
        onOpenDetail: effectiveOpenDetail,
        onReportTotal: reportProviderTotal
      });
    }()), showDetailAside && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
      className: "pisell-global-search__resizer",
      onMouseDown: onResizerMouseDown,
      role: "separator",
      "aria-orientation": "vertical"
    }), /*#__PURE__*/React.createElement("aside", {
      className: "pisell-global-search__detail",
      style: {
        flex: "0 0 ".concat(rightWidth),
        width: rightWidth
      }
    }, detailContent))));
  }, [activeTab, className, style, scopeOptions, enabledProviders, stateMap, locale, handleActiveTabChange, navigate, reportProviderTotal, modeSwitchNode, mode, variant, useDrawerDetail, selectedDetail, effectiveOpenDetail, rightWidth, contentRef, onResizerMouseDown, resizing]);

  // 给 GlobalSearchFind / PisellFind 的默认配置；调用方可通过 lookupProps 覆盖
  // 注：当前订单结果使用 Sales Management 表格展示，默认 modalWidth 拉宽到 1080
  var finalLookupProps = useMemo(function () {
    return _objectSpread({
      triggerType: 'input',
      displayType: 'modal',
      placeholder: getGlobalSearchText('pisell-global-search.placeholder'),
      confirmButtonText: getGlobalSearchText('pisell-global-search.search'),
      modalWidth: 1080,
      showHistory: true,
      historyKey: 'pisell_global_search_history'
    }, lookupProps);
  }, [lookupProps]);

  // submitMode 决策（与 FullPage 统一为提交式）：
  // - submit（默认）：searchMode='confirm'，onChange 只更新 inputValue，
  //   仅回车 / 点搜索按钮（onSearch）才提交 keyword；
  // - instant：searchMode='realtime'，onChange 同时更新 inputValue + keyword（输入即搜）。
  var searchMode = submitMode === 'instant' ? 'realtime' : 'confirm';
  var handleLookupChange = useCallback(function (next) {
    setInputValue(next);
    if (submitMode === 'instant') _setKeyword(next);
  }, [submitMode]);
  var handleLookupSearch = useCallback(function (next) {
    setInputValue(next);
    _setKeyword(next);
  }, []);
  return /*#__PURE__*/React.createElement(GlobalSearchFind, _extends({
    ref: lookupRef
    // 手机端默认小号输入框（放在 finalLookupProps 之前，调用方仍可通过 lookupProps.size 覆盖）
    ,
    size: variant === 'phone' ? 'small' : undefined
  }, finalLookupProps, {
    searchMode: searchMode,
    value: inputValue,
    onChange: handleLookupChange,
    onSearch: handleLookupSearch,
    resultRender: renderResults
  }));
});
PisellGlobalSearchInner.displayName = 'PisellGlobalSearch';

/**
 * 对外导出：用 withResponsive 包裹，注入 `variant`，
 * 用于「桌面右栏详情 / 手机抽屉详情」分支与根节点 variant class。
 * （PisellGlobalSearchInner 本身是 forwardRef，ref 会被透传给内部 imperative handle。）
 */
export var PisellGlobalSearch = withResponsive(PisellGlobalSearchInner);
export default PisellGlobalSearch;