'use strict';

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

var vue = require('vue');
var lodash = require('lodash');
require('../../../utils/index.cjs');
var index = require('../../select/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var Option = require('./Option.cjs');
var props = require('./props.cjs');
var log = require('../../../utils/log.cjs');
var props$1 = require('../../../utils/vue/props.cjs');
var is = require('../../../utils/is.cjs');

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);
}
var AAutoComplete = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AAutoComplete",
  inheritAttrs: false,
  props: props.autoCompleteProps(),
  // emits: ['change', 'select', 'focus', 'blur'],
  slots: Object,
  setup(props, {
    slots,
    attrs,
    expose
  }) {
    log.devWarning(!("dataSource" in slots), "AutoComplete", "`dataSource` slot is deprecated, please use props `options` instead.");
    log.devWarning(!("options" in slots), "AutoComplete", "`options` slot is deprecated, please use props `options` instead.");
    log.devWarning(!props.dropdownClassName, "AutoComplete", "`dropdownClassName` is deprecated, please use `popupClassName` instead.");
    const selectRef = vue.ref();
    const getInputElement = () => {
      var _a;
      const children = props$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 (is.isValidElement(item))
              return item;
            switch (typeof item) {
              case "string":
                return vue.createVNode(Option.default, {
                  "key": item,
                  "value": 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 selectProps = lodash.omit({
        ...props,
        ...attrs,
        mode: index.Select.SECRET_COMBOBOX_MODE_DO_NOT_USE,
        // optionLabelProp,
        getInputElement,
        notFoundContent,
        // placeholder: '',
        class: cls,
        popupClassName: props.popupClassName || props.dropdownClassName,
        ref: selectRef
      }, ["dataSource", "loading"]);
      return vue.createVNode(index.Select, selectProps, {
        default: () => [optionChildren],
        ...lodash.omit(slots, ["default", "dataSource", "options"])
      });
    };
  }
});

exports.default = AAutoComplete;
//# sourceMappingURL=AutoComplete.cjs.map
