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

import { h as helper } from '../_chunks/dep-c89aafbb.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { defineComponent, toRefs, ref, computed, nextTick } from '@vue/composition-api';
import { Input } from '../input/index.js';
import { Popup } from '../popup/index.js';
import useCommonClassName from '../hooks/useCommonClassName.js';
import useVModel from '../hooks/useVModel.js';
import { useConfig } from '../config-provider/useConfig.js';
import { renderContent, renderTNodeJSX } from '../utils/render-tnode.js';
import AutoCompleteOptionList from './option-list.js';
import props from './props.js';
import '../utils/map-props.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'vue';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import '../input/input.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/typeof';
import '@ldesign/icons-vue';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../_common/js/utils/helper.js';
import 'lodash/isString';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../utils/helper.js';
import '../config-provider/config-receiver.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 '../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../_chunks/dep-67ff4010.js';
import '../config-provider/type.js';
import '../utils/mixins.js';
import '../utils/event.js';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../input/props.js';
import '../input/input-group.js';
import '../input/style';
import '../input/type.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../utils/dom.js';
import 'raf';
import '../utils/easing.js';
import '../_common/js/utils/set-style.js';
import '../popup/props.js';
import '../popup/container.js';
import 'lodash/isFunction';
import '../popup/utils.js';
import '../popup/trigger.js';
import '../popup/style';
import '../popup/type.js';
import '../popup/plugin.js';
import '../hooks/useConfig.js';
import './highlight-option.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 _AutoComplete = defineComponent({
  name: "TAutoComplete",
  props: props,
  setup: function setup(props2, _ref) {
    var emit = _ref.emit;
    var _toRefs = toRefs(props2),
      value = _toRefs.value;
    var _useVModel = useVModel(value, props2.defaultValue, props2.onChange),
      _useVModel2 = _slicedToArray(_useVModel, 2),
      tValue = _useVModel2[0],
      setTValue = _useVModel2[1];
    var _useCommonClassName = useCommonClassName(),
      classPrefix = _useCommonClassName.classPrefix,
      sizeClassNames = _useCommonClassName.sizeClassNames;
    var _useConfig = useConfig("input"),
      global = _useConfig.global;
    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;
      emit("focus", _objectSpread(_objectSpread({}, context), {}, {
        value: value2
      }));
      (_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;
      emit("blur", _objectSpread(_objectSpread({}, context), {}, {
        value: value2
      }));
      (_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;
      emit("compositionend", _objectSpread(_objectSpread({}, context), {}, {
        value: value2
      }));
      (_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;
      emit("compositionstart", _objectSpread(_objectSpread({}, context), {}, {
        value: value2
      }));
      (_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;
      emit("enter", _objectSpread(_objectSpread({}, context), {}, {
        value: value2
      }));
      (_props2$onEnter = props2.onEnter) === null || _props2$onEnter === void 0 ? void 0 : _props2$onEnter.call(props2, _objectSpread(_objectSpread({}, context), {}, {
        value: value2
      }));
    };
    var onInnerClear = function onInnerClear(context) {
      var _props2$onClear;
      emit("clear", context);
      (_props2$onClear = props2.onClear) === null || _props2$onClear === void 0 ? void 0 : _props2$onClear.call(props2, context);
    };
    var inputListeners = computed(function () {
      return {
        change: onInputChange,
        focus: onInnerFocus,
        blur: onInnerBlur,
        compositionend: onInnerCompositionend,
        compositionstart: onInnerCompositionstart,
        enter: onInnerEnter,
        clear: onInnerClear
      };
    });
    var onInnerSelect = function onInnerSelect(value2, context) {
      var _props2$onSelect;
      if (props2.readonly || props2.disabled) return;
      popupVisible.value = false;
      setTValue(value2, context);
      emit("select", 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 {
      global: global,
      classes: classes,
      classPrefix: classPrefix,
      popupClasses: popupClasses,
      popupInnerClasses: popupInnerClasses,
      sizeClassNames: sizeClassNames,
      innerInputProps: innerInputProps,
      inputListeners: inputListeners,
      tValue: tValue,
      popupVisible: popupVisible,
      optionListRef: optionListRef,
      onPopupVisibleChange: onPopupVisibleChange,
      getOverlayStyle: getOverlayStyle,
      onInnerSelect: onInnerSelect
    };
  },
  render: function render() {
    var _this$placeholder, _this$options;
    var h = arguments[0];
    var triggerNode = renderContent(this, "default", "triggerElement") || h(Input, helper([{
      "attrs": {
        "placeholder": (_this$placeholder = this.placeholder) !== null && _this$placeholder !== void 0 ? _this$placeholder : this.global.placeholder
      }
    }, {
      "on": this.inputListeners
    }, {
      "attrs": {
        "tips": this.tips,
        "status": this.status,
        "readonly": this.readonly,
        "disabled": this.disabled,
        "autofocus": this.autofocus,
        "clearable": this.clearable
      }
    }, {
      "props": this.innerInputProps
    }, {
      "scopedSlots": this.$scopedSlots
    }]));
    var listContent = h(AutoCompleteOptionList, {
      "ref": "optionListRef",
      "attrs": {
        "value": this.tValue,
        "options": this.options,
        "size": this.size,
        "sizeClassNames": this.sizeClassNames,
        "popupVisible": this.popupVisible,
        "highlightKeyword": this.highlightKeyword,
        "filterable": this.filterable,
        "filter": this.filter
      },
      "on": {
        "select": this.onInnerSelect
      },
      "scopedSlots": {
        option: this.$scopedSlots.option
      }
    });
    var topContent = renderTNodeJSX(this, "panelTopContent");
    var bottomContent = renderTNodeJSX(this, "panelBottomContent");
    var panelContent = topContent || (_this$options = this.options) !== null && _this$options !== void 0 && _this$options.length || bottomContent ? h("div", {
      "class": "".concat(this.classPrefix, "-autocomplete__panel")
    }, [topContent, listContent, bottomContent]) : null;
    var popupProps = _objectSpread(_objectSpread({}, this.popupProps), {}, {
      overlayInnerStyle: this.getOverlayStyle,
      overlayInnerClassName: this.popupInnerClasses,
      overlayClassName: this.popupClasses
    });
    return h("div", {
      "class": this.classes
    }, [panelContent && h(Popup, helper([{
      "attrs": {
        "visible": this.popupVisible
      }
    }, {
      "on": {
        "visible-change": this.onPopupVisibleChange
      }
    }, {
      "attrs": {
        "trigger": "focus",
        "placement": "bottom-left",
        "hideEmptyPopup": true,
        "content": panelContent ? function () {
          return panelContent;
        } : null
      }
    }, {
      "props": popupProps
    }]), [triggerNode]), !panelContent && triggerNode]);
  }
});

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