/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-1ec74b8b.js';
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import isFunction from 'lodash/isFunction';
import debounce from 'lodash/debounce';
import get from 'lodash/get';
import set from 'lodash/set';
import { CloseCircleFilledIcon } from 'tdesign-icons-vue';
import { Loading } from '../loading/index.js';
import { Popup } from '../popup/index.js';
import mixins from '../utils/mixins.js';
import getConfigReceiverMixins from '../config-provider/config-receiver.js';
import { renderTNodeJSX } from '../utils/render-tnode.js';
import { prefix } from '../config.js';
import ClASSNAMES from '../utils/classnames.js';
import { Input } from '../input/index.js';
import { Tag } from '../tag/index.js';
import FakeArrow from '../common-components/fake-arrow.js';
import _Option from './option.js';
import props from './props.js';
import { emitEvent } from '../utils/event.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../loading/type.js';
import '../loading/plugin.js';
import 'lodash/isObject';
import '../popup/popup.js';
import '@popperjs/core';
import '../utils/helper.js';
import 'lodash/camelCase';
import '../popup/props.js';
import '../popup/container.js';
import '../utils/map-props.js';
import '../popup/type.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';
import '../input/addon.js';
import '../input/input.js';
import 'lodash/kebabCase';
import '../input/props.js';
import '../input/input-group.js';
import '../input/type.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../tag/type.js';
import '../utils/ripple.js';
import './option-props.js';
import '../checkbox/index.js';
import '../checkbox/group.js';
import 'lodash/intersection';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/checkbox-group-props.js';
import '../checkbox/type.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var name = "".concat(prefix, "-select");
var listName = "".concat(name, "__list");
var DEFAULT_MAX_OVERLAY_WIDTH = 500;
var DEFAULT_SCROLLY_WIDTH = 8;
var _Select = mixins(getConfigReceiverMixins("select")).extend({
  name: "TSelect",
  model: {
    prop: "value",
    event: "change"
  },
  props: _objectSpread({}, props),
  data: function data() {
    return {
      formDisabled: void 0,
      isHover: false,
      visible: false,
      searchInput: "",
      showCreateOption: false,
      hasSlotOptions: false,
      defaultProps: {
        trigger: "click",
        placement: "bottom-left",
        overlayClassName: "",
        overlayStyle: {}
      },
      focusing: false,
      labelInValue: this.valueType === "object",
      realValue: this.keys && this.keys.value ? this.keys.value : "value",
      realLabel: this.keys && this.keys.label ? this.keys.label : "label",
      realOptions: [],
      hoverIndex: -1,
      popupOpenTime: 250,
      checkScroll: true,
      isInited: false
    };
  },
  components: {
    CloseCircleFilledIcon: CloseCircleFilledIcon,
    TInput: Input,
    TLoading: Loading,
    Tag: Tag,
    Popup: Popup,
    TOption: _Option,
    FakeArrow: FakeArrow
  },
  provide: function provide() {
    return {
      tSelect: this
    };
  },
  computed: {
    classes: function classes() {
      var _ref;

      return ["".concat(name), "".concat(prefix, "-select-polyfill"), (_ref = {}, _defineProperty(_ref, ClASSNAMES.STATUS.disabled, this.tDisabled), _defineProperty(_ref, ClASSNAMES.STATUS.active, this.visible), _defineProperty(_ref, ClASSNAMES.SIZE[this.size], this.size), _defineProperty(_ref, "".concat(prefix, "-has-prefix"), this.$scopedSlots.prefixIcon), _defineProperty(_ref, "".concat(prefix, "-no-border"), !this.bordered), _ref)];
    },
    popClass: function popClass() {
      var popupObject = this.popupObject;
      return "".concat(popupObject.overlayClassName, " ").concat(name, "__dropdown narrow-scrollbar");
    },
    tipsClass: function tipsClass() {
      return ["".concat(name, "__loading-tips"), _defineProperty({}, ClASSNAMES.SIZE[this.size], this.size)];
    },
    emptyClass: function emptyClass() {
      return ["".concat(name, "__empty"), _defineProperty({}, ClASSNAMES.SIZE[this.size], this.size)];
    },
    tDisabled: function tDisabled() {
      return this.formDisabled || this.disabled;
    },
    showPlaceholder: function showPlaceholder() {
      if (!this.showFilter && (!this.multiple && !this.selectedSingle || !this.multiple && _typeof(this.value) === "object" && !this.selectedSingle || this.multiple && !this.selectedMultiple.length || this.value === null || this.value === void 0)) {
        return true;
      }

      return false;
    },
    isGroupOption: function isGroupOption() {
      var _this$options;

      var firstOption = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options[0];
      return !!(firstOption && "group" in firstOption && "children" in firstOption);
    },
    filterPlaceholder: function filterPlaceholder() {
      if (this.multiple && Array.isArray(this.value) && this.value.length) {
        return "";
      }

      if (!this.multiple && this.selectedSingle) {
        return this.selectedSingle;
      }

      return this.placeholder;
    },
    showClose: function showClose() {
      return Boolean(this.clearable && this.isHover && !this.tDisabled && (!this.multiple && (this.value || this.value === 0) || this.multiple && Array.isArray(this.value) && this.value.length));
    },
    showRightArrow: function showRightArrow() {
      if (!this.showArrow) return false;
      return !this.clearable || !this.isHover || this.tDisabled || !this.multiple && !this.value && this.value !== 0 || this.multiple && (!Array.isArray(this.value) || Array.isArray(this.value) && !this.value.length);
    },
    canFilter: function canFilter() {
      return this.filterable || isFunction(this.filter);
    },
    showLoading: function showLoading() {
      return this.loading && !this.tDisabled;
    },
    showFilter: function showFilter() {
      if (this.tDisabled) return false;

      if (!this.multiple && this.selectedSingle && this.canFilter) {
        return this.visible;
      }

      return this.canFilter;
    },
    selectedSingle: function selectedSingle() {
      var _this = this;

      if (!this.multiple && (typeof this.value === "string" || typeof this.value === "number")) {
        var target = [];

        if (this.realOptions && this.realOptions.length) {
          target = this.realOptions.filter(function (item) {
            return get(item, _this.realValue) === _this.value;
          });
        }

        if (target.length) {
          if (get(target[target.length - 1], this.realLabel) === "") {
            return get(target[target.length - 1], this.realValue);
          }

          return get(target[target.length - 1], this.realLabel);
        }

        return this.value.toString();
      }

      var showText = get(this.value, this.realLabel);

      if (!this.multiple && _typeof(this.value) === "object" && showText !== void 0) {
        return showText === "" ? get(this.value, this.realValue) : showText;
      }

      return "";
    },
    selectedMultiple: function selectedMultiple() {
      var _this2 = this;

      if (this.multiple && Array.isArray(this.value) && this.value.length) {
        return this.value.map(function (item) {
          if (_typeof(item) === "object") {
            return item;
          }

          var tmp = _this2.realOptions.filter(function (op) {
            return get(op, _this2.realValue) === item;
          });

          var valueLabel = {};
          set(valueLabel, _this2.realValue, item);
          set(valueLabel, _this2.realLabel, tmp.length ? get(tmp[tmp.length - 1], _this2.realLabel) : item);
          return tmp.length && tmp[tmp.length - 1].disabled ? _objectSpread(_objectSpread({}, valueLabel), {}, {
            disabled: true
          }) : valueLabel;
        });
      }

      return [];
    },
    popupObject: function popupObject() {
      var propsObject = this.popupProps ? _objectSpread(_objectSpread({}, this.defaultProps), this.popupProps) : this.defaultProps;
      return propsObject;
    },
    filterOptions: function filterOptions() {
      var _this3 = this;

      if (isFunction(this.filter)) {
        return this.realOptions.filter(function (option) {
          return _this3.filter(_this3.searchInput, option);
        });
      }

      if (this.filterable) {
        return this.realOptions.filter(function (option) {
          return option[_this3.realLabel].toString().toLowerCase().indexOf(_this3.searchInput.toString().toLowerCase()) !== -1;
        });
      }

      return [];
    },
    displayOptions: function displayOptions() {
      if (isFunction(this.onSearch) || this.$listeners.search) {
        return this.realOptions;
      }

      if (this.canFilter && !this.creatable) {
        if (this.searchInput === "") {
          return this.realOptions;
        }

        return this.filterOptions;
      }

      return this.realOptions;
    },
    displayOptionsMap: function displayOptionsMap() {
      var map = /* @__PURE__ */new Map();
      this.displayOptions.forEach(function (item) {
        map.set(item, true);
      });
      return map;
    },
    hoverOptions: function hoverOptions() {
      if (!this.showCreateOption) {
        if (isFunction(this.filter) || this.filterable) {
          return this.filterOptions;
        }

        return this.realOptions;
      }

      var willCreateOption = [{
        value: this.searchInput,
        label: this.searchInput
      }];

      if (isFunction(this.filter) || this.filterable) {
        return willCreateOption.concat(this.filterOptions);
      }

      return willCreateOption.concat(this.realOptions);
    }
  },
  watch: {
    showFilter: function showFilter(val) {
      var _this4 = this;

      if (val && this.selectedSingle) {
        this.$nextTick(function () {
          _this4.doFocus();
        });
      }
    },
    searchInput: function searchInput(val) {
      var _this5 = this;

      if (!val && !this.visible) return;

      if (isFunction(this.onSearch) || this.$listeners.search) {
        this.debounceOnRemote();
      }

      if (this.canFilter && val && this.creatable) {
        var tmp = this.realOptions.filter(function (item) {
          return get(item, _this5.realLabel).toString() === val;
        });
        this.showCreateOption = !tmp.length;
      } else {
        this.showCreateOption = false;
      }
    },
    options: {
      immediate: true,
      handler: function handler(options) {
        if (Array.isArray(options)) {
          this.realOptions = this.getRealOptions(options);
        } else {
          console.error("TDesign Select: options must be an array.");
        }
      }
    },
    visible: function visible() {
      this.visible && document.addEventListener("keydown", this.keydownEvent);
      !this.visible && document.removeEventListener("keydown", this.keydownEvent);
      !this.visible && (this.showCreateOption = false);
    }
  },
  methods: {
    getRealOptions: function getRealOptions(options) {
      var result = [];

      if (this.isGroupOption) {
        var arr = [];
        options.forEach(function (item) {
          if ("children" in item) {
            arr = arr.concat(item.children);
          }
        });
        result = arr;
      } else {
        result = _toConsumableArray(options);
      }

      return result.map(function (item) {
        if (_typeof(item) !== "object") return {
          label: item,
          value: item
        };
        return item;
      });
    },
    multiLimitDisabled: function multiLimitDisabled(value) {
      if (this.multiple && this.max) {
        if (Array.isArray(this.value) && this.value.indexOf(value) === -1 && this.max <= this.value.length) {
          return true;
        }
      }

      return false;
    },
    visibleChange: function visibleChange(val) {
      emitEvent(this, "visible-change", val);
      this.visible = val;

      if (!val) {
        this.searchInput = "";
      }

      val && this.monitorWidth();
      val && this.canFilter && this.doFocus();
    },
    onOptionClick: function onOptionClick(value, e) {
      var _this6 = this;

      if (this.value !== value) {
        if (this.multiple) {
          var tempValue = Array.isArray(this.value) ? [].concat(this.value) : [];

          if (this.labelInValue) {
            var index = tempValue.map(function (item) {
              return get(item, _this6.realValue);
            }).indexOf(value);

            if (index > -1) {
              this.removeTag(index, {
                e: e
              });
            } else {
              tempValue.push(this.realOptions.filter(function (item) {
                return get(item, _this6.realValue) === value;
              })[0]);
              this.emitChange(tempValue);
            }
          } else {
            var _index = tempValue.indexOf(value);

            if (_index > -1) {
              this.removeTag(_index, {
                e: e
              });
            } else {
              tempValue.push(value);
              this.emitChange(tempValue);
            }
          }
        } else {
          this.emitChange(value);
        }
      }

      if (!this.multiple) {
        this.searchInput = "";
        this.hideMenu();
      } else {
        if (!this.reserveKeyword) {
          this.searchInput = "";
        }

        this.canFilter && this.doFocus();
      }
    },
    removeTag: function removeTag(index, context) {
      var _this7 = this;

      var _ref4 = context || {},
          e = _ref4.e;

      e === null || e === void 0 ? void 0 : e.stopPropagation();

      if (this.tDisabled) {
        return;
      }

      var val = this.value[index];
      var removeOption = this.realOptions.filter(function (item) {
        return get(item, _this7.realValue) === val;
      });
      var tempValue = Array.isArray(this.value) ? [].concat(this.value) : [];
      tempValue.splice(index, 1);
      this.emitChange(tempValue);
      emitEvent(this, "remove", {
        value: val,
        data: removeOption[0],
        e: e
      });
    },
    hideMenu: function hideMenu() {
      this.visible = false;
      emitEvent(this, "visible-change", false);
    },
    clearSelect: function clearSelect(e) {
      e === null || e === void 0 ? void 0 : e.stopPropagation();

      if (this.multiple) {
        this.emitChange([]);
      } else {
        this.emitChange("");
      }

      this.focusing = false;
      this.searchInput = "";
      this.visible = false;
      emitEvent(this, "clear", {
        e: e
      });
    },
    getOptions: function getOptions(option) {
      var _this8 = this;

      if (option.$el && option.$el.className && option.$el.className.indexOf("".concat(name, "__create-option--special")) !== -1) return;
      var tmp = this.realOptions.filter(function (item) {
        return get(item, _this8.realValue) === option.value && get(item, _this8.realLabel) === option.label;
      });

      if (!tmp.length) {
        this.hasSlotOptions = true;
        var valueLabel = {};
        set(valueLabel, this.realValue, option.value);
        set(valueLabel, this.realLabel, option.label);
        var valueLabelAble = option.disabled ? _objectSpread(_objectSpread({}, valueLabel), {}, {
          disabled: true
        }) : valueLabel;
        this.realOptions.push(valueLabelAble);
      }
    },
    destroyOptions: function destroyOptions(option) {
      var _this9 = this;

      this.realOptions.forEach(function (item, index) {
        if (item[_this9.realValue] === option.value && item[_this9.realLabel] === option.label) {
          _this9.realOptions.splice(index, 1);
        }
      });
    },
    emitChange: function emitChange(val) {
      var _this10 = this;

      var value;

      if (this.labelInValue) {
        if (Array.isArray(val)) {
          if (!val.length) {
            value = [];
          } else {
            value = val;
          }
        } else {
          var target = this.realOptions.filter(function (item) {
            return get(item, _this10.realValue) === val;
          });
          value = target.length ? target[0] : "";
        }
      } else {
        value = val;
      }

      emitEvent(this, "change", value);
    },
    createOption: function createOption(value) {
      emitEvent(this, "create", value);
    },
    debounceOnRemote: debounce(function () {
      emitEvent(this, "search", this.searchInput);
    }, 300),
    focus: function focus(value, context) {
      this.focusing = true;
      emitEvent(this, "focus", {
        value: this.value,
        e: context === null || context === void 0 ? void 0 : context.e
      });
    },
    blur: function blur(value, context) {
      this.focusing = false;
      emitEvent(this, "blur", {
        value: this.value,
        e: context === null || context === void 0 ? void 0 : context.e
      });
    },
    enter: function enter(value, context) {
      emitEvent(this, "enter", {
        inputValue: this.searchInput,
        value: this.value,
        e: context === null || context === void 0 ? void 0 : context.e
      });
    },
    keydownEvent: function keydownEvent(e) {
      if (!this.hoverOptions.length) return;
      var preventKeys = ["ArrowDown", "ArrowUp", "Enter", "Escape", "Tab"];

      if (preventKeys.includes(e.code)) {
        e.preventDefault();
      }

      switch (e.code) {
        case "ArrowDown":
          if (this.hoverIndex === -1) {
            this.initHoverindex();
            return;
          }

          if (this.hoverIndex < this.hoverOptions.length - 1) {
            this.hoverIndex += 1;
            this.arrowDownOption();
          } else {
            this.hoverIndex = 0;
            this.arrowDownOption();
          }

          break;

        case "ArrowUp":
          if (this.hoverIndex === -1) {
            this.initHoverindex();
            return;
          }

          if (this.hoverIndex > 0) {
            this.hoverIndex -= 1;
            this.arrowUpOption();
          } else {
            this.hoverIndex = this.hoverOptions.length - 1;
            this.arrowUpOption();
          }

          break;

        case "Enter":
          if (this.hoverIndex === -1) return;

          if (this.showCreateOption && this.hoverIndex === 0) {
            this.createOption(this.searchInput);
          }

          this.hoverOptions[this.hoverIndex] && this.onOptionClick(this.hoverOptions[this.hoverIndex][this.realValue], e);
          break;

        case "Escape":
        case "Tab":
          this.visible = false;
          emitEvent(this, "visible-change", false);
          this.searchInput = "";

          if (this.focusing) {
            this.blur(this.searchInput, {
              e: e
            });
          }

          break;
      }
    },
    arrowDownOption: function arrowDownOption() {
      var count = 0;

      while (this.hoverIndex < this.hoverOptions.length) {
        if (!this.hoverOptions[this.hoverIndex] || !this.hoverOptions[this.hoverIndex].disabled) {
          break;
        }

        if (this.hoverIndex === this.hoverOptions.length - 1) {
          this.hoverIndex = 0;
        } else {
          this.hoverIndex += 1;
        }

        count += 1;
        if (count >= this.hoverOptions.length) break;
      }
    },
    arrowUpOption: function arrowUpOption() {
      var count = 0;

      while (this.hoverIndex > -1) {
        if (!this.hoverOptions[this.hoverIndex] || !this.hoverOptions[this.hoverIndex].disabled) {
          break;
        }

        if (this.hoverIndex === 0) {
          this.hoverIndex = this.hoverOptions.length - 1;
        } else {
          this.hoverIndex -= 1;
        }

        count += 1;
        if (count >= this.hoverOptions.length) break;
      }
    },
    hoverEvent: function hoverEvent(v) {
      this.isHover = v;
    },
    getOverlayElm: function getOverlayElm() {
      var r;

      try {
        r = this.$refs.popup.$refs.overlay || this.$refs.popup.$refs.component.$refs.overlay;
      } catch (e) {
        console.warn("TDesign Warn:", e);
      }

      return r;
    },
    monitorWidth: function monitorWidth() {
      var _this11 = this;

      this.$nextTick(function () {
        var styles = _this11.popupProps && _this11.popupProps.overlayStyle || {};

        if (_this11.popupProps && isFunction(_this11.popupProps.overlayStyle)) {
          styles = _this11.popupProps.overlayStyle(_this11.$refs.select, _this11.$refs.content) || {};
        }

        if (_typeof(styles) === "object" && !styles.width) {
          var elWidth = _this11.$refs.select.getBoundingClientRect().width;

          var popupWidth = _this11.getOverlayElm().getBoundingClientRect().width;

          var width = elWidth > DEFAULT_MAX_OVERLAY_WIDTH ? elWidth : Math.min(DEFAULT_MAX_OVERLAY_WIDTH, Math.max(elWidth, popupWidth));
          Vue.set(_this11.defaultProps, "overlayStyle", {
            width: "".concat(Math.ceil(width), "px")
          });

          if (_this11.checkScroll) {
            var timer = setTimeout(function () {
              var _this11$getOverlayElm = _this11.getOverlayElm(),
                  scrollHeight = _this11$getOverlayElm.scrollHeight,
                  clientHeight = _this11$getOverlayElm.clientHeight;

              if (scrollHeight > clientHeight) {
                Vue.set(_this11.defaultProps, "overlayStyle", {
                  width: "".concat(Math.ceil(width) + DEFAULT_SCROLLY_WIDTH, "px")
                });
              }

              _this11.checkScroll = false;
              clearTimeout(timer);
            }, _this11.popupOpenTime);
          }
        }
      });
    },
    getEmpty: function getEmpty() {
      var useLocale = !this.empty && !this.$scopedSlots.empty;
      return useLocale ? this.t(this.global.empty) : renderTNodeJSX(this, "empty");
    },
    getLoadingText: function getLoadingText() {
      var useLocale = !this.loadingText && !this.$scopedSlots.loadingText;
      return useLocale ? this.t(this.global.loadingText) : renderTNodeJSX(this, "loadingText");
    },
    getPlaceholderText: function getPlaceholderText() {
      return this.placeholder || this.t(this.global.placeholder);
    },
    getCloseIcon: function getCloseIcon() {
      var h = this.$createElement;
      var closeIconClass = ["".concat(name, "__right-icon"), "".concat(name, "__right-icon-clear"), "".concat(name, "__right-icon-polyfill")];

      if (isFunction(this.global.clearIcon)) {
        return h("span", {
          "class": closeIconClass,
          "on": {
            "click": this.clearSelect
          }
        }, [this.global.clearIcon(this.$createElement)]);
      }

      return h(CloseCircleFilledIcon, {
        "class": closeIconClass,
        "attrs": {
          "size": this.size
        },
        "nativeOn": {
          "click": this.clearSelect
        }
      });
    },
    doFocus: function doFocus() {
      var input = this.$refs.input;
      input === null || input === void 0 ? void 0 : input.focus();
      this.focusing = true;
    },
    renderGroupOptions: function renderGroupOptions(options) {
      var _this12 = this;

      var h = this.$createElement;
      return h("ul", {
        "class": listName
      }, [options.map(function (groupList) {
        var children = groupList.children.filter(function (item) {
          return _this12.displayOptionsMap.get(item);
        });
        return h("t-option-group", {
          "directives": [{
            name: "show",
            value: children.length
          }],
          "attrs": {
            "label": groupList.group,
            "divider": groupList.divider
          }
        }, [_this12.renderOptions(children)]);
      })]);
    },
    renderOptions: function renderOptions(options) {
      var _this13 = this;

      var h = this.$createElement;
      return h("ul", {
        "class": listName
      }, [options.map(function (item, index) {
        return h("t-option", {
          "attrs": {
            "value": get(item, _this13.realValue),
            "label": get(item, _this13.realLabel),
            "content": item.content,
            "disabled": item.disabled || _this13.multiLimitDisabled(get(item, _this13.realValue))
          },
          "key": index
        });
      })]);
    },
    renderDataWithOptions: function renderDataWithOptions() {
      return this.isGroupOption ? this.renderGroupOptions(this.options) : this.renderOptions(this.displayOptions);
    },
    initHoverindex: function initHoverindex() {
      var _this14 = this;

      var ableOptionIndex = Object.keys(this.hoverOptions).filter(function (i) {
        return !_this14.hoverOptions[i].disabled;
      });
      var ableIndex = ableOptionIndex.length ? ableOptionIndex[0] : "0";

      if (!this.multiple && (typeof this.value === "string" || typeof this.value === "number")) {
        var targetIndex = Object.keys(this.hoverOptions).filter(function (i) {
          return get(_this14.hoverOptions[i], _this14.realValue) === _this14.value;
        });
        this.hoverIndex = targetIndex.length ? parseInt(targetIndex[targetIndex.length - 1], 10) : parseInt(ableIndex, 10);
      } else if (this.multiple) {
        this.hoverIndex = parseInt(ableIndex, 10);
        Array.isArray(this.value) && this.value.some(function (item) {
          var targetIndex = Object.keys(_this14.hoverOptions).filter(function (i) {
            return _typeof(item) === "object" && get(_this14.hoverOptions[i], _this14.realValue) === get(item, _this14.realValue) || get(_this14.hoverOptions[i], _this14.realValue) === item;
          });
          _this14.hoverIndex = targetIndex.length ? parseInt(targetIndex[targetIndex.length - 1], 10) : parseInt(ableIndex, 10);
          return _this14.hoverIndex !== -1;
        });
      }
    },
    renderContent: function renderContent() {
      var h = this.$createElement;
      var loading = this.loading,
          showCreateOption = this.showCreateOption,
          displayOptions = this.displayOptions;
      var children = renderTNodeJSX(this, "default");
      var emptySlot = this.getEmpty();
      var loadingTextSlot = this.getLoadingText();
      return h("div", {
        "slot": "content",
        "class": "".concat(name, "__dropdown-inner")
      }, [renderTNodeJSX(this, "panelTopContent"), h("ul", {
        "directives": [{
          name: "show",
          value: showCreateOption
        }],
        "class": ["".concat(name, "__create-option"), listName]
      }, [h("t-option", {
        "attrs": {
          "value": this.searchInput,
          "label": this.searchInput
        },
        "class": "".concat(name, "__create-option--special")
      })]), loading && h("div", {
        "class": this.tipsClass
      }, [loadingTextSlot]), !loading && !displayOptions.length && !showCreateOption && h("div", {
        "class": this.emptyClass
      }, [emptySlot]), !this.hasSlotOptions && displayOptions.length && !loading ? this.renderDataWithOptions() : h("ul", {
        "directives": [{
          name: "show",
          value: !loading && displayOptions.length
        }],
        "class": ["".concat(prefix, "-select__groups"), listName]
      }, [children]), renderTNodeJSX(this, "panelBottomContent")]);
    },
    initOptions: function initOptions() {
      if (this.realOptions.length || this.isInited) return;
      var children = renderTNodeJSX(this, "default");

      if (children) {
        this.realOptions = parseOptions(children);
        this.isInited = true;
        this.hasSlotOptions = true;
      }

      function parseOptions(vnodes) {
        if (!vnodes) return [];
        return vnodes.reduce(function (options, vnode) {
          var componentOptions = vnode.componentOptions;

          if ((componentOptions === null || componentOptions === void 0 ? void 0 : componentOptions.tag) === "t-option") {
            var propsData = componentOptions.propsData;
            return options.concat({
              label: propsData.label,
              value: propsData.value,
              disabled: propsData.disabled,
              content: componentOptions.children ? function () {
                return componentOptions.children;
              } : propsData.content,
              "default": propsData["default"]
            });
          }

          if ((componentOptions === null || componentOptions === void 0 ? void 0 : componentOptions.tag) === "t-option-group") {
            return options.concat(parseOptions(componentOptions.children));
          }

          return options;
        }, []);
      }
    }
  },
  mounted: function mounted() {
    this.initOptions();
  },
  updated: function updated() {
    this.initOptions();
  },
  render: function render() {
    var _this15 = this;

    var h = arguments[0];
    var classes = this.classes,
        popupObject = this.popupObject,
        tDisabled = this.tDisabled,
        popClass = this.popClass,
        size = this.size,
        showPlaceholder = this.showPlaceholder,
        selectedMultiple = this.selectedMultiple,
        multiple = this.multiple,
        showFilter = this.showFilter,
        selectedSingle = this.selectedSingle,
        filterPlaceholder = this.filterPlaceholder,
        realLabel = this.realLabel;
    var prefixIconSlot = renderTNodeJSX(this, "prefixIcon");
    var placeholderText = this.getPlaceholderText();
    return h("div", {
      "ref": "select",
      "class": "".concat(name, "__wrap")
    }, [h(Popup, helper([{
      "ref": "popup",
      "attrs": {
        "visible": this.visible,
        "disabled": tDisabled
      },
      "class": "".concat(name, "__popup-reference")
    }, {
      "on": {
        "visible-change": this.visibleChange
      }
    }, {
      "attrs": {
        "expandAnimation": true
      },
      "props": _objectSpread({}, _objectSpread(_objectSpread({}, popupObject), {}, {
        overlayClassName: popClass
      }))
    }]), [h("div", {
      "class": classes,
      "on": {
        "mouseenter": this.hoverEvent.bind(null, true),
        "mouseleave": this.hoverEvent.bind(null, false)
      }
    }, [prefixIconSlot && h("span", {
      "class": "".concat(name, "__left-icon")
    }, [prefixIconSlot[0]]), showPlaceholder && h("span", {
      "class": "".concat(name, "__placeholder")
    }, [" ", placeholderText]), this.valueDisplay || this.$scopedSlots.valueDisplay ? renderTNodeJSX(this, "valueDisplay", {
      params: {
        value: selectedMultiple,
        onClose: function onClose(index) {
          return _this15.removeTag(index);
        }
      }
    }) : selectedMultiple.map(function (item, index) {
      return h("tag", {
        "directives": [{
          name: "show",
          value: _this15.minCollapsedNum <= 0 || index < _this15.minCollapsedNum
        }],
        "key": index,
        "attrs": {
          "size": size,
          "closable": !item.disabled && !tDisabled,
          "disabled": tDisabled,
          "maxWidth": "100%",
          "title": get(item, realLabel)
        },
        "style": "max-width: 100%;",
        "on": {
          "close": _this15.removeTag.bind(null, index)
        }
      }, [get(item, realLabel)]);
    }), this.collapsedItems || this.$scopedSlots.collapsedItems ? renderTNodeJSX(this, "collapsedItems", {
      params: {
        value: selectedMultiple,
        collapsedSelectedItems: selectedMultiple.slice(this.minCollapsedNum),
        count: selectedMultiple.length - this.minCollapsedNum
      }
    }) : h("tag", {
      "directives": [{
        name: "show",
        value: this.minCollapsedNum > 0 && selectedMultiple.length > this.minCollapsedNum
      }],
      "attrs": {
        "size": size
      }
    }, ["+".concat(selectedMultiple.length - this.minCollapsedNum)]), !multiple && !showPlaceholder && !showFilter && h("span", {
      "attrs": {
        "title": selectedSingle
      },
      "class": "".concat(name, "__single")
    }, [selectedSingle]), showFilter && h("t-input", {
      "ref": "input",
      "attrs": {
        "size": size,
        "placeholder": filterPlaceholder,
        "disabled": tDisabled,
        "readonly": !this.visible || !this.showFilter
      },
      "class": "".concat(name, "__input"),
      "on": {
        "focus": this.focus,
        "blur": this.blur,
        "enter": this.enter
      },
      "model": {
        value: _this15.searchInput,
        callback: function callback($$v) {
          _this15.searchInput = $$v;
        }
      }
    }), this.showRightArrow && !this.showLoading && h("fake-arrow", {
      "attrs": {
        "overlayClassName": "".concat(name, "__right-icon ").concat(name, "__right-icon-polyfill"),
        "isActive": this.visible && !this.tDisabled
      }
    }), this.showClose && !this.showLoading && this.getCloseIcon(), this.showLoading && h("t-loading", {
      "class": "".concat(name, "__right-icon ").concat(name, "__active-icon ").concat(name, "__right-icon-polyfill"),
      "attrs": {
        "size": "small"
      }
    })]), this.renderContent()])]);
  }
});

export { _Select as default };
//# sourceMappingURL=select.js.map
