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

import { _ as _defineProperty } from '../_chunks/dep-2db7b3ec.mjs';
import { _ as _slicedToArray } from '../_chunks/dep-84acf3c2.mjs';
import { isVNode, defineComponent, toRefs, ref, computed, nextTick, createVNode, mergeProps } from 'vue';
import { Input } from '../input/index.mjs';
import { Popup } from '../popup/index.mjs';
import useCommonClassName from '../hooks/useCommonClassName.mjs';
import useVModel from '../hooks/useVModel.mjs';
import { useConfig } from '../config-provider/useConfig.mjs';
import '../hooks/index.mjs';
import AutoCompleteOptionList from './option-list.mjs';
import props from './props.mjs';
import { useContent, useTNodeJSX } from '../hooks/tnode.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-b8d7992c.mjs';
import '../utils/withInstall.mjs';
import '../input/input.mjs';
import '../_chunks/dep-60fae668.mjs';
import '@ldesign/icons-vue-next';
import '../_chunks/dep-78847b2e.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import '../form/hooks.mjs';
import '../hooks/useConfig.mjs';
import '../hooks/useGlobalIcon.mjs';
import '../input/props.mjs';
import '../input/useInput.mjs';
import '../form/const.mjs';
import '../input/useLengthLimit.mjs';
import '../_chunks/dep-3f21269a.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../_chunks/dep-a8bcacea.mjs';
import '../_common/js/log/index.mjs';
import '../_common/js/log/log.mjs';
import '../_common/js/utils/helper.mjs';
import '../_chunks/dep-bf1e33c8.mjs';
import '../_chunks/dep-876fb3ec.mjs';
import '../_chunks/dep-b57180d0.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-ed5ebb35.mjs';
import '../input/useInputEventHandler.mjs';
import '../input/useInputWidth.mjs';
import '../input/input-group.mjs';
import '../input/input-group-props.mjs';
import '../input/style/css.mjs';
import '../input/type.mjs';
import '../_chunks/dep-095107f7.mjs';
import '../_chunks/dep-c989dff3.mjs';
import '../_chunks/dep-9cf86cf1.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-5717e263.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-40d69a9c.mjs';
import '../_chunks/dep-dcc83161.mjs';
import '../_chunks/dep-0fc02184.mjs';
import '../_chunks/dep-f1994936.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 '../_chunks/dep-406cd044.mjs';
import '../_chunks/dep-42cc3015.mjs';
import '../_chunks/dep-2bc37d52.mjs';
import '../_chunks/dep-327559e8.mjs';
import '../_chunks/dep-b2235f26.mjs';
import '../_chunks/dep-8b989474.mjs';
import '../_chunks/dep-1372b2d3.mjs';
import '../_chunks/dep-9a85dac1.mjs';
import '../utils/render-tnode.mjs';
import '../_chunks/dep-888e80c4.mjs';
import '../hooks/icon.mjs';
import '../hooks/slot.mjs';
import '../hooks/useDefaultValue.mjs';
import '../hooks/useDestroyOnClose.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useVirtualScroll.mjs';
import '../popup/popup.mjs';
import '@popperjs/core';
import '../utils/dom.mjs';
import '../utils/easing.mjs';
import '../_common/js/utils/set-style.mjs';
import '../popup/props.mjs';
import '../popup/container.mjs';
import '../hooks/useResizeObserver.mjs';
import '../popup/style/css.mjs';
import '../popup/type.mjs';
import './highlight-option.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 _AutoComplete = defineComponent({
  name: "TAutoComplete",
  props: props,
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var _toRefs = toRefs(props2),
      value = _toRefs.value,
      modelValue = _toRefs.modelValue;
    var _useVModel = useVModel(value, modelValue, props2.defaultValue, props2.onChange),
      _useVModel2 = _slicedToArray(_useVModel, 2),
      tValue = _useVModel2[0],
      setTValue = _useVModel2[1];
    var renderContent = useContent();
    var renderTNodeJSX = useTNodeJSX();
    var _useCommonClassName = useCommonClassName(),
      classPrefix = _useCommonClassName.classPrefix,
      sizeClassNames = _useCommonClassName.sizeClassNames;
    var _useConfig = useConfig("input"),
      global = _useConfig.globalConfig;
    var popupVisible = ref();
    var optionListRef = ref();
    var getOverlayStyle = function getOverlayStyle(trigger, popupElement) {
      var _props2$popupProps;
      var triggerWidth = trigger.getBoundingClientRect().width || trigger.offsetWidth || trigger.clientWidth;
      var popupWidth = popupElement.getBoundingClientRect().width || popupElement.offsetWidth || popupElement.clientWidth;
      return _objectSpread({
        width: triggerWidth >= popupWidth ? "".concat(triggerWidth, "px") : "auto"
      }, (_props2$popupProps = props2.popupProps) === null || _props2$popupProps === void 0 ? void 0 : _props2$popupProps.overlayInnerStyle);
    };
    var classes = computed(function () {
      return ["".concat(classPrefix.value, "-auto-complete")];
    });
    var popupClasses = computed(function () {
      var _props2$popupProps2;
      var classes2 = ["".concat(classPrefix.value, "-select__dropdown")];
      if ((_props2$popupProps2 = props2.popupProps) !== null && _props2$popupProps2 !== void 0 && _props2$popupProps2.overlayClassName) classes2 = classes2.concat(props2.popupProps.overlayClassName);
      return classes2;
    });
    var popupInnerClasses = computed(function () {
      var _props2$popupProps3;
      var classes2 = ["".concat(classPrefix.value, "-select__dropdown-inner")];
      if ((_props2$popupProps3 = props2.popupProps) !== null && _props2$popupProps3 !== void 0 && _props2$popupProps3.overlayInnerClassName) classes2 = classes2.concat(props2.popupProps.overlayInnerClassName);
      return classes2;
    });
    var onInputChange = function onInputChange(value2, context) {
      setTValue(value2, context);
    };
    var innerInputProps = computed(function () {
      var tProps = _objectSpread({
        value: tValue.value,
        size: props2.size
      }, props2.inputProps);
      return tProps;
    });
    var onInnerFocus = function onInnerFocus(value2, context) {
      var _props2$onFocus;
      popupVisible.value = true;
      (_props2$onFocus = props2.onFocus) === null || _props2$onFocus === void 0 ? void 0 : _props2$onFocus.call(props2, _objectSpread(_objectSpread({}, context), {}, {
        value: value2
      }));
      nextTick(function () {
        var _optionListRef$value;
        (_optionListRef$value = optionListRef.value) === null || _optionListRef$value === void 0 ? void 0 : _optionListRef$value.addKeyboardListener();
      });
    };
    var onInnerBlur = function onInnerBlur(value2, context) {
      var _props2$onBlur;
      (_props2$onBlur = props2.onBlur) === null || _props2$onBlur === void 0 ? void 0 : _props2$onBlur.call(props2, _objectSpread(_objectSpread({}, context), {}, {
        value: value2
      }));
    };
    var onInnerCompositionend = function onInnerCompositionend(value2, context) {
      var _props2$onComposition;
      (_props2$onComposition = props2.onCompositionend) === null || _props2$onComposition === void 0 ? void 0 : _props2$onComposition.call(props2, _objectSpread(_objectSpread({}, context), {}, {
        value: value2
      }));
    };
    var onInnerCompositionstart = function onInnerCompositionstart(value2, context) {
      var _props2$onComposition2;
      (_props2$onComposition2 = props2.onCompositionstart) === null || _props2$onComposition2 === void 0 ? void 0 : _props2$onComposition2.call(props2, _objectSpread(_objectSpread({}, context), {}, {
        value: value2
      }));
    };
    var onInnerEnter = function onInnerEnter(value2, context) {
      var _props2$onEnter;
      (_props2$onEnter = props2.onEnter) === null || _props2$onEnter === void 0 ? void 0 : _props2$onEnter.call(props2, _objectSpread(_objectSpread({}, context), {}, {
        value: value2
      }));
    };
    var onInnerSelect = function onInnerSelect(value2, context) {
      var _props2$onSelect;
      if (props2.readonly || props2.disabled) return;
      popupVisible.value = false;
      setTValue(value2, context);
      (_props2$onSelect = props2.onSelect) === null || _props2$onSelect === void 0 ? void 0 : _props2$onSelect.call(props2, value2, context);
    };
    var onPopupVisibleChange = function onPopupVisibleChange(visible, _ref2) {
      var trigger = _ref2.trigger;
      if (trigger !== "trigger-element-click") popupVisible.value = visible;
    };
    return function () {
      var _props2$placeholder, _props2$options;
      var triggerNode = renderContent("default", "triggerElement") || createVNode(Input, mergeProps({
        "placeholder": (_props2$placeholder = props2.placeholder) !== null && _props2$placeholder !== void 0 ? _props2$placeholder : global.value.placeholder,
        "tips": props2.tips,
        "status": props2.status,
        "readonly": props2.readonly,
        "disabled": props2.disabled,
        "autofocus": props2.autofocus,
        "clearable": props2.clearable,
        "onChange": onInputChange,
        "onFocus": onInnerFocus,
        "onBlur": onInnerBlur,
        "onClear": props2.onClear,
        "onCompositionend": onInnerCompositionend,
        "onCompositionstart": onInnerCompositionstart,
        "onEnter": onInnerEnter
      }, innerInputProps.value), slots);
      var listContent = createVNode(AutoCompleteOptionList, {
        "ref": optionListRef,
        "value": tValue.value,
        "options": props2.options,
        "size": props2.size,
        "sizeClassNames": sizeClassNames,
        "onSelect": onInnerSelect,
        "popupVisible": popupVisible.value,
        "highlightKeyword": props2.highlightKeyword,
        "filterable": props2.filterable,
        "filter": props2.filter
      }, {
        option: slots.option
      });
      var topContent = renderTNodeJSX("panelTopContent");
      var bottomContent = renderTNodeJSX("panelBottomContent");
      var panelContent = topContent || (_props2$options = props2.options) !== null && _props2$options !== void 0 && _props2$options.length || bottomContent ? createVNode("div", {
        "class": "".concat(classPrefix.value, "-autocomplete__panel")
      }, [topContent, listContent, bottomContent]) : null;
      var popupProps = _objectSpread(_objectSpread({}, props2.popupProps), {}, {
        overlayInnerStyle: getOverlayStyle,
        overlayInnerClassName: popupInnerClasses.value,
        overlayClassName: popupClasses.value
      });
      return createVNode("div", {
        "class": classes.value
      }, [panelContent && createVNode(Popup, mergeProps({
        "visible": popupVisible.value,
        "onVisibleChange": onPopupVisibleChange,
        "trigger": "focus",
        "placement": "bottom-left",
        "hideEmptyPopup": true,
        "content": panelContent ? function () {
          return panelContent;
        } : null
      }, popupProps), _isSlot(triggerNode) ? triggerNode : {
        "default": function _default() {
          return [triggerNode];
        }
      }), !panelContent && triggerNode]);
    };
  }
});

export { _AutoComplete as default };
//# sourceMappingURL=auto-complete.mjs.map
