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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var vue = require('vue');
var input_index = require('../input/index.js');
var popup_index = require('../popup/index.js');
var hooks_useCommonClassName = require('../hooks/useCommonClassName.js');
var hooks_useVModel = require('../hooks/useVModel.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
var autoComplete_optionList = require('./option-list.js');
var autoComplete_props = require('./props.js');
var hooks_tnode = require('../hooks/tnode.js');
require('../utils/withInstall.js');
require('../input/input.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@ldesign/icons-vue-next');
require('lodash/isUndefined');
require('../form/hooks.js');
require('../hooks/useConfig.js');
require('../hooks/useGlobalIcon.js');
require('../input/props.js');
require('../input/useInput.js');
require('../form/const.js');
require('../input/useLengthLimit.js');
require('lodash/isNumber');
require('lodash/isObject');
require('../_common/js/log/log.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/isString');
require('lodash/isNull');
require('lodash/isArray');
require('../input/useInputEventHandler.js');
require('../input/useInputWidth.js');
require('../input/input-group.js');
require('../input/input-group-props.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('dayjs');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('../popup/popup.js');
require('@popperjs/core');
require('../utils/dom.js');
require('../utils/easing.js');
require('../_common/js/utils/set-style.js');
require('../popup/props.js');
require('../popup/container.js');
require('../hooks/useResizeObserver.js');
require('./highlight-option.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);

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__default["default"](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]' && !vue.isVNode(s);
}
var _AutoComplete = vue.defineComponent({
  name: "TAutoComplete",
  props: autoComplete_props["default"],
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var _toRefs = vue.toRefs(props2),
      value = _toRefs.value,
      modelValue = _toRefs.modelValue;
    var _useVModel = hooks_useVModel["default"](value, modelValue, props2.defaultValue, props2.onChange),
      _useVModel2 = _slicedToArray__default["default"](_useVModel, 2),
      tValue = _useVModel2[0],
      setTValue = _useVModel2[1];
    var renderContent = hooks_tnode.useContent();
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var _useCommonClassName = hooks_useCommonClassName["default"](),
      classPrefix = _useCommonClassName.classPrefix,
      sizeClassNames = _useCommonClassName.sizeClassNames;
    var _useConfig = configProvider_useConfig.useConfig("input"),
      global = _useConfig.globalConfig;
    var popupVisible = vue.ref();
    var optionListRef = vue.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 = vue.computed(function () {
      return ["".concat(classPrefix.value, "-auto-complete")];
    });
    var popupClasses = vue.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 = vue.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 = vue.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
      }));
      vue.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") || vue.createVNode(input_index.Input, vue.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 = vue.createVNode(autoComplete_optionList["default"], {
        "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 ? vue.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 vue.createVNode("div", {
        "class": classes.value
      }, [panelContent && vue.createVNode(popup_index.Popup, vue.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]);
    };
  }
});

exports["default"] = _AutoComplete;
//# sourceMappingURL=auto-complete.js.map
