import React__default, { useContext, useState, useMemo, useRef, useEffect, useImperativeHandle } from "react";
import cs from "../_util/classNames.js";
import { Esc, Enter, Tab, ArrowUp, ArrowDown } from "../_util/keycode.js";
import Trigger from "../Trigger/index.js";
import OptGroup from "./opt-group.js";
import Option from "./option.js";
import ResizeObserver from "../_util/resizeObserver.js";
import { isArray, isFunction, isObject } from "../_util/is.js";
import getHotkeyHandler from "../_util/getHotkeyHandler.js";
import warning from "../_util/warning.js";
import SelectView from "../_class/select-view.js";
import VirtualList from "../_class/VirtualList/index.js";
import { getValidValue, flatChildren, isEmptyValue, preventDefaultEvent, isSelectOptGroup, isSelectOption } from "./utils.js";
import { ConfigContext } from "../ConfigProvider/index.js";
import useMergeValue from "../_util/hooks/useMergeValue.js";
import omit from "../_util/omit.js";
import useMergeProps from "../_util/hooks/useMergeProps.js";
import useIsFirstRender from "../_util/hooks/useIsFirstRender.js";
import useId from "../_util/hooks/useId.js";
import { jsx } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = {
      error
    };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
var __values = globalThis && globalThis.__values || function(o) {
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  if (m)
    return m.call(o);
  if (o && typeof o.length === "number")
    return {
      next: function() {
        if (o && i >= o.length)
          o = void 0;
        return {
          value: o && o[i++],
          done: !o
        };
      }
    };
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __spreadArray = globalThis && globalThis.__spreadArray || function(to, from, pack) {
  if (pack || arguments.length === 2)
    for (var i = 0, l = from.length, ar; i < l; i++) {
      if (ar || !(i in from)) {
        if (!ar)
          ar = Array.prototype.slice.call(from, 0, i);
        ar[i] = from[i];
      }
    }
  return to.concat(ar || Array.prototype.slice.call(from));
};
var THRESHOLD_TOKEN_SEPARATOR_TRIGGER = 100;
var defaultProps = {
  trigger: "click",
  bordered: true,
  filterOption: true,
  unmountOnExit: true,
  defaultActiveFirstOption: true
};
function Select(baseProps, ref) {
  var _a = useContext(ConfigContext), getPrefixCls = _a.getPrefixCls, renderEmpty = _a.renderEmpty, componentConfig = _a.componentConfig, rtl = _a.rtl;
  var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Select);
  var children = props.children, renderFormat = props.renderFormat, defaultActiveFirstOption = props.defaultActiveFirstOption, disabled = props.disabled, unmountOnExit = props.unmountOnExit, notFoundContent = props.notFoundContent, showSearch = props.showSearch, tokenSeparators = props.tokenSeparators, options = props.options, filterOption = props.filterOption, labelInValue = props.labelInValue, getPopupContainer = props.getPopupContainer, trigger = props.trigger, triggerElement = props.triggerElement, triggerProps = props.triggerProps, dropdownRender = props.dropdownRender, dropdownMenuStyle = props.dropdownMenuStyle, dropdownMenuClassName = props.dropdownMenuClassName, virtualListProps = props.virtualListProps, onChange = props.onChange, onDeselect = props.onDeselect, onClear = props.onClear, onSearch = props.onSearch, onFocus = props.onFocus, onBlur = props.onBlur, onPopupScroll = props.onPopupScroll, onVisibleChange = props.onVisibleChange, onInputValueChange = props.onInputValueChange, onPaste = props.onPaste, onKeyDown = props.onKeyDown;
  var mode = props.mode, allowCreate = props.allowCreate;
  if (mode === "tags") {
    mode = "multiple";
    allowCreate = true;
    warning(true, `[Arco Select] The 'tags' mode will be removed in the next major version, please use {mode: "multiple", allowCreate: true} instead.`);
  }
  var prefixCls = getPrefixCls("select");
  var isMultipleMode = mode === "multiple";
  var _b = __read(useState(getValidValue(props.defaultValue, isMultipleMode, labelInValue)), 2), stateValue = _b[0], setValue = _b[1];
  var value = "value" in props ? getValidValue(props.value, isMultipleMode, labelInValue) : stateValue;
  var _c = __read(useMergeValue("", {
    value: "inputValue" in props ? props.inputValue || "" : void 0
  }), 3), inputValue = _c[0], setInputValue = _c[1], stateInputValue = _c[2];
  var _d = __read(useMergeValue(false, {
    defaultValue: props.defaultPopupVisible,
    value: "popupVisible" in props ? props.popupVisible : triggerProps && "popupVisible" in triggerProps ? triggerProps.popupVisible : void 0
  }), 2), popupVisible = _d[0], setPopupVisible = _d[1];
  var _e = __read(useState(null), 2), userCreatingOption = _e[0], setUserCreatingOption = _e[1];
  var _f = __read(useState([]), 2), userCreatedOptions = _f[0], setUserCreatedOptions = _f[1];
  var _g = __read(useState(isArray(value) ? value[0] : value), 2), valueActive = _g[0], setValueActive = _g[1];
  var _h = useMemo(function() {
    return flatChildren({
      children,
      options,
      filterOption
    }, {
      prefixCls,
      inputValue,
      userCreatedOptions,
      userCreatingOption
    });
  }, [children, options, filterOption, inputValue, userCreatingOption, userCreatedOptions]), childrenList = _h.childrenList, optionInfoMap = _h.optionInfoMap, optionValueList = _h.optionValueList, optionIndexListForArrowKey = _h.optionIndexListForArrowKey, hasOptGroup = _h.hasOptGroup, hasComplexLabelInOptions = _h.hasComplexLabelInOptions;
  var refWrapper = useRef(null);
  var refTrigger = useRef(null);
  var refSelectView = useRef(null);
  var refValueMap = useRef([]);
  var refKeyboardArrowDirection = useRef(null);
  var refOnInputChangeCallbackValue = useRef(inputValue);
  var refOnInputChangeCallbackReason = useRef(null);
  var refTSLastSeparateTriggered = useRef(0);
  var refIsFirstRender = useIsFirstRender();
  var instancePopupID = useId(prefixCls + "-popup-");
  var isNoOptionSelected = isEmptyValue(value, isMultipleMode);
  var valueActiveDefault = defaultActiveFirstOption ? optionValueList[optionIndexListForArrowKey[0]] : void 0;
  var scrollIntoView = function(optionValue) {
    var _a2;
    var activeOption = optionInfoMap.get(optionValue);
    if (refWrapper.current && ((_a2 = activeOption === null || activeOption === void 0 ? void 0 : activeOption.child) === null || _a2 === void 0 ? void 0 : _a2.props)) {
      refWrapper.current.scrollTo({
        key: activeOption.child.props._key
      });
    }
  };
  var tryUpdateInputValue = function(value2, reason) {
    if (value2 !== refOnInputChangeCallbackValue.current || reason !== refOnInputChangeCallbackReason.current) {
      setInputValue(value2);
      refOnInputChangeCallbackValue.current = value2;
      refOnInputChangeCallbackReason.current = reason;
      onInputValueChange && onInputValueChange(value2, reason);
    }
  };
  var tryUpdatePopupVisible = function(value2) {
    if (popupVisible !== value2) {
      setPopupVisible(value2);
      onVisibleChange && onVisibleChange(value2);
      triggerProps && triggerProps.onVisibleChange && triggerProps.onVisibleChange(value2);
    }
  };
  useEffect(function() {
    if (isMultipleMode) {
      if (!Array.isArray(value)) {
        setValue(value === void 0 ? [] : [value]);
      }
    } else if (Array.isArray(value)) {
      setValue(value.length === 0 ? void 0 : value[0]);
    }
  }, [isMultipleMode, value]);
  useEffect(function() {
    if (popupVisible) {
      var firstValue = isArray(value) ? value[0] : value;
      var nextValueActive_1 = !isNoOptionSelected && optionInfoMap.has(firstValue) ? firstValue : valueActiveDefault;
      setValueActive(nextValueActive_1);
      setTimeout(function() {
        return scrollIntoView(nextValueActive_1);
      });
    } else if (!refIsFirstRender) {
      tryUpdateInputValue("", "optionListHide");
    }
  }, [popupVisible]);
  useEffect(function() {
    if (refKeyboardArrowDirection.current === "up" || refKeyboardArrowDirection.current === "down") {
      scrollIntoView(valueActive);
      refKeyboardArrowDirection.current = "none";
    }
  }, [valueActive]);
  useEffect(function() {
    setValueActive(valueActiveDefault);
  }, [JSON.stringify(childrenList.map(function(child) {
    var _a2;
    return (_a2 = child === null || child === void 0 ? void 0 : child.props) === null || _a2 === void 0 ? void 0 : _a2.value;
  }))]);
  useEffect(function() {
    refValueMap.current = refValueMap.current.filter(function(x) {
      return isMultipleMode ? isArray(value) && value.indexOf(x.value) > -1 : x.value === value;
    });
  }, [value, isMultipleMode]);
  useEffect(function() {
    if (allowCreate && Array.isArray(value)) {
      var newUserCreatedOptions = value.filter(function(v) {
        var _a2;
        var option = optionInfoMap.get(v) || ((_a2 = refValueMap.current.find(function(item) {
          return item.value === v;
        })) === null || _a2 === void 0 ? void 0 : _a2.option);
        return !option || option._origin === "userCreatingOption";
      });
      var validUserCreatedOptions = userCreatedOptions.filter(function(tag) {
        return value.indexOf(tag) !== -1;
      });
      var _userCreatedOptions = validUserCreatedOptions.concat(newUserCreatedOptions);
      if (_userCreatedOptions.toString() !== userCreatedOptions.toString()) {
        setUserCreatedOptions(_userCreatedOptions);
      }
    }
  }, [value]);
  useEffect(function() {
    if (allowCreate) {
      setUserCreatingOption(optionInfoMap.has(inputValue) ? null : inputValue);
    }
  }, [inputValue]);
  useEffect(function() {
    var reason = refOnInputChangeCallbackReason.current;
    if (stateInputValue === inputValue && (reason === "manual" || reason === "optionListHide")) {
      onSearch && onSearch(inputValue, reason);
    }
  }, [inputValue]);
  var getOptionInfoByValue = function(value2) {
    var option = optionInfoMap.get(value2);
    if (option) {
      var index = refValueMap.current.findIndex(function(item2) {
        return item2.value === value2;
      });
      if (index > -1) {
        refValueMap.current.splice(index, 1, {
          value: value2,
          option
        });
      } else {
        refValueMap.current.push({
          value: value2,
          option
        });
      }
      return option;
    }
    var item = refValueMap.current.find(function(x) {
      return x.value === value2;
    });
    return item && item.option;
  };
  var getValueActive = function(direction) {
    if (!optionIndexListForArrowKey.length) {
      return void 0;
    }
    if (valueActive === void 0 || !optionInfoMap.has(valueActive)) {
      return optionValueList[optionIndexListForArrowKey[0]];
    }
    var activeOption = optionInfoMap.get(valueActive);
    var activeIndex = activeOption._index;
    var _index = optionIndexListForArrowKey.indexOf(activeIndex);
    var _length = optionIndexListForArrowKey.length;
    return optionValueList[optionIndexListForArrowKey[((direction === "up" ? _index - 1 : _index + 1) + _length) % _length]];
  };
  var getValueAndOptionForCallback = function(stateValue2, isEmpty) {
    if (isEmpty === void 0) {
      isEmpty = isEmptyValue(stateValue2, isMultipleMode);
    }
    var value2 = stateValue2;
    var option = stateValue2 === void 0 ? void 0 : Array.isArray(stateValue2) ? stateValue2.map(getOptionInfoByValue) : getOptionInfoByValue(stateValue2);
    if (labelInValue && !isEmpty) {
      var getOptionLabel_1 = function(optionValue, optionInfo) {
        var e_1, _a2;
        if (optionInfo) {
          return optionInfo.children;
        }
        var propValue = "value" in props ? props.value : "defaultValue" in props ? props.defaultValue : null;
        if (Array.isArray(propValue)) {
          try {
            for (var propValue_1 = __values(propValue), propValue_1_1 = propValue_1.next(); !propValue_1_1.done; propValue_1_1 = propValue_1.next()) {
              var item = propValue_1_1.value;
              if (isObject(item) && item.value === optionValue) {
                return item.label;
              }
            }
          } catch (e_1_1) {
            e_1 = {
              error: e_1_1
            };
          } finally {
            try {
              if (propValue_1_1 && !propValue_1_1.done && (_a2 = propValue_1.return))
                _a2.call(propValue_1);
            } finally {
              if (e_1)
                throw e_1.error;
            }
          }
        } else if (isObject(propValue) && propValue.value === optionValue) {
          return propValue.label;
        }
      };
      if (Array.isArray(stateValue2)) {
        value2 = stateValue2.map(function(optionValue, index) {
          return {
            value: optionValue,
            label: getOptionLabel_1(optionValue, option[index])
          };
        });
      } else {
        value2 = {
          value: stateValue2,
          label: getOptionLabel_1(stateValue2, option)
        };
      }
    }
    return {
      option,
      value: value2
    };
  };
  var tryUpdateSelectValue = function(value2) {
    setValue(value2);
    if (onChange) {
      var paramsForCallback = getValueAndOptionForCallback(value2);
      onChange(paramsForCallback.value, paramsForCallback.option);
    }
  };
  var checkOption = function(valueToAdd) {
    var option = optionInfoMap.get(valueToAdd);
    if (option) {
      var newValue = value.concat(valueToAdd);
      tryUpdateSelectValue(newValue);
    }
  };
  var uncheckOption = function(valueToRemove) {
    var newValue = value.filter(function(v) {
      return v !== valueToRemove;
    });
    tryUpdateSelectValue(newValue);
    if (onDeselect) {
      var paramsForCallback = getValueAndOptionForCallback(valueToRemove, false);
      onDeselect(paramsForCallback.value, paramsForCallback.option);
    }
  };
  var handleOptionClick = function(optionValue, disabled2) {
    if (disabled2) {
      return;
    }
    if (isMultipleMode) {
      value.indexOf(optionValue) === -1 ? checkOption(optionValue) : uncheckOption(optionValue);
      if (!isObject(showSearch) || !showSearch.retainInputValueWhileSelect) {
        tryUpdateInputValue("", "optionChecked");
      }
    } else {
      if (optionValue !== value) {
        tryUpdateSelectValue(optionValue);
      }
      setTimeout(function() {
        tryUpdatePopupVisible(false);
      });
    }
  };
  var hotkeyHandler = getHotkeyHandler(/* @__PURE__ */ new Map([[Esc.code, function() {
    return tryUpdatePopupVisible(false);
  }], [Enter.code, function() {
    if (popupVisible) {
      var option = optionInfoMap.get(valueActive);
      option && handleOptionClick(valueActive, option.disabled);
    } else {
      tryUpdatePopupVisible(true);
    }
  }], [
    Tab.code,
    function() {
      return tryUpdatePopupVisible(false);
    }
  ], [ArrowUp.code, function() {
    if (popupVisible) {
      refKeyboardArrowDirection.current = "up";
      setValueActive(getValueActive("up"));
      return false;
    }
  }], [ArrowDown.code, function() {
    if (popupVisible) {
      refKeyboardArrowDirection.current = "down";
      setValueActive(getValueActive("down"));
      return false;
    }
  }]]));
  var renderPopup = function() {
    var _a2;
    var needMeasureLongestItem = (triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.autoAlignPopupWidth) === false;
    var needForbidVirtual = needMeasureLongestItem && hasComplexLabelInOptions;
    var mergedNotFoundContent = "notFoundContent" in props ? notFoundContent : renderEmpty("Select");
    var eleOptionList = childrenList.length ? /* @__PURE__ */ jsx(VirtualList, {
      ...__assign({
        id: instancePopupID,
        role: "listbox",
        style: dropdownMenuStyle,
        className: cs(prefixCls + "-popup-inner", dropdownMenuClassName),
        ref: refWrapper,
        data: childrenList,
        height: null,
        isStaticItemHeight: !hasOptGroup,
        measureLongestItem: needMeasureLongestItem,
        itemKey: function(child) {
          return child.props._key;
        },
        onMouseDown: preventDefaultEvent,
        onMouseMove: function() {
          refKeyboardArrowDirection.current = null;
        },
        onScroll: function(e) {
          return onPopupScroll && onPopupScroll(e.target);
        }
      }, virtualListProps, {
        threshold: needForbidVirtual ? null : virtualListProps === null || virtualListProps === void 0 ? void 0 : virtualListProps.threshold
      }),
      children: function(child) {
        var _a3;
        if (isSelectOptGroup(child)) {
          return React__default.createElement(child.type, __assign({}, child.props, {
            prefixCls
          }));
        }
        if (isSelectOption(child)) {
          var optionValue = (_a3 = child.props) === null || _a3 === void 0 ? void 0 : _a3.value;
          var optionProps = {
            prefixCls,
            rtl,
            _valueActive: valueActive,
            _valueSelect: value,
            _isMultipleMode: isMultipleMode,
            _isUserCreatingOption: allowCreate && userCreatingOption === optionValue,
            _isUserCreatedOption: allowCreate && userCreatedOptions.indexOf(optionValue) > -1,
            _onClick: handleOptionClick,
            _onMouseEnter: function(value2) {
              refKeyboardArrowDirection.current === null && setValueActive(value2);
            },
            _onMouseLeave: function() {
              refKeyboardArrowDirection.current === null && setValueActive(void 0);
            }
          };
          return child && React__default.createElement(child.type, __assign({}, child.props, optionProps));
        }
        return child;
      }
    }) : null;
    var eleNoOptionPlaceholder = mergedNotFoundContent && !allowCreate ? /* @__PURE__ */ jsx("div", {
      style: dropdownMenuStyle,
      className: cs(prefixCls + "-popup-inner", dropdownMenuClassName),
      children: mergedNotFoundContent
    }) : null;
    return /* @__PURE__ */ jsx("div", {
      className: cs(prefixCls + "-popup", (_a2 = {}, _a2[prefixCls + "-popup-hidden"] = eleOptionList === null && eleNoOptionPlaceholder === null, _a2[prefixCls + "-popup-multiple"] = isMultipleMode, _a2)),
      tabIndex: -1,
      onKeyDown: function(e) {
        return hotkeyHandler(e);
      },
      children: typeof dropdownRender === "function" ? dropdownRender(eleOptionList || eleNoOptionPlaceholder) : eleOptionList || eleNoOptionPlaceholder
    });
  };
  var handleTokenSeparators = function(str) {
    var hasSeparator = false;
    if (isMultipleMode && isArray(tokenSeparators) && tokenSeparators.length) {
      var rawValues_1 = str.split(new RegExp("[" + tokenSeparators.join("") + "]"));
      if (rawValues_1.length > 1) {
        var splitValues = rawValues_1.filter(function(v, index) {
          return v && rawValues_1.indexOf(v) === index;
        });
        var newValue_1 = value.slice(0);
        var needUpdate_1 = false;
        splitValues.forEach(function(v) {
          if (newValue_1.indexOf(v) === -1 && (allowCreate || optionInfoMap.get(v))) {
            newValue_1.push(v);
            needUpdate_1 = true;
          }
        });
        if (needUpdate_1) {
          tryUpdateSelectValue(newValue_1);
        }
        hasSeparator = true;
      }
    }
    return hasSeparator;
  };
  var selectViewEventHandlers = {
    onFocus,
    onBlur: function(event) {
      onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
      !popupVisible && tryUpdateInputValue("", "optionListHide");
    },
    onKeyDown: function(event) {
      if (event.target.tagName === "INPUT" && event.target.value) {
        var isTab = event.key === Tab.key;
        var isEnter = event.key === Enter.key;
        if (isEnter || isTab) {
          var suffix = isEnter ? "\n" : isTab ? "	" : "";
          if (handleTokenSeparators(event.target.value + suffix)) {
            refTSLastSeparateTriggered.current = Date.now();
            tryUpdateInputValue("", "tokenSeparator");
          }
        }
      }
      hotkeyHandler(event);
      onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
    },
    onChangeInputValue: function(value2, _a2) {
      var inputType = _a2.nativeEvent.inputType;
      if (inputType === "insertFromPaste" && Date.now() - refTSLastSeparateTriggered.current < THRESHOLD_TOKEN_SEPARATOR_TRIGGER || handleTokenSeparators(value2)) {
        tryUpdateInputValue("", "tokenSeparator");
      } else {
        tryUpdateInputValue(value2, "manual");
      }
      if (!popupVisible && value2) {
        tryUpdatePopupVisible(true);
      }
    },
    onPaste: function(e) {
      if (handleTokenSeparators(e.clipboardData.getData("text"))) {
        refTSLastSeparateTriggered.current = Date.now();
      }
      onPaste === null || onPaste === void 0 ? void 0 : onPaste(e);
    },
    onRemoveCheckedItem: function(_, index, event) {
      event.stopPropagation();
      uncheckOption(value[index]);
    },
    onClear: function(event) {
      event.stopPropagation();
      if (isMultipleMode) {
        var newValue = value.filter(function(v) {
          var item = optionInfoMap.get(v);
          return item && item.disabled;
        });
        tryUpdateSelectValue(newValue);
      } else {
        tryUpdateSelectValue(void 0);
      }
      tryUpdateInputValue("", "manual");
      onClear === null || onClear === void 0 ? void 0 : onClear(popupVisible);
    }
  };
  useImperativeHandle(ref, function() {
    var _a2;
    return {
      dom: (_a2 = refSelectView.current) === null || _a2 === void 0 ? void 0 : _a2.dom,
      focus: function() {
        refSelectView.current && refSelectView.current.focus();
      },
      blur: function() {
        refSelectView.current && refSelectView.current.blur();
      },
      hotkeyHandler,
      activeOptionValue: valueActive,
      getOptionInfoByValue,
      getOptionInfoList: function() {
        return __spreadArray([], __read(optionInfoMap.values()), false).filter(function(info) {
          return info._valid;
        });
      }
    };
  }, [hotkeyHandler, optionInfoMap, valueActive]);
  return /* @__PURE__ */ jsx(ResizeObserver, {
    onResize: function() {
      return refTrigger.current.updatePopupPosition();
    },
    children: /* @__PURE__ */ jsx(Trigger, {
      ...__assign({
        ref: function(ref2) {
          return refTrigger.current = ref2;
        },
        popup: renderPopup,
        trigger,
        disabled,
        getPopupContainer,
        classNames: "slideDynamicOrigin",
        autoAlignPopupWidth: true,
        popupAlign: {
          bottom: 4
        },
        popupVisible,
        unmountOnExit,
        onVisibleChange: tryUpdatePopupVisible
      }, omit(triggerProps, ["popupVisible", "onVisibleChange"])),
      children: typeof triggerElement === "function" ? function() {
        return triggerElement(getValueAndOptionForCallback(value));
      }() : triggerElement || /* @__PURE__ */ jsx(SelectView, {
        ...__assign({}, props, selectViewEventHandlers, {
          ref: refSelectView,
          value,
          inputValue,
          popupVisible,
          rtl,
          prefixCls,
          ariaControls: instancePopupID,
          isEmptyValue: isNoOptionSelected,
          isMultiple: isMultipleMode,
          onSort: tryUpdateSelectValue,
          renderText: function(value2) {
            var option = getOptionInfoByValue(value2);
            var text = value2;
            if (isFunction(renderFormat)) {
              var paramsForCallback = getValueAndOptionForCallback(value2, false);
              text = renderFormat(paramsForCallback.option || null, paramsForCallback.value);
            } else {
              var foundLabelFromProps = false;
              if (labelInValue) {
                var propValue = props.value || props.defaultValue;
                if (Array.isArray(propValue)) {
                  var targetLabeledValue = propValue.find(function(item) {
                    return isObject(item) && item.value === value2;
                  });
                  if (targetLabeledValue) {
                    text = targetLabeledValue.label;
                    foundLabelFromProps = true;
                  }
                } else if (isObject(propValue)) {
                  text = propValue.label;
                  foundLabelFromProps = true;
                }
              }
              if (!foundLabelFromProps && option && "children" in option) {
                text = option.children;
              }
            }
            return {
              text,
              disabled: option && option.disabled
            };
          }
        })
      })
    })
  });
}
var ForwardRefSelect = React__default.forwardRef(Select);
var SelectComponent = ForwardRefSelect;
SelectComponent.displayName = "Select";
SelectComponent.Option = Option;
SelectComponent.OptGroup = OptGroup;
const Select$1 = SelectComponent;
export {
  Select$1 as default
};
//# sourceMappingURL=select.js.map
