/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _defineProperty } from '../_chunks/dep-2db7b3ec.mjs';
import { isVNode, defineComponent, inject, ref, computed, createVNode, mergeProps } from 'vue';
import { i as isFunction_1 } from '../_chunks/dep-5717e263.mjs';
import { o as omit_1 } from '../_chunks/dep-350764bc.mjs';
import { useTNodeJSX, useTNodeDefault } from '../hooks/tnode.mjs';
import { usePrefixClass } from '../hooks/useConfig.mjs';
import _Option from './option.mjs';
import _OptionGroup from './optionGroup.mjs';
import props from './props.mjs';
import { usePanelVirtualScroll } from './hooks/usePanelVirtualScroll.mjs';
import { selectInjectKey } from './helper.mjs';
import { useConfig } from '../config-provider/useConfig.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-a8bcacea.mjs';
import '../_chunks/dep-42cc3015.mjs';
import '../_chunks/dep-b57180d0.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-2bc37d52.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../_chunks/dep-c989dff3.mjs';
import '../_chunks/dep-9cf86cf1.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-855db8bc.mjs';
import '../_chunks/dep-a87f3e4c.mjs';
import '../_chunks/dep-1e566bb5.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-42a19209.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-8d3e9aa3.mjs';
import '../_chunks/dep-0d3dd4b5.mjs';
import '../_chunks/dep-8b989474.mjs';
import '../_chunks/dep-f1994936.mjs';
import '../_chunks/dep-6884627f.mjs';
import '../_chunks/dep-0fc02184.mjs';
import '../_chunks/dep-406cd044.mjs';
import '../_chunks/dep-327559e8.mjs';
import '../_chunks/dep-b2235f26.mjs';
import '../_chunks/dep-1372b2d3.mjs';
import '../_chunks/dep-9a85dac1.mjs';
import '../utils/render-tnode.mjs';
import '../_chunks/dep-888e80c4.mjs';
import '../_chunks/dep-876fb3ec.mjs';
import '../_chunks/dep-095107f7.mjs';
import '../_chunks/dep-40d69a9c.mjs';
import '../_chunks/dep-dcc83161.mjs';
import '../_chunks/dep-345e1be3.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-9888611c.mjs';
import '../_chunks/dep-697a1365.mjs';
import '../config-provider/type.mjs';
import '../checkbox/index.mjs';
import '../utils/withInstall.mjs';
import '../checkbox/checkbox.mjs';
import '../_chunks/dep-84acf3c2.mjs';
import '../_chunks/dep-b8d7992c.mjs';
import '../hooks/useVModel.mjs';
import '../form/hooks.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../checkbox/props.mjs';
import '../checkbox/constants.mjs';
import '../checkbox/group.mjs';
import '../_chunks/dep-bf1e33c8.mjs';
import '../_chunks/dep-85ed244c.mjs';
import '../_chunks/dep-c42916c7.mjs';
import '../_chunks/dep-78847b2e.mjs';
import '../hooks/slot.mjs';
import '../checkbox/checkbox-group-props.mjs';
import '../checkbox/style/css.mjs';
import '../checkbox/type.mjs';
import './option-props.mjs';
import './option-group-props.mjs';
import '../hooks/useVirtualScroll.mjs';

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; }
function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
}
var SelectPanel = defineComponent({
  name: "TSelectPanel",
  props: {
    inputValue: props.inputValue,
    panelTopContent: props.panelTopContent,
    panelBottomContent: props.panelBottomContent,
    empty: props.empty,
    creatable: props.creatable,
    loading: props.loading,
    loadingText: props.loadingText,
    multiple: props.multiple,
    filterable: props.filterable,
    filter: props.filter,
    options: {
      type: Array,
      "default": function _default() {
        return [];
      }
    },
    scroll: props.scroll
  },
  setup: function setup(props, _ref) {
    var expose = _ref.expose;
    var COMPONENT_NAME = usePrefixClass("select");
    var renderTNodeJSX = useTNodeJSX();
    var renderDefaultTNode = useTNodeDefault();
    var _useConfig = useConfig("select"),
      t = _useConfig.t,
      globalConfig = _useConfig.globalConfig;
    var tSelect = inject(selectInjectKey);
    var innerRef = ref(null);
    var popupContentRef = computed(function () {
      return tSelect.value.popupContentRef.value;
    });
    var showCreateOption = computed(function () {
      return props.creatable && props.filterable && props.inputValue;
    });
    var displayOptions = computed(function () {
      if (!props.inputValue || !(props.filterable || isFunction_1(props.filter))) return props.options;
      var filterMethods = function filterMethods(option) {
        var _option$label, _option$label$toLower;
        if (isFunction_1(props.filter)) return props.filter("".concat(props.inputValue), option);
        return ((_option$label = option.label) === null || _option$label === void 0 ? void 0 : (_option$label$toLower = _option$label.toLowerCase) === null || _option$label$toLower === void 0 ? void 0 : _option$label$toLower.call(_option$label).indexOf("".concat(props.inputValue).toLowerCase())) > -1;
      };
      var res = [];
      props.options.forEach(function (option) {
        if (option.group && option.children) {
          res.push(_objectSpread(_objectSpread({}, option), {}, {
            children: option.children.filter(filterMethods)
          }));
        }
        if (filterMethods(option)) res.push(option);
      });
      return res;
    });
    var _usePanelVirtualScrol = usePanelVirtualScroll({
        scroll: props.scroll,
        popupContentRef: popupContentRef,
        options: displayOptions
      }),
      trs = _usePanelVirtualScrol.trs,
      visibleData = _usePanelVirtualScrol.visibleData,
      handleRowMounted = _usePanelVirtualScrol.handleRowMounted,
      isVirtual = _usePanelVirtualScrol.isVirtual,
      panelStyle = _usePanelVirtualScrol.panelStyle,
      cursorStyle = _usePanelVirtualScrol.cursorStyle;
    var isEmpty = computed(function () {
      return !displayOptions.value.length;
    });
    var renderCreateOption = function renderCreateOption() {
      return createVNode("ul", {
        "class": ["".concat(COMPONENT_NAME.value, "__create-option"), "".concat(COMPONENT_NAME.value, "__list")]
      }, [createVNode(_Option, {
        "value": props.inputValue,
        "label": "".concat(props.inputValue),
        "createAble": true,
        "class": "".concat(COMPONENT_NAME.value, "__create-option--special")
      }, null)]);
    };
    var renderOptionsContent = function renderOptionsContent(options) {
      return createVNode("ul", {
        "class": "".concat(COMPONENT_NAME.value, "__list")
      }, [options.map(function (item, index) {
        var _props$scroll, _props$scroll2;
        if (item.group) {
          var _slot;
          return createVNode(_OptionGroup, {
            "label": item.group,
            "divider": item.divider
          }, _isSlot(_slot = renderOptionsContent(item.children)) ? _slot : {
            "default": function _default() {
              return [_slot];
            }
          });
        }
        return createVNode(_Option, mergeProps(omit_1(item, "$index"), isVirtual.value ? {
          rowIndex: item.$index,
          trs: trs,
          scrollType: (_props$scroll = props.scroll) === null || _props$scroll === void 0 ? void 0 : _props$scroll.type,
          isVirtual: isVirtual.value,
          bufferSize: (_props$scroll2 = props.scroll) === null || _props$scroll2 === void 0 ? void 0 : _props$scroll2.bufferSize,
          key: "".concat(item.$index || "", "_").concat(index)
        } : {
          key: index
        }, {
          "multiple": props.multiple,
          "onRowMounted": handleRowMounted
        }), item.slots);
      })]);
    };
    var dropdownInnerSize = computed(function () {
      return {
        small: "s",
        medium: "m",
        large: "l"
      }[tSelect.value.size];
    });
    expose({
      innerRef: innerRef
    });
    var renderPanel = function renderPanel(options, extraStyle) {
      return createVNode("div", {
        "ref": innerRef,
        "class": ["".concat(COMPONENT_NAME.value, "__dropdown-inner"), "".concat(COMPONENT_NAME.value, "__dropdown-inner--size-").concat(dropdownInnerSize.value)],
        "onClick": function onClick(e) {
          return e.stopPropagation();
        },
        "style": extraStyle
      }, [renderTNodeJSX("panelTopContent"), showCreateOption.value && renderCreateOption(), props.loading && renderDefaultTNode("loadingText", {
        defaultNode: createVNode("div", {
          "class": "".concat(COMPONENT_NAME.value, "__loading-tips")
        }, [t(globalConfig.value.loadingText)])
      }), !props.loading && isEmpty.value && !showCreateOption.value && renderDefaultTNode("empty", {
        defaultNode: createVNode("div", {
          "class": "".concat(COMPONENT_NAME.value, "__empty")
        }, [t(globalConfig.value.empty)])
      }), !isEmpty.value && !props.loading && renderOptionsContent(options), renderTNodeJSX("panelBottomContent")]);
    };
    return {
      renderPanel: renderPanel,
      panelStyle: panelStyle,
      cursorStyle: cursorStyle,
      isVirtual: isVirtual,
      displayOptions: displayOptions,
      visibleData: visibleData
    };
  },
  render: function render() {
    return this.isVirtual ? createVNode("div", null, [createVNode("div", {
      "style": this.cursorStyle
    }, null), this.renderPanel(this.visibleData, this.panelStyle)]) : this.renderPanel(this.displayOptions);
  }
});

export { SelectPanel as default };
//# sourceMappingURL=select-panel.mjs.map
