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

'use strict';

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

var helper = require('../_chunks/dep-c3e1ffac.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var VueCompositionAPI = require('@vue/composition-api');
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 utils_renderTnode = require('../utils/render-tnode.js');
var autoComplete_optionList = require('./option-list.js');
var autoComplete_props = require('./props.js');
require('../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('vue');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../input/input.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/typeof');
require('@ldesign/icons-vue');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../_common/js/utils/helper.js');
require('lodash/isString');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('../utils/helper.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/mixins.js');
require('../utils/event.js');
require('../_common/js/log/log.js');
require('../input/props.js');
require('../input/input-group.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../utils/dom.js');
require('raf');
require('../utils/easing.js');
require('../_common/js/utils/set-style.js');
require('../popup/props.js');
require('../popup/container.js');
require('lodash/isFunction');
require('../popup/utils.js');
require('../popup/trigger.js');
require('../popup/plugin.js');
require('../hooks/useConfig.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; }
var _AutoComplete = VueCompositionAPI.defineComponent({
  name: "TAutoComplete",
  props: autoComplete_props["default"],
  setup: function setup(props2, _ref) {
    var emit = _ref.emit;
    var _toRefs = VueCompositionAPI.toRefs(props2),
      value = _toRefs.value;
    var _useVModel = hooks_useVModel["default"](value, props2.defaultValue, props2.onChange),
      _useVModel2 = _slicedToArray__default["default"](_useVModel, 2),
      tValue = _useVModel2[0],
      setTValue = _useVModel2[1];
    var _useCommonClassName = hooks_useCommonClassName["default"](),
      classPrefix = _useCommonClassName.classPrefix,
      sizeClassNames = _useCommonClassName.sizeClassNames;
    var _useConfig = configProvider_useConfig.useConfig("input"),
      global = _useConfig.global;
    var popupVisible = VueCompositionAPI.ref();
    var optionListRef = VueCompositionAPI.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 = VueCompositionAPI.computed(function () {
      return ["".concat(classPrefix.value, "-auto-complete")];
    });
    var popupClasses = VueCompositionAPI.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 = VueCompositionAPI.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 = VueCompositionAPI.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
      }));
      VueCompositionAPI.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 = VueCompositionAPI.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 = utils_renderTnode.renderContent(this, "default", "triggerElement") || h(input_index.Input, helper.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(autoComplete_optionList["default"], {
      "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 = utils_renderTnode.renderTNodeJSX(this, "panelTopContent");
    var bottomContent = utils_renderTnode.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_index.Popup, helper.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]);
  }
});

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