import { _ as _defineProperty } from '../_verture/defineProperty-62acccfc.js';
import { _ as _toConsumableArray } from '../_verture/toConsumableArray-81040c9e.js';
import { _ as _slicedToArray } from '../_verture/slicedToArray-76060636.js';
import { _ as _typeof } from '../_verture/typeof-498dd2b1.js';
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
import React__default, { useRef, useState, useEffect, useMemo } from 'react';
import Empty from '../Empty/index.js';
import Label from '../Label/index.js';
import { D as Dropdown } from '../_verture/index-fac03ce3.js';
import { UUID, DeepClone } from '@iam-com/lib';
import GlobalContext from '@para-ui/core/GlobalContext';
import CloseIcon from '@iam-com/icons/Close';
import CloseCircle from '@iam-com/icons/CloseCircle';
import Down from '@iam-com/icons/Down';
import Check from '@iam-com/icons/Check';
import SearchIcon from '@iam-com/icons/Search';
import { u as useFormatMessage } from '../_verture/useFormatMessage-703f8b20.js';
import AutoTips from '../AutoTips/index.js';
import { Loading } from '../Loading/index.js';
import { Popover } from '../Popover/index.js';
import HelperText from '../HelperText/index.js';
import { u as useGlobalProps } from '../_verture/useGlobalProps-1b846a65.js';
import { $ as $prefixCls } from '../_verture/constant-66aa48a1.js';
import { s as styleInject } from '../_verture/style-inject.es-300983ab.js';
import '../_verture/unsupportedIterableToArray-cb478f24.js';
import 'clsx';
import '../_verture/tslib.es6-55ed4bd2.js';
import '../Help/index.js';
import '../Tooltip/index.js';
import 'rc-tooltip';
import 'rc-tooltip/lib/placements';
import '@iam-com/icons/Help';
import 'rc-dropdown';
import '../_verture/usePopupContainer-87febeb9.js';
import 'dayjs';
import '@iam-com/icons/LoadingF';

var en = {
  searchPlaceholder: 'Please enter a search name',
  selected: 'Selected'
};

var zh = {
  searchPlaceholder: '请输入搜索名',
  selected: '已选中'
};

var localeJson = {
  zh: zh,
  en: en
};

var css_248z = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2021/10/20 下午2:08\n* @description color\n*/\n.paraui-v3-select {\n  font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, WenQuanYi Micro Hei, sans-serif;\n  font-size: 14px;\n  font-weight: 400;\n  display: inline-block;\n  vertical-align: top;\n  width: 100%;\n}\n.paraui-v3-select > .select-content {\n  line-height: 0;\n  border: 1px solid;\n  border-radius: 4px;\n  border-color: rgba(171, 176, 185, 0.4);\n  padding-right: 12px;\n  position: relative;\n  cursor: pointer;\n  background-color: rgb(255, 255, 255);\n}\n.paraui-v3-select > .select-content:hover {\n  border-color: rgb(54, 102, 214);\n}\n.paraui-v3-select > .select-content:hover > .select-svg > svg {\n  color: rgb(54, 102, 214);\n}\n.paraui-v3-select > .select-content > .select-label-placeholder {\n  width: 100%;\n  height: 100%;\n  padding: 0 12px;\n  color: rgba(46, 55, 67, 0.4);\n  display: inline-block;\n  overflow: hidden;\n  text-overflow: ellipsis;\n  white-space: nowrap;\n  position: absolute;\n  left: 0;\n  top: 0;\n  z-index: 1;\n}\n.paraui-v3-select > .select-content > .select-label-placeholder > .select-required {\n  margin-left: 2px;\n  color: rgb(235, 96, 84);\n}\n.paraui-v3-select > .select-content > .select-svg {\n  position: absolute;\n  right: 12px;\n  top: 0;\n  z-index: 2;\n}\n.paraui-v3-select > .select-content > .select-svg > svg {\n  font-size: 20px;\n  transition: all 0.3s;\n  color: rgba(46, 55, 67, 0.7);\n  opacity: 0;\n}\n.paraui-v3-select > .select-content > .select-svg > .clean-up-icon {\n  position: absolute;\n  left: 0;\n  top: 0;\n  height: 100%;\n  width: 100%;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  opacity: 0;\n}\n.paraui-v3-select > .select-content > .select-svg > .clean-up-icon > svg {\n  font-size: 16px;\n  transition: all 0.3s;\n  color: rgba(46, 55, 67, 0.7);\n}\n.paraui-v3-select > .select-content > .select-svg > .clean-up-icon:hover > svg {\n  color: rgba(54, 102, 214, 0.8);\n}\n.paraui-v3-select > .select-content > .radio-select-content {\n  padding-left: 12px;\n  font-size: 14px;\n  line-height: 1.43;\n  color: rgb(46, 55, 67);\n  word-break: break-all;\n}\n.paraui-v3-select > .select-content > .radio-search-outside {\n  position: absolute;\n  top: 0;\n  left: 0;\n  width: 100%;\n  height: 100%;\n  line-height: 1.43;\n  padding: 0 30px 0 10px;\n  font-size: 14px;\n  cursor: pointer;\n  color: rgb(46, 55, 67);\n  border: 0;\n  border-radius: 4px;\n  background: transparent;\n}\n.paraui-v3-select > .select-content > .check-select-content {\n  padding-left: 12px;\n  overflow: hidden;\n}\n.paraui-v3-select > .select-content > .check-select-content > .check-select-content-item {\n  display: inline-block;\n  background-color: rgba(171, 176, 185, 0.2);\n  border-radius: 4px;\n  padding: 0 12px 0 12px;\n  color: rgb(46, 55, 67);\n  margin-right: 8px;\n  vertical-align: top;\n  max-width: 100%;\n  white-space: nowrap;\n}\n.paraui-v3-select > .select-content > .check-select-content > .check-select-content-item.check-select-content-item-more {\n  cursor: pointer;\n  color: rgb(46, 55, 67);\n}\n.paraui-v3-select > .select-content > .check-select-content > .check-select-content-item.check-select-content-item-more > span {\n  max-width: none;\n}\n.paraui-v3-select > .select-content > .check-select-content > .check-select-content-item > span {\n  display: inline-block;\n  height: 100%;\n  vertical-align: top;\n  max-width: calc(100% - 20px);\n  overflow: hidden;\n  text-overflow: ellipsis;\n}\n.paraui-v3-select > .select-content > .check-select-content > .check-select-content-item > svg {\n  cursor: pointer;\n  margin-left: 8px;\n  color: rgb(46, 55, 67);\n  font-size: 16px;\n  position: relative;\n  z-index: 10;\n}\n.paraui-v3-select > .select-content > .check-select-content > .check-select-content-item > svg:hover {\n  color: rgb(54, 102, 214);\n}\n.paraui-v3-select > .select-content > .check-select-content > .check-select-content-item.check-select-content-item-noclose > span {\n  max-width: none;\n}\n.paraui-v3-select > .select-content > .check-select-content > .check-search-outside {\n  width: 10px;\n  max-width: 100% !important;\n  display: none;\n  border: 0;\n  color: rgb(46, 55, 67);\n  font-size: 14px;\n  cursor: pointer;\n}\n.paraui-v3-select.paraui-v3-select-allow-clear > .select-content {\n  padding-right: 40px;\n}\n.paraui-v3-select.paraui-v3-select-allow-clear > .select-content .select-label-placeholder {\n  padding-right: 40px;\n}\n.paraui-v3-select.paraui-v3-select-allow-clear.paraui-v3-select-value > .select-content:hover > .select-svg > svg {\n  opacity: 0;\n  transition: all 0s;\n}\n.paraui-v3-select.paraui-v3-select-allow-clear.paraui-v3-select-value > .select-content:hover > .select-svg > .clean-up-icon {\n  opacity: 1;\n  transition: all 0.3s;\n}\n.paraui-v3-select.paraui-v3-select-over-line.paraui-v3-select-small > .select-content {\n  height: inherit;\n  min-height: 28px;\n}\n.paraui-v3-select.paraui-v3-select-over-line.paraui-v3-select-small > .select-content > .check-select-content {\n  height: 100%;\n}\n.paraui-v3-select.paraui-v3-select-over-line.paraui-v3-select-medium > .select-content {\n  height: inherit;\n  min-height: 32px;\n}\n.paraui-v3-select.paraui-v3-select-over-line.paraui-v3-select-medium > .select-content > .check-select-content {\n  height: 100%;\n}\n.paraui-v3-select.paraui-v3-select-over-line.paraui-v3-select-large > .select-content {\n  height: inherit;\n  min-height: 36px;\n}\n.paraui-v3-select.paraui-v3-select-over-line.paraui-v3-select-large > .select-content > .check-select-content {\n  height: 100%;\n}\n.paraui-v3-select.paraui-v3-select-show-select > .select-content {\n  padding-right: 40px;\n}\n.paraui-v3-select.paraui-v3-select-show-select > .select-content .select-label-placeholder {\n  padding-right: 40px;\n}\n.paraui-v3-select.paraui-v3-select-show-select > .select-content > .select-svg > svg {\n  opacity: 1;\n}\n.paraui-v3-select.paraui-v3-select-disabled > .select-content {\n  background-color: rgba(171, 176, 185, 0.12);\n  cursor: not-allowed;\n}\n.paraui-v3-select.paraui-v3-select-disabled > .select-content:hover {\n  border-color: rgba(171, 176, 185, 0.4);\n}\n.paraui-v3-select.paraui-v3-select-disabled > .select-content:hover > .select-svg > svg {\n  color: rgba(46, 55, 67, 0.7);\n}\n.paraui-v3-select.paraui-v3-select-disabled > .select-content > .check-select-content > .check-select-content-item > span {\n  max-width: 100%;\n}\n.paraui-v3-select.paraui-v3-select-error > .select-content {\n  border-color: rgb(235, 96, 84) !important;\n}\n.paraui-v3-select.paraui-v3-select-open > .select-content {\n  border-color: rgb(54, 102, 214);\n}\n.paraui-v3-select.paraui-v3-select-open > .select-content > .select-svg > svg {\n  transform: rotate(180deg);\n  color: rgb(54, 102, 214);\n}\n.paraui-v3-select.paraui-v3-select-open > .select-content > .check-select-content > .check-search-outside {\n  display: inline-block;\n}\n.paraui-v3-select.paraui-v3-select-small > .select-content {\n  height: 28px;\n}\n.paraui-v3-select.paraui-v3-select-small > .select-content > .select-label-placeholder {\n  line-height: 26px;\n}\n.paraui-v3-select.paraui-v3-select-small > .select-content > .select-svg {\n  top: 3px;\n}\n.paraui-v3-select.paraui-v3-select-small > .select-content > .radio-select-content {\n  padding-bottom: 3px;\n  padding-top: 3px;\n}\n.paraui-v3-select.paraui-v3-select-small > .select-content > .check-select-content {\n  padding-bottom: 3px;\n  height: 26px;\n}\n.paraui-v3-select.paraui-v3-select-small > .select-content > .check-select-content > .check-select-content-item {\n  margin-top: 3px;\n  height: 20px;\n  line-height: 20px;\n}\n.paraui-v3-select.paraui-v3-select-small > .select-content > .check-select-content > .check-select-content-item > svg {\n  top: 2px;\n}\n.paraui-v3-select.paraui-v3-select-small > .select-content > .check-select-content > .check-search-outside {\n  margin-top: 3px;\n  height: 20px;\n}\n.paraui-v3-select.paraui-v3-select-medium > .select-content {\n  height: 32px;\n}\n.paraui-v3-select.paraui-v3-select-medium > .select-content > .select-label-placeholder {\n  line-height: 30px;\n}\n.paraui-v3-select.paraui-v3-select-medium > .select-content > .select-svg {\n  top: 6px;\n}\n.paraui-v3-select.paraui-v3-select-medium > .select-content > .radio-select-content {\n  padding-bottom: 5px;\n  padding-top: 5px;\n}\n.paraui-v3-select.paraui-v3-select-medium > .select-content > .check-select-content {\n  padding-bottom: 4px;\n  height: 30px;\n}\n.paraui-v3-select.paraui-v3-select-medium > .select-content > .check-select-content > .check-select-content-item {\n  margin-top: 4px;\n  height: 22px;\n  line-height: 22px;\n}\n.paraui-v3-select.paraui-v3-select-medium > .select-content > .check-select-content > .check-select-content-item > svg {\n  top: 3px;\n}\n.paraui-v3-select.paraui-v3-select-medium > .select-content > .check-select-content > .check-search-outside {\n  margin-top: 4px;\n  height: 22px;\n}\n.paraui-v3-select.paraui-v3-select-large > .select-content {\n  height: 36px;\n}\n.paraui-v3-select.paraui-v3-select-large > .select-content > .select-label-placeholder {\n  line-height: 34px;\n}\n.paraui-v3-select.paraui-v3-select-large > .select-content > .select-svg {\n  top: 8px;\n}\n.paraui-v3-select.paraui-v3-select-large > .select-content > .radio-select-content {\n  padding-bottom: 7px;\n  padding-top: 7px;\n}\n.paraui-v3-select.paraui-v3-select-large > .select-content > .check-select-content {\n  padding-bottom: 5px;\n  height: 34px;\n}\n.paraui-v3-select.paraui-v3-select-large > .select-content > .check-select-content > .check-select-content-item {\n  margin-top: 5px;\n  height: 24px;\n  line-height: 24px;\n}\n.paraui-v3-select.paraui-v3-select-large > .select-content > .check-select-content > .check-select-content-item > svg {\n  top: 3px;\n}\n.paraui-v3-select.paraui-v3-select-large > .select-content > .check-select-content > .check-search-outside {\n  margin-top: 5px;\n  height: 24px;\n}\n\n.paraui-v3-select-popover.component-dropdown .select-popover-content.select-popover-content-search > .select-popover-list {\n  padding-top: 0px;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content.select-popover-content-search > .select-popover-list > .select-nodata {\n  margin-top: 58px;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-search {\n  display: flex;\n  align-items: center;\n  padding: 0 12px;\n  border-bottom: 1px solid;\n  border-color: rgba(171, 176, 185, 0.2);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-search > input {\n  border: 0;\n  outline: none;\n  font-size: 14px;\n  color: rgb(46, 55, 67);\n  width: 100%;\n  height: 100%;\n  line-height: 1.43;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-search > input::placeholder {\n  font-size: 14px;\n  opacity: 1;\n  color: rgba(46, 55, 67, 0.4);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-search > input::-ms-clear {\n  display: none;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-search > input::-ms-reveal {\n  display: none;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-search > input:-moz-placeholder {\n  color: rgba(46, 55, 67, 0.4);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-search > input::-moz-placeholder {\n  color: rgba(46, 55, 67, 0.4);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-search > input:-ms-input-placeholder { /* Internet Explorer 10-11 */\n  color: rgba(46, 55, 67, 0.4);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-search > input::-ms-input-placeholder { /* Microsoft Edge */\n  color: rgba(46, 55, 67, 0.4);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-search > svg {\n  color: rgba(46, 55, 67, 0.4);\n  font-size: 20px;\n  cursor: pointer;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list {\n  padding: 8px 0;\n  max-height: 300px;\n  overflow: auto;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list.select-popover-list-loading {\n  height: 100px;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item {\n  display: flex;\n  cursor: pointer;\n  padding: 0 12px;\n  align-items: center;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item > .select-popover-list-item-label {\n  flex: 1;\n  overflow: hidden;\n  color: rgb(46, 55, 67);\n  font-size: 14px;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item > .select-popover-list-item-svg {\n  line-height: 0;\n  display: none;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item > .select-popover-list-item-svg > svg {\n  font-size: 20px;\n  color: rgb(54, 102, 214);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item.select-popover-list-item-select > .select-popover-list-item-label {\n  color: rgb(54, 102, 214);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item.select-popover-list-item-select > .select-popover-list-item-svg {\n  display: inline-block;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item.select-popover-list-item-hover {\n  background-color: rgba(171, 176, 185, 0.12);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item.select-popover-list-item-hover > .select-popover-list-item-label {\n  color: rgb(54, 102, 214);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item.select-popover-list-item-keydown {\n  background-color: rgba(171, 176, 185, 0.12);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item.select-popover-list-item-keydown > .select-popover-list-item-label {\n  color: rgb(54, 102, 214);\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item.select-popover-list-item-disabled {\n  cursor: not-allowed;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list .select-popover-list-item.select-popover-list-item-disabled > .select-popover-list-item-label {\n  color: rgba(46, 55, 67, 0.4) !important;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list > .select-popover-list-group .select-popover-list-group-label {\n  display: inline-block;\n  width: 100%;\n  padding: 0 12px;\n  color: rgba(46, 55, 67, 0.4);\n  font-size: 14px;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list > .select-popover-list-group .select-popover-list-item {\n  padding-left: 20px;\n}\n.paraui-v3-select-popover.component-dropdown .select-popover-content > .select-popover-list > .select-nodata {\n  text-align: center;\n  font-size: 14px;\n  color: rgb(46, 55, 67);\n  margin-top: 50px;\n  margin-bottom: 72px;\n}\n.paraui-v3-select-popover.component-dropdown.paraui-v3-select-popover-small > .select-popover-content > .select-popover-search {\n  height: 28px;\n}\n.paraui-v3-select-popover.component-dropdown.paraui-v3-select-popover-small > .select-popover-content > .select-popover-list .select-popover-list-item {\n  height: 28px;\n  line-height: 28px;\n}\n.paraui-v3-select-popover.component-dropdown.paraui-v3-select-popover-small > .select-popover-content > .select-popover-list > .select-popover-list-group .select-popover-list-group-label {\n  height: 28px;\n  line-height: 28px;\n}\n.paraui-v3-select-popover.component-dropdown.paraui-v3-select-popover-medium > .select-popover-content > .select-popover-search {\n  height: 32px;\n}\n.paraui-v3-select-popover.component-dropdown.paraui-v3-select-popover-medium > .select-popover-content > .select-popover-list .select-popover-list-item {\n  height: 32px;\n  line-height: 32px;\n}\n.paraui-v3-select-popover.component-dropdown.paraui-v3-select-popover-medium > .select-popover-content > .select-popover-list > .select-popover-list-group .select-popover-list-group-label {\n  line-height: 32px;\n  height: 32px;\n}\n.paraui-v3-select-popover.component-dropdown.paraui-v3-select-popover-large > .select-popover-content > .select-popover-search {\n  height: 36px;\n}\n.paraui-v3-select-popover.component-dropdown.paraui-v3-select-popover-large > .select-popover-content > .select-popover-list .select-popover-list-item {\n  height: 36px;\n  line-height: 36px;\n}\n.paraui-v3-select-popover.component-dropdown.paraui-v3-select-popover-large > .select-popover-content > .select-popover-list > .select-popover-list-group .select-popover-list-group-label {\n  height: 36px;\n  line-height: 36px;\n}\n\n.paraui-v3-select-more-popover {\n  padding-left: 16px;\n}\n.paraui-v3-select-more-popover .select-more {\n  width: 300px;\n}\n.paraui-v3-select-more-popover .select-more > .select-more-title {\n  font-size: 14px;\n  padding: 0 12px;\n  color: rgba(46, 55, 67, 0.7);\n}\n.paraui-v3-select-more-popover .select-more > .select-more-content {\n  max-height: 300px;\n  overflow: auto;\n}\n.paraui-v3-select-more-popover .select-more > .select-more-content > .select-more-content-item {\n  padding: 0 12px;\n  display: flex;\n  justify-content: space-around;\n  align-items: center;\n}\n.paraui-v3-select-more-popover .select-more > .select-more-content > .select-more-content-item > span {\n  width: calc(100% - 25px);\n  display: inline-block;\n  font-size: 14px;\n}\n.paraui-v3-select-more-popover .select-more > .select-more-content > .select-more-content-item > svg {\n  font-size: 20px;\n  position: relative;\n  cursor: pointer;\n  color: rgb(46, 55, 67);\n}\n.paraui-v3-select-more-popover .select-more > .select-more-content > .select-more-content-item > svg:hover {\n  color: rgb(54, 102, 214);\n}\n.paraui-v3-select-more-popover.paraui-v3-select-more-popover-small .select-more > .select-more-title {\n  line-height: 28px;\n}\n.paraui-v3-select-more-popover.paraui-v3-select-more-popover-small .select-more > .select-more-content > .select-more-content-item {\n  line-height: 28px;\n}\n.paraui-v3-select-more-popover.paraui-v3-select-more-popover-medium .select-more > .select-more-title {\n  line-height: 32px;\n}\n.paraui-v3-select-more-popover.paraui-v3-select-more-popover-medium .select-more > .select-more-content > .select-more-content-item {\n  line-height: 32px;\n}\n.paraui-v3-select-more-popover.paraui-v3-select-more-popover-large .select-more > .select-more-title {\n  line-height: 36px;\n}\n.paraui-v3-select-more-popover.paraui-v3-select-more-popover-large .select-more > .select-more-content > .select-more-content-item {\n  line-height: 36px;\n}";
styleInject(css_248z);

/**
 * 计算文本长度
 * @param fontSize 字体大小
 * @param fontFamily 字体类型
 * @param text 文本
 */
var textSize = function textSize(fontSize, fontFamily, text) {
  var span = document.createElement("span");
  span.id = 'referenceSpan';
  var result = {};
  result.width = span.offsetWidth;
  result.height = span.offsetHeight;
  span.style.visibility = "hidden";
  span.style.fontSize = fontSize;
  span.style.fontFamily = fontFamily;
  span.style.display = "inline-block";
  var isExists = document.getElementById("referenceSpan");
  if (isExists) {
    document.body.removeChild(isExists);
  }
  document.body.appendChild(span);
  if (typeof span.textContent != "undefined") {
    span.textContent = text;
  } else {
    span.innerText = text;
  }
  result.width = parseFloat(window.getComputedStyle(span).width) - result.width;
  result.height = parseFloat(window.getComputedStyle(span).height) - result.height;
  document.body.removeChild(span);
  return result;
};
var useDidMountEffect = function useDidMountEffect(func, deps) {
  var didMount = React__default.useRef(false);
  React__default.useEffect(function () {
    if (didMount.current) func();else didMount.current = true;
    // eslint-disable-next-line
  }, deps);
};
var Select = function Select(props) {
  var _useGlobalProps = useGlobalProps(props, 'Select'),
    className = _useGlobalProps.className,
    style = _useGlobalProps.style,
    _useGlobalProps$showS = _useGlobalProps.showSelect,
    showSelect = _useGlobalProps$showS === void 0 ? true : _useGlobalProps$showS,
    _useGlobalProps$allow = _useGlobalProps.allowClear,
    allowClear = _useGlobalProps$allow === void 0 ? false : _useGlobalProps$allow,
    emptyProps = _useGlobalProps.emptyProps,
    _useGlobalProps$size = _useGlobalProps.size,
    size = _useGlobalProps$size === void 0 ? 'large' : _useGlobalProps$size,
    _useGlobalProps$label = _useGlobalProps.labelMode,
    labelMode = _useGlobalProps$label === void 0 ? 'outside' : _useGlobalProps$label,
    labelTooltip = _useGlobalProps.labelTooltip,
    _useGlobalProps$place = _useGlobalProps.placeholder,
    placeholder = _useGlobalProps$place === void 0 ? '' : _useGlobalProps$place,
    searchPlaceholder = _useGlobalProps.searchPlaceholder,
    _useGlobalProps$label2 = _useGlobalProps.label,
    label = _useGlobalProps$label2 === void 0 ? '' : _useGlobalProps$label2,
    _useGlobalProps$input = _useGlobalProps.input,
    input = _useGlobalProps$input === void 0 ? false : _useGlobalProps$input,
    _useGlobalProps$disab = _useGlobalProps.disabled,
    disabled = _useGlobalProps$disab === void 0 ? false : _useGlobalProps$disab,
    _useGlobalProps$multi = _useGlobalProps.multiple,
    multiple = _useGlobalProps$multi === void 0 ? false : _useGlobalProps$multi,
    _useGlobalProps$requi = _useGlobalProps.required,
    required = _useGlobalProps$requi === void 0 ? false : _useGlobalProps$requi,
    labelSign = _useGlobalProps.labelSign,
    _useGlobalProps$error = _useGlobalProps.error,
    error = _useGlobalProps$error === void 0 ? false : _useGlobalProps$error,
    hideErrorDom = _useGlobalProps.hideErrorDom,
    _useGlobalProps$helpe = _useGlobalProps.helperText,
    helperText = _useGlobalProps$helpe === void 0 ? '' : _useGlobalProps$helpe,
    list = _useGlobalProps.list,
    _useGlobalProps$showN = _useGlobalProps.showName,
    showName = _useGlobalProps$showN === void 0 ? 'label' : _useGlobalProps$showN,
    _useGlobalProps$showV = _useGlobalProps.showValue,
    showValue = _useGlobalProps$showV === void 0 ? 'value' : _useGlobalProps$showV,
    _useGlobalProps$child = _useGlobalProps.childrenName,
    childrenName = _useGlobalProps$child === void 0 ? 'children' : _useGlobalProps$child,
    value = _useGlobalProps.value,
    onChange = _useGlobalProps.onChange,
    _useGlobalProps$overL = _useGlobalProps.overLine,
    overLine = _useGlobalProps$overL === void 0 ? false : _useGlobalProps$overL,
    _useGlobalProps$searc = _useGlobalProps.search,
    search = _useGlobalProps$searc === void 0 ? false : _useGlobalProps$searc,
    _useGlobalProps$searc2 = _useGlobalProps.searchModel,
    searchModel = _useGlobalProps$searc2 === void 0 ? 'inside' : _useGlobalProps$searc2,
    selectPopoverClassName = _useGlobalProps.selectPopoverClassName,
    morePopoverClassName = _useGlobalProps.morePopoverClassName;
    _useGlobalProps.fetchSuggestions;
    var searchInputProps = _useGlobalProps.searchInputProps,
    onEnter = _useGlobalProps.onEnter,
    onEnterInput = _useGlobalProps.onEnterInput,
    onClear = _useGlobalProps.onClear,
    getPopupContainer = _useGlobalProps.getPopupContainer,
    renderContent = _useGlobalProps.renderContent,
    _useGlobalProps$selec = _useGlobalProps.selectCheckIcon,
    selectCheckIcon = _useGlobalProps$selec === void 0 ? true : _useGlobalProps$selec;
  /**
   * 处理初始化数据,让list支持传入字符串
   * 把数组转换成,组件能接收的格式
   * */
  var handList = function handList() {
    var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var handArr = [];
    for (var i = 0, l = arr.length; i < l; i++) {
      var item = arr[i];
      if (_typeof(item) === 'object' && item !== null) {
        handArr.push(item);
      } else {
        var obj = {};
        obj[showName] = item;
        obj[showValue] = item;
        handArr.push(obj);
      }
    }
    return handArr;
  };
  var handleInitValue = function handleInitValue() {
    var valArr = [];
    if (props.defaultValue !== undefined) {
      if (props.multiple) {
        // 多选
        valArr = DeepClone(props.defaultValue || []);
      } else {
        // 单选
        valArr = props.defaultValue === '' ? [] : [props.defaultValue];
      }
    }
    if (value !== undefined) {
      if (multiple) {
        // 多选
        valArr = DeepClone(value || []);
      } else {
        // 单选
        valArr = value === '' ? [] : [value];
      }
    }
    return valArr;
  };
  var handleIntlList = function handleIntlList() {
    var listHand = handList(list);
    var json = {};
    for (var i = 0, l = listHand.length; i < l; i++) {
      var item = listHand[i];
      if (item[childrenName] && item[childrenName].length > 0) {
        var childArr = item[childrenName];
        for (var j = 0, k = childArr.length; j < k; j++) {
          var childItem = childArr[j];
          var key = childItem[showValue];
          json[key] = childItem;
        }
      } else {
        var _key = item[showValue];
        json[_key] = item;
      }
    }
    return json;
  };
  var posDom = useRef(null);
  var _useState = useState($prefixCls + '-select-' + UUID()),
    _useState2 = _slicedToArray(_useState, 1),
    classOne = _useState2[0]; // 唯一class
  var _useState3 = useState('select-popover-' + UUID()),
    _useState4 = _slicedToArray(_useState3, 1),
    classOneSelect = _useState4[0]; // 唯一class
  var _useState5 = useState(false),
    _useState6 = _slicedToArray(_useState5, 2),
    open = _useState6[0],
    setOpen = _useState6[1]; // 是否打开下拉框
  var _useState7 = useState(false),
    _useState8 = _slicedToArray(_useState7, 2),
    showText = _useState8[0],
    setShowText = _useState8[1]; // 是否显示lable,placeholder, true不显示
  var _useState9 = useState(handleInitValue()),
    _useState10 = _slicedToArray(_useState9, 2),
    valueCom = _useState10[0],
    setValueCom = _useState10[1]; // 值
  var _useState11 = useState([]),
    _useState12 = _slicedToArray(_useState11, 2),
    listCom = _useState12[0],
    setListCom = _useState12[1]; // 下拉框渲染
  var _useState13 = useState(handleIntlList()),
    _useState14 = _slicedToArray(_useState13, 2),
    listJson = _useState14[0],
    setListJson = _useState14[1]; // 下拉选项对象
  var _useState15 = useState(null),
    _useState16 = _slicedToArray(_useState15, 2),
    morePos = _useState16[0],
    setMorePos = _useState16[1]; // 超出在原始位置
  var _useState17 = useState(false),
    _useState18 = _slicedToArray(_useState17, 2),
    openMore = _useState18[0],
    setOpenMore = _useState18[1]; // 显示更多
  var _useState19 = useState(''),
    _useState20 = _slicedToArray(_useState19, 2),
    searchValue = _useState20[0],
    setSearchValue = _useState20[1]; // 搜索值
  var _useState21 = useState(false),
    _useState22 = _slicedToArray(_useState21, 2),
    overLineCom = _useState22[0],
    setOverLineCom = _useState22[1]; // 超出是否换行
  var _useState23 = useState(false),
    _useState24 = _slicedToArray(_useState23, 2),
    loading = _useState24[0],
    setLoading = _useState24[1]; // 下拉加载loading
  // const [emptyBol, setEmptyBol] = useState<boolean>(false); // 延迟显示空状态
  var textDom = useRef(null);
  var _useState25 = useState({}),
    _useState26 = _slicedToArray(_useState25, 1),
    constData = _useState26[0]; // 不变的常量 多行 不换行定时器  搜索定时器
  var _React$useContext = React__default.useContext(GlobalContext),
    language = _React$useContext.language,
    locale = _React$useContext.locale;
  var intl = useFormatMessage('Select', localeJson);
  constData.listCom = listCom;
  constData.searchModel = searchModel;
  useEffect(function () {
    return function () {
      clearTimeout(constData.searchTimer);
      clearTimeout(constData.timer);
      clearTimeout(constData.scrollTimer);
    };
  }, []);
  // 赋值value
  useDidMountEffect(function () {
    if (value !== undefined) {
      if (multiple) {
        // 多选
        setValueCom(DeepClone(value || []));
      } else {
        // 单选
        setValueCom(value === '' ? [] : [value]);
      }
    }
  }, [value, multiple]);
  // 判断组件超出是换行,还是不换行
  useEffect(function () {
    if (searchModel === 'outside' && input) {
      if (multiple) return setOverLineCom(true); // 多选,输入框在框里面,超出必须换行
      // return setOverLineCom(false); // 单选不换行
    }

    setOverLineCom(overLine);
  }, [overLine, searchModel, multiple, input]);
  // 计算下拉选项,处理下拉选项json
  useDidMountEffect(function () {
    setListJson(handleIntlList());
  }, [list]);
  useEffect(function () {
    if (multiple) {
      if (!overLineCom) {
        // 不换行
        setMorePos(valueCom.length);
      }
    }
  }, [overLineCom, multiple, valueCom]);
  // 多行,不换行计算
  useEffect(function () {
    // 多行不换行计算
    if (!overLineCom) {
      setTimeout(function () {
        handMultiline(valueCom.length);
      });
      window.addEventListener("resize", changeSize);
    } else {
      setMorePos(valueCom.length);
    }
    return function () {
      window.removeEventListener("resize", changeSize);
    };
  }, [valueCom, overLineCom]);
  // 计算是否显示label,placehold
  useEffect(function () {
    if (valueCom && valueCom.length > 0) {
      setShowText(true); // 有值不显示label,placehold
    } else {
      setShowText(false);
      if (searchModel === 'outside') {
        setShowText(searchValue !== '');
      }
    }
  }, [search, searchValue, searchModel, valueCom, input]);
  // 筛选下拉框数据
  useEffect(function () {
    if (!open) return;
    setLoading(true);
    if (props.fetchSuggestions) {
      props.fetchSuggestions && props.fetchSuggestions(searchValue, function (data) {
        var listHand = handList(data);
        handSelectList(listHand, true);
        setLoading(false);
      });
    } else {
      var listHand = handList(list);
      handSelectList(listHand);
      setLoading(false);
    }
  }, [search, searchValue, list, open]);
  // 搜索框自动得到焦点
  useEffect(function () {
    if (open) {
      setTimeout(function () {
        inputFocus();
        //window.addEventListener("click", clickCom);
        window.addEventListener("keydown", keydownCom);
      });
    } else {
      setSearchValue('');
      //window.removeEventListener("click", clickCom);
      window.removeEventListener("keydown", keydownCom);
    }
    return function () {
      //window.removeEventListener("click", clickCom);
      window.removeEventListener("keydown", keydownCom);
    };
  }, [open]);
  // 是否计算搜索框长度
  useEffect(function () {
    if (disabled === true) return;
    if (multiple && searchModel === 'outside') handInputLength(searchValue);
  }, [searchValue, multiple, disabled, searchModel, input]);
  /**
   * 处理下拉内容
   * @param listData 数据源
   * @param customSearch 是否自定义搜索
   * */
  var handSelectList = function handSelectList(listData, customSearch) {
    var arr = [];
    var listDeep = _toConsumableArray(listData);
    for (var i = 0, l = listDeep.length; i < l; i++) {
      var item = Object.assign({}, listDeep[i]);
      if (item[childrenName] && item[childrenName].length > 0) {
        var childArr = item[childrenName];
        var handChildArr = [];
        for (var j = 0, k = childArr.length; j < k; j++) {
          var childItem = childArr[j];
          if (customSearch) {
            handChildArr.push(childItem);
          } else {
            var bol = handShowItem(childItem);
            if (bol) handChildArr.push(childItem);
          }
        }
        // 存在二级
        if (handChildArr.length > 0) {
          item[childrenName] = handChildArr;
          arr.push(item);
        }
      } else {
        if (customSearch) {
          arr.push(item);
        } else {
          var _bol = handShowItem(item);
          if (_bol) arr.push(item);
        }
      }
    }
    setListCom(arr);
    setLoading(false);
  };
  // 输入框的到焦点
  var inputFocus = function inputFocus() {
    var inputDom = textDom && textDom.current;
    if (constData.searchModel === "inside") return;
    inputDom && inputDom.focus({
      preventScroll: true
    });
  };
  /**
   * 查找元素
   * @param el 当前元素
   * @param selector 查找元素class
   */
  var closest = function closest(el, selector) {
    var matchesSelector = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
    while (el) {
      if (matchesSelector.call(el, selector)) {
        break;
      }
      el = el.parentElement;
    }
    return el;
  };
  /**
   * 判断是否显示
   * @param item 详细信息
   * @return boolean
   */
  var handShowItem = function handShowItem(item) {
    var bol = true;
    // 按显示名来
    var name = item[showName];
    if (name && typeof name === 'string' && name.toLowerCase().indexOf(searchValue.trim().toLowerCase()) === -1) bol = false;
    return bol;
  };
  /**
   * 多选 不换行 计算
   * @param index 数组下标
   */
  var handMultiline = function handMultiline(index) {
    if (index === null || index === 0) return;
    if (index === undefined) index = valueCom.length;
    var boxDom = document.querySelector('.' + classOne + ' > .select-content > .check-select-content');
    if (!boxDom) return;
    if (boxDom.scrollHeight > boxDom.clientHeight) {
      var num = Number(index) - 1;
      // 超出
      setMorePos(num);
      handMultiline(num);
    } else {
      // 一行
      if (valueCom.length <= index) handleCloseMore();
    }
  };
  // 多选 不换行
  var changeSize = function changeSize() {
    clearTimeout(constData.timer);
    constData.timer = setTimeout(function () {
      setMorePos(valueCom.length);
      handMultiline();
    }, 100);
  };
  // 显示下拉框
  var clickSelect = function clickSelect() {
    if (disabled === true) return;
    setOpen(true);
  };
  // 关闭下拉框
  var handleClose = function handleClose() {
    setOpen(false);
  };
  /**
   * 点击显示更多
   * @param e 点击元素
   */
  var clickMore = function clickMore(e) {
    setOpenMore(true);
    setOpen(false);
    e.stopPropagation();
  };
  // 关闭显示更多
  var handleCloseMore = function handleCloseMore() {
    setOpenMore(false);
  };
  /**
   * 点击选项
   * @param item 当前选项信息
   * @param enter 是否回车
   * @param e 元素
   */
  var clickItem = function clickItem(item, enter) {
    return function (e) {
      var val = item[showValue];
      if (_typeof(disabled) === 'object' && disabled.indexOf(val) !== -1) return;
      if (multiple) {
        // 多选
        var index = valueCom.indexOf(val);
        if (index !== -1) {
          // 存在 去除
          valueCom.splice(index, 1);
        } else {
          valueCom.push(val);
        }
        if (props.value === undefined) setValueCom(_toConsumableArray(valueCom));
        onChange && onChange(_toConsumableArray(valueCom), e);
        if (enter) onEnter && onEnter(_toConsumableArray(valueCom));
        inputFocus();
      } else {
        // 单选
        if (props.value === undefined) setValueCom([val]);
        onChange && onChange(val, e);
        if (enter) onEnter && onEnter(val);
        handleClose();
        setSearchValue('');
      }
    };
  };
  /**
   * 多选删除index
   * @param item 当前选项信息
   * @param val 值
   * @param e 元素
   */
  var delItem = function delItem(item, val) {
    return function (e) {
      if (!item) item = _defineProperty({}, showValue, val);
      clickItem(item)(e);
      e.stopPropagation();
    };
  };
  // 处理下拉框class
  var handClass = function handClass() {
    var str = "".concat($prefixCls, "-select");
    if (multiple && !overLineCom) str += ' ' + classOne; // 多选 超出不换行
    if (className) str += ' ' + className;
    if (size) str += " ".concat($prefixCls, "-select-").concat(size);
    if (error) str += " ".concat($prefixCls, "-select-error");
    if (disabled === true) str += " ".concat($prefixCls, "-select-disabled");
    if (open) str += " ".concat($prefixCls, "-select-open");
    if (multiple) str += " ".concat($prefixCls, "-select-multiple");
    if (overLineCom) str += " ".concat($prefixCls, "-select-over-line"); // 可输入,换行
    if (showSelect) str += " ".concat($prefixCls, "-select-show-select");
    if (valueCom.length > 0) str += " ".concat($prefixCls, "-select-value");
    if (allowClear) str += " ".concat($prefixCls, "-select-allow-clear");
    return str;
  };
  // 处理下拉弹框class
  var handleClassPopover = function handleClassPopover() {
    var str = "".concat($prefixCls, "-select-popover ").concat($prefixCls, "-scrollbar-small");
    if (size) str += " ".concat($prefixCls, "-select-popover-").concat(size);
    if (multiple) {
      str += " ".concat($prefixCls, "-select-popover-multiple");
    } else {
      str += " ".concat($prefixCls, "-select-popover-radio");
    }
    if (selectPopoverClassName) str += ' ' + selectPopoverClassName;
    return str;
  };
  // 处理下拉框更多class
  var handleClassMorePopover = function handleClassMorePopover() {
    var str = "".concat($prefixCls, "-select-more-popover ").concat($prefixCls, "-scrollbar-small");
    if (size) str += " ".concat($prefixCls, "-select-more-popover-").concat(size);
    if (morePopoverClassName) str += ' ' + morePopoverClassName;
    return str;
  };
  /**
   * 改变搜索输入框
   * @param e 搜索框元素
   */
  var changeSearch = function changeSearch(e) {
    setSearchValue(e.target.value);
    searchInputProps && searchInputProps.onChange && searchInputProps.onChange(e);
  };
  /**
   * 回车搜索输入框
   * @param e 搜索框元素
   */
  var onKeyDownSearch = function onKeyDownSearch(e) {
    if (e.keyCode === 13) {
      onEnterInput && onEnterInput(searchValue);
      var selectDom = document.querySelector('.' + classOneSelect + ' .select-popover-list');
      if (selectDom) {
        var hoverDom = selectDom.querySelector('.select-popover-list-item-hover');
        var keydownDom = selectDom.querySelector('.select-popover-list-item-keydown');
        var operateDom = keydownDom || hoverDom;
        if (operateDom) return;
      }
      if (props.input && searchValue.trim() !== '') {
        var arr = '';
        if (multiple) {
          arr = [].concat(_toConsumableArray(valueCom), [searchValue]);
        } else {
          arr = searchValue;
        }
        if (props.value === undefined) setValueCom(arr);
        onChange && onChange(arr, e);
        setSearchValue('');
      }
    }
    searchInputProps && searchInputProps.onKeyDown && searchInputProps.onKeyDown(e);
  };
  /**
   * 多选框设置input框长度
   * @param text 文本
   */
  var handInputLength = function handInputLength(text) {
    var inputDom = textDom && textDom.current;
    if (!inputDom) return null;
    var style = window.getComputedStyle(inputDom);
    var fontFamily = style.fontFamily;
    var fontSize = style.fontSize;
    var results = textSize(fontSize, fontFamily, text);
    var width = results.width;
    if (width < 10) width = 10;
    inputDom.style.width = width + 'px';
  };
  /**
   * 处理键盘事件 上/下
   * @param config
   * 例:
   * {
   *     selectDom: 外容器
   *     keyCode: 键盘code
   *     currentDom: 当前元素
   * }
   */
  var handKeydown = function handKeydown(config) {
    var selectDom = config.selectDom,
      keyCode = config.keyCode,
      currentKeydownDom = config.currentKeydownDom;
    var brotherDom = null;
    var type = 'nextSibling';
    var classSelectStr = '.select-popover-list > div';
    var classGroupStr = '.select-popover-list-item';
    if (keyCode === 38) {
      // 上
      type = 'previousSibling';
      classSelectStr = '.select-popover-list > div:last-child';
      classGroupStr = '.select-popover-list-item:last-child';
    }
    if (!currentKeydownDom) {
      brotherDom = selectDom.querySelector(classSelectStr); // 初始节点
    } else {
      brotherDom = currentKeydownDom[type];
      if (brotherDom) {
        if (brotherDom.className.indexOf('select-popover-list-group-label') !== -1) {
          // 存在标题元素
          brotherDom = currentKeydownDom.parentNode; // 组元素
          brotherDom = brotherDom[type]; // 组元素兄弟节点
          if (!brotherDom) brotherDom = selectDom.querySelector(classSelectStr);
        }
      } else {
        var parentNode = currentKeydownDom.parentNode;
        if (parentNode && parentNode.className && parentNode.className.indexOf('select-popover-list-group') !== -1) {
          // 组元素最后元素, 设置父级兄弟节点, 没有父级,设置最后或者第一节点
          brotherDom = currentKeydownDom.parentNode; // 组元素
          brotherDom = brotherDom[type]; // 组元素兄弟节点
          if (!brotherDom) brotherDom = selectDom.querySelector(classSelectStr);
        } else {
          // 不存在兄弟节点,设置最后一个或第一个
          brotherDom = selectDom.querySelector(classSelectStr);
        }
      }
    }
    if (brotherDom) {
      // 兄弟是组列表
      if (brotherDom.className.indexOf('select-popover-list-group') !== -1) {
        var currentDom = brotherDom.querySelector(classGroupStr);
        if (currentDom) {
          currentDom.classList.add("select-popover-list-item-keydown");
          domClientTop(currentDom, selectDom);
        }
      } else {
        brotherDom.classList.add("select-popover-list-item-keydown");
        domClientTop(brotherDom, selectDom);
      }
    }
  };
  /**
   * 设置当前上下选中的元素是否在当前可见页面里面
   * @param currentDom 当前元素
   * @param selectDom 可见页面
   */
  var domClientTop = function domClientTop(currentDom, selectDom) {
    clearTimeout(constData.scrollTimer);
    var clientHeight = selectDom.clientHeight; // 可见区域的高度
    var top = currentDom.offsetTop + currentDom.clientHeight;
    var difference = top - clientHeight;
    constData.scroll = true;
    if (difference > 0) {
      selectDom.scrollTop = difference;
    } else {
      selectDom.scrollTop = 0;
    }
    // 防止滚动触发hover效果
    constData.scrollTimer = setTimeout(function () {
      constData.scroll = false;
    }, 100);
  };
  /**
   * 键盘事件
   * @param e 键盘信息
   */
  var keydownCom = function keydownCom(e) {
    var selectDom = document.querySelector('.' + classOneSelect + ' .select-popover-list');
    if (!selectDom) return;
    var selectItemDom = selectDom.querySelector('.select-popover-list-item-select');
    var hoverDom = selectDom.querySelector('.select-popover-list-item-hover');
    var keydownDom = selectDom.querySelector('.select-popover-list-item-keydown');
    var currentKeydownDom = selectItemDom; // 选中,hover,keydown元素
    if (hoverDom) currentKeydownDom = hoverDom;
    // 回车
    if (e.keyCode === 13) {
      var operateDom = keydownDom || hoverDom;
      if (operateDom) {
        var val = operateDom.dataset.val;
        clickItem(listJson[val], true)({
          target: keydownDom
        });
      } else {
        onEnter && onEnter(value);
      }
    }
    if (keydownDom) {
      currentKeydownDom = keydownDom;
      keydownDom.classList.remove("select-popover-list-item-keydown");
    }
    // 下
    if (e.keyCode === 40) {
      handKeydown({
        selectDom: selectDom,
        keyCode: e.keyCode,
        currentKeydownDom: currentKeydownDom
      });
    }
    // 上
    if (e.keyCode === 38) {
      handKeydown({
        selectDom: selectDom,
        keyCode: e.keyCode,
        currentKeydownDom: currentKeydownDom
      });
    }
  };
  /**
   * 鼠标移入
   * @param e 移入元素
   */
  var mouseEnter = function mouseEnter(e) {
    if (constData.scroll) return;
    var target = closest(e.target, '.select-popover-list-item');
    if (!target) return;
    target.classList.add("select-popover-list-item-hover");
    // 鼠标移入清除所有keydown
    var selectDom = document.querySelector('.' + classOneSelect);
    var keydownDom = selectDom.querySelector('.select-popover-list-item-keydown');
    if (keydownDom) keydownDom.classList.remove("select-popover-list-item-keydown");
  };
  /**
   * 鼠标移出
   * @param e 移出元素
   */
  var mouseLeave = function mouseLeave(e) {
    var target = closest(e.target, '.select-popover-list-item');
    if (!target) return;
    target.classList.remove("select-popover-list-item-hover");
  };
  // 外标题memo
  var OutLabelMemo = useMemo(function () {
    var bol = Boolean(label || required || labelSign);
    var handLabelClass = function handLabelClass() {
      var str = 'select-label';
      if (labelTooltip && labelTooltip.className) {
        str += ' ' + labelTooltip.className;
      }
      return str;
    };
    return jsx(Fragment, {
      children: labelMode === 'outside' && bol && jsx(Label, Object.assign({
        label: label,
        required: required,
        labelSign: labelSign
      }, labelTooltip, {
        className: handLabelClass()
      }))
    });
  }, [labelMode, label, labelSign, required, labelTooltip]);
  // 内标题memo
  var InsideMemo = useMemo(function () {
    var handInsideContent = function handInsideContent() {
      if (labelMode === 'outside') return placeholder;
      return jsxs(Fragment, {
        children: [label || placeholder, required && jsx("span", Object.assign({
          className: "select-required"
        }, {
          children: "*"
        })), labelSign && jsx("span", {
          children: labelSign
        })]
      });
    };
    return jsx(Fragment, {
      children: !showText && jsx("span", Object.assign({
        className: "select-label-placeholder"
      }, {
        children: handInsideContent()
      }))
    });
  }, [showText, labelMode, placeholder, label, labelSign, required]);
  /**
   * 处理搜索框
   * */
  var handInput = function handInput(type) {
    if (disabled === true) return null;
    var str = "".concat(type, "-search-outside");
    if (searchModel === 'outside') {
      return jsx("input", Object.assign({}, searchInputProps, {
        className: str,
        value: searchValue,
        onChange: changeSearch,
        onKeyDown: onKeyDownSearch,
        ref: textDom
      }));
    }
    return null;
  };
  // 单选内容
  var RadioMemo = useMemo(function () {
    var handContent = function handContent() {
      // 有搜索值且(输入框在内容里面或者有输入赋值)
      if (searchValue !== '' && (searchModel === 'outside' || input)) return null;
      var val = listJson[valueCom[0]] && listJson[valueCom[0]][showName] || valueCom[0];
      var renderContentVal = renderContent && renderContent(listJson[valueCom[0]], false);
      if (overLineCom) return renderContentVal || val;
      return jsx(AutoTips, {
        children: renderContentVal || val
      });
    };
    return jsx(Fragment, {
      children: !multiple && jsxs(Fragment, {
        children: [jsx("div", Object.assign({
          className: "radio-select-content"
        }, {
          children: handContent()
        })), handInput('radio')]
      })
    });
  }, [multiple, showText, overLineCom, listJson, valueCom, showName, search, searchModel, searchValue, disabled, input, searchInputProps, renderContent]);
  // 多选内容
  var CheckMemo = useMemo(function () {
    var handContent = function handContent(index) {
      var val = listJson[valueCom[index]] && listJson[valueCom[index]][showName] || valueCom[index];
      var renderContentVal = renderContent && renderContent(listJson[valueCom[index]], false);
      return renderContentVal || val;
    };
    return jsx(Fragment, {
      children: multiple && jsxs("div", Object.assign({
        className: "check-select-content"
      }, {
        children: [valueCom && valueCom.map(function (item, index) {
          if (morePos !== null && morePos <= index) return null;
          var isClose = true;
          if (disabled === true || _typeof(disabled) === 'object' && disabled.indexOf(valueCom[index]) !== -1) {
            isClose = false; // 禁用不显示×
          }

          return jsxs("div", Object.assign({
            className: isClose ? 'check-select-content-item' : 'check-select-content-item check-select-content-item-noclose'
          }, {
            children: [jsx("span", {
              children: jsx(AutoTips, {
                children: handContent(index)
              })
            }), isClose && jsx(CloseIcon, {
              onClick: delItem(listJson[valueCom[index]], valueCom[index])
            })]
          }), index);
        }), function () {
          if (morePos !== null && valueCom.length > morePos) {
            return jsx("div", Object.assign({
              className: "check-select-content-item check-select-content-item-more",
              onClick: clickMore
            }, {
              children: jsxs("span", {
                children: ["+", valueCom.length - morePos]
              })
            }));
          }
        }(), handInput('check')]
      }))
    });
  }, [multiple, showText, valueCom, morePos, listJson, disabled, onChange, searchValue, search, searchModel, input, searchInputProps, renderContent]);
  var clickClean = function clickClean(e) {
    e.stopPropagation();
    var val = '';
    var valCom = [];
    if (multiple) {
      val = [];
      // 判断多选的时候,有部分数据被禁用,禁用的数据不可删除
      if (disabled instanceof Array) {
        for (var i = 0, l = valueCom.length; i < l; i++) {
          var valueComItem = valueCom[i];
          if (disabled.indexOf(valueComItem) !== -1) {
            val.push(valueComItem);
            valCom.push(valueComItem);
          }
        }
      }
    }
    if (props.value === undefined) {
      setValueCom(valCom);
    }
    onChange && onChange(val, e);
    setOpen(false);
    onClear && onClear();
  };
  // 清空内容
  var clearRender = function clearRender() {
    if (valueCom.length > 0 && disabled !== true && allowClear) {
      return jsx("span", Object.assign({
        className: "clean-up-icon",
        onClick: clickClean
      }, {
        children: jsx(CloseCircle, {})
      }));
    }
  };
  var morePopoverContent = function morePopoverContent() {
    var handContent = function handContent(index) {
      var val = listJson[valueCom[index]] && listJson[valueCom[index]][showName] || valueCom[index];
      var renderContentVal = renderContent && renderContent(listJson[valueCom[index]], false);
      return renderContentVal || val;
    };
    return jsxs("div", Object.assign({
      className: "select-more"
    }, {
      children: [jsxs("div", Object.assign({
        className: "select-more-title"
      }, {
        children: [jsx("span", {
          children: intl({
            id: 'selected'
          })
        }), jsxs("span", {
          children: ["(", valueCom.length - Number(morePos), ")"]
        })]
      })), jsx("div", Object.assign({
        className: "select-more-content"
      }, {
        children: valueCom && valueCom.map(function (item, index) {
          if (morePos !== null && morePos > index) return null;
          var isClose = true;
          if (disabled === true || _typeof(disabled) === 'object' && disabled.indexOf(valueCom[index]) !== -1) {
            isClose = false; // 禁用不显示×
          }

          return jsxs("div", Object.assign({
            className: "select-more-content-item"
          }, {
            children: [jsx("span", {
              children: jsx(AutoTips, {
                children: handContent(index)
              })
            }), isClose && jsx(CloseIcon, {
              onClick: delItem(listJson[valueCom[index]], valueCom[index])
            })]
          }), index);
        })
      }))]
    }));
  };
  // 主体内容
  var ContentMemo = useMemo(function () {
    return jsx(Popover, Object.assign({
      placement: "rightTop",
      visible: openMore,
      content: morePopoverContent(),
      onVisibleChange: handleCloseMore,
      overlayClassName: handleClassMorePopover()
    }, {
      children: jsxs("div", Object.assign({
        className: "select-content",
        onClick: clickSelect,
        ref: posDom
      }, {
        children: [InsideMemo, jsxs("span", Object.assign({
          className: "select-svg"
        }, {
          children: [jsx(Down, {}), clearRender()]
        })), RadioMemo, CheckMemo]
      }))
    }));
  }, [posDom, showText, labelMode, placeholder, label, labelSign, required, overLineCom, listJson, valueCom, showName, multiple, morePos, disabled, onChange, searchValue, searchModel, input, showSelect, searchInputProps, allowClear, onClear, openMore, renderContent]);
  // 下拉框popover 列表
  var SelectPopoverListMemo = useMemo(function () {
    var handClass = function handClass() {
      var str = 'select-popover-list';
      if (loading) str += ' select-popover-list-loading';
      return str;
    };
    var handContent = function handContent(item) {
      var val = item[showName] || item[showValue];
      var renderContentVal = renderContent && renderContent(item, true);
      return jsxs(Fragment, {
        children: [jsx("span", Object.assign({
          className: "select-popover-list-item-label"
        }, {
          children: jsx(AutoTips, {
            children: renderContentVal || val
          })
        })), multiple && selectCheckIcon && jsx("span", Object.assign({
          className: "select-popover-list-item-svg"
        }, {
          children: jsx(Check, {})
        }))]
      });
    };
    return jsxs("div", Object.assign({
      className: handClass(),
      style: {
        outline: '1px  solid transparent'
      }
    }, {
      children: [listCom && listCom.length > 0 ? jsx(Fragment, {
        children: listCom.map(function (item, index) {
          if (item[childrenName] && item[childrenName].length > 0) {
            var childrenList = item[childrenName];
            return jsxs("div", Object.assign({
              className: "select-popover-list-group"
            }, {
              children: [jsx("span", Object.assign({
                className: "select-popover-list-group-label"
              }, {
                children: item[showName] || item[showValue]
              })), childrenList.map(function (childItem, childIndex) {
                var val = childItem[showValue];
                var classStrItem = 'select-popover-list-item';
                if (valueCom.indexOf(val) !== -1) classStrItem += ' select-popover-list-item-select'; // 选中的样式
                if (_typeof(disabled) === 'object' && disabled.indexOf(val) !== -1) {
                  // 禁用
                  classStrItem += ' select-popover-list-item-disabled';
                }
                return jsx("div", Object.assign({
                  onClick: clickItem(childItem),
                  className: classStrItem,
                  onMouseEnter: mouseEnter,
                  onMouseLeave: mouseLeave,
                  "data-val": val
                }, {
                  children: handContent(childItem)
                }), childIndex);
              })]
            }), index);
          }
          var val = item[showValue];
          var classStrItem = 'select-popover-list-item';
          if (valueCom.indexOf(val) !== -1) classStrItem += ' select-popover-list-item-select'; // 选中的样式
          if (_typeof(disabled) === 'object' && disabled.indexOf(val) !== -1) {
            // 禁用
            classStrItem += ' select-popover-list-item-disabled';
          }
          return jsx("div", Object.assign({
            onClick: clickItem(item),
            className: classStrItem,
            onMouseEnter: mouseEnter,
            onMouseLeave: mouseLeave,
            "data-val": val
          }, {
            children: handContent(item)
          }), index);
        })
      }) : !loading && jsx("div", Object.assign({
        className: "select-nodata"
      }, {
        children: jsx(Empty, Object.assign({}, emptyProps, {
          size: (emptyProps === null || emptyProps === void 0 ? void 0 : emptyProps.size) || "small"
        }))
      })), loading && jsx(Loading, {})]
    }));
  }, [listCom, showName, showValue, valueCom, onChange, multiple, loading, language, locale, emptyProps, renderContent, selectCheckIcon]);
  // 下拉框popover memo
  var SelectPopoverMemo = useMemo(function () {
    if (!showSelect) return '';
    var handSelectPopoverMemoClass = function handSelectPopoverMemoClass() {
      var classStr = 'select-popover-content ' + classOneSelect;
      if (search && searchModel === 'inside') classStr += ' select-popover-content-search';
      return classStr;
    };
    return jsxs("div", Object.assign({
      style: {
        width: (posDom && posDom.current ? posDom.current.offsetWidth : 0) + 'px'
      },
      className: handSelectPopoverMemoClass()
    }, {
      children: [search && searchModel === 'inside' && jsxs("div", Object.assign({
        className: "select-popover-search"
      }, {
        children: [jsx("input", Object.assign({}, searchInputProps, {
          placeholder: searchPlaceholder || intl({
            id: 'searchPlaceholder'
          }),
          value: searchValue,
          onChange: changeSearch,
          onKeyDown: onKeyDownSearch,
          ref: textDom
        })), jsx(SearchIcon, {})]
      })), SelectPopoverListMemo]
    }));
  }, [open, posDom, listCom, childrenName, showValue, showName, valueCom, searchValue, search, classOneSelect, searchModel, multiple, searchPlaceholder, showSelect, loading, searchInputProps, language, locale, emptyProps, renderContent, selectCheckIcon]);
  /** 处理下拉内容 */
  var handDropdown = function handDropdown() {
    return jsx(Dropdown, Object.assign({
      visible: open,
      placement: 'bottomLeft',
      trigger: ['click'],
      overlay: jsx(Fragment, {
        children: SelectPopoverMemo
      }),
      overlayClassName: handleClassPopover(),
      getPopupContainer: getPopupContainer,
      onVisibleChange: function onVisibleChange(bol) {
        if (!bol) setOpen(false);
      }
    }, {
      children: ContentMemo
    }));
  };
  return jsxs("div", Object.assign({
    className: handClass(),
    style: style
  }, {
    children: [OutLabelMemo, handDropdown(), jsx(HelperText, {
      className: "select-error-text",
      error: error,
      helperText: helperText,
      hideErrorDom: hideErrorDom
    })]
  }));
};

export { Select as default };
