'use strict';

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

var vue = require('vue');
require('../select/index.js');
require('../hooks/index.js');
var omit = require('../_util/omit.js');
var warning = require('../_util/warning.js');
var index$1 = require('../_util/props-util/index.js');
var Option = require('./Option.js');
var OptGroup = require('./OptGroup.js');
var props = require('../select/props.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');
var select = require('../select/select.js');

function _isSlot(s) {
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
}
function isSelectOptionOrSelectOptGroup(child) {
  var _a, _b;
  return ((_a = child == null ? void 0 : child.type) == null ? void 0 : _a.isSelectOption) || ((_b = child == null ? void 0 : child.type) == null ? void 0 : _b.isSelectOptGroup);
}
const autoCompleteProps = () => ({
  ...omit.default(props.selectProps(), ["loading", "mode", "optionLabelProp", "labelInValue"]),
  dataSource: Array,
  dropdownMenuStyle: {
    type: Object,
    default: void 0
  },
  // optionLabelProp: String,
  dropdownMatchSelectWidth: {
    type: [Number, Boolean],
    default: true
  },
  prefixCls: String,
  showSearch: {
    type: Boolean,
    default: void 0
  },
  transitionName: String,
  choiceTransitionName: {
    type: String,
    default: "zoom"
  },
  autofocus: {
    type: Boolean,
    default: void 0
  },
  backfill: {
    type: Boolean,
    default: void 0
  },
  // optionLabelProp: PropTypes.string.def('children'),
  filterOption: {
    type: [Boolean, Function],
    default: false
  },
  defaultActiveFirstOption: {
    type: Boolean,
    default: true
  },
  status: String
});
const AutoCompleteOption = Option.default;
const AutoCompleteOptGroup = OptGroup.default;
const AutoComplete = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AAutoComplete",
  inheritAttrs: false,
  props: autoCompleteProps(),
  // emits: ['change', 'select', 'focus', 'blur'],
  slots: Object,
  setup(props, {
    slots,
    attrs,
    expose
  }) {
    warning.default(!("dataSource" in slots), "AutoComplete", "`dataSource` slot is deprecated, please use props `options` instead.");
    warning.default(!("options" in slots), "AutoComplete", "`options` slot is deprecated, please use props `options` instead.");
    warning.default(!props.dropdownClassName, "AutoComplete", "`dropdownClassName` is deprecated, please use `popupClassName` instead.");
    const selectRef = vue.ref();
    const getInputElement = () => {
      var _a;
      const children = index$1.flattenChildren((_a = slots.default) == null ? void 0 : _a.call(slots));
      const element = children.length ? children[0] : void 0;
      return element;
    };
    const focus = () => {
      var _a;
      (_a = selectRef.value) == null ? void 0 : _a.focus();
    };
    const blur = () => {
      var _a;
      (_a = selectRef.value) == null ? void 0 : _a.blur();
    };
    expose({
      focus,
      blur
    });
    const {
      prefixCls
    } = useConfigInject.default("select", props);
    return () => {
      var _a, _b, _c;
      const {
        size,
        dataSource,
        notFoundContent = (_a = slots.notFoundContent) == null ? void 0 : _a.call(slots)
      } = props;
      let optionChildren;
      const {
        class: className
      } = attrs;
      const cls = {
        [className]: !!className,
        [`${prefixCls.value}-lg`]: size === "large",
        [`${prefixCls.value}-sm`]: size === "small",
        [`${prefixCls.value}-show-search`]: true,
        [`${prefixCls.value}-auto-complete`]: true
      };
      if (props.options === void 0) {
        const childArray = ((_b = slots.dataSource) == null ? void 0 : _b.call(slots)) || ((_c = slots.options) == null ? void 0 : _c.call(slots)) || [];
        if (childArray.length && isSelectOptionOrSelectOptGroup(childArray[0])) {
          optionChildren = childArray;
        } else {
          optionChildren = dataSource ? dataSource.map((item) => {
            if (index$1.isValidElement(item))
              return item;
            switch (typeof item) {
              case "string":
                return vue.createVNode(Option.default, {
                  "key": item,
                  "value": item
                }, _isSlot(item) ? item : {
                  default: () => [item]
                });
              case "object":
                return vue.createVNode(Option.default, {
                  "key": item.value,
                  "value": item.value
                }, {
                  default: () => [item.text]
                });
              default:
                throw new Error("AutoComplete[dataSource] only supports type `string[] | Object[]`.");
            }
          }) : [];
        }
      }
      const selectProps2 = omit.default({
        ...props,
        ...attrs,
        mode: select.default.SECRET_COMBOBOX_MODE_DO_NOT_USE,
        // optionLabelProp,
        getInputElement,
        notFoundContent,
        // placeholder: '',
        class: cls,
        popupClassName: props.popupClassName || props.dropdownClassName,
        ref: selectRef
      }, ["dataSource", "loading"]);
      return vue.createVNode(select.default, selectProps2, {
        default: () => [optionChildren],
        ...omit.default(slots, ["default", "dataSource", "options"])
      });
    };
  }
});
var index = Object.assign(AutoComplete, {
  Option: Option.default,
  OptGroup: OptGroup.default,
  install(app) {
    app.component(AutoComplete.name, AutoComplete);
    app.component(Option.default.displayName, Option.default);
    app.component(OptGroup.default.displayName, OptGroup.default);
    return app;
  }
});

exports.AutoCompleteOptGroup = AutoCompleteOptGroup;
exports.AutoCompleteOption = AutoCompleteOption;
exports.autoCompleteProps = autoCompleteProps;
exports.default = index;
//# sourceMappingURL=index.js.map
