import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _extends from "@babel/runtime/helpers/esm/extends";
import { createVNode as _createVNode } from "vue";
import { cloneElement } from '../../_util/vnode';
import { defineComponent, getCurrentInstance, inject, onMounted, withDirectives } from 'vue';
import PropTypes from '../../_util/vue-types';
import antInput from '../../_util/antInputDirective';
import classNames from '../../_util/classNames';
var Input = defineComponent({
  name: 'Input',
  inheritAttrs: false,
  props: {
    inputRef: PropTypes.any,
    prefixCls: PropTypes.string,
    id: PropTypes.string,
    inputElement: PropTypes.any,
    disabled: PropTypes.looseBool,
    autofocus: PropTypes.looseBool,
    autocomplete: PropTypes.string,
    editable: PropTypes.looseBool,
    accessibilityIndex: PropTypes.number,
    value: PropTypes.string,
    open: PropTypes.looseBool,
    tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

    /** Pass accessibility props to input */
    attrs: PropTypes.object,
    onKeydown: PropTypes.func,
    onMousedown: PropTypes.func,
    onChange: PropTypes.func,
    onPaste: PropTypes.func,
    onCompositionstart: PropTypes.func,
    onCompositionend: PropTypes.func,
    onFocus: PropTypes.func,
    onBlur: PropTypes.func
  },
  setup: function setup(props) {
    if (process.env.NODE_ENV === 'test') {
      onMounted(function () {
        var ins = getCurrentInstance();

        if (props.autofocus) {
          if (ins.vnode && ins.vnode.el) {
            ins.vnode.el.focus();
          }
        }
      });
    }

    return {
      blurTimeout: null,
      VCSelectContainerEvent: inject('VCSelectContainerEvent')
    };
  },
  render: function render() {
    var _inputNode,
        _inputNode$props,
        _this = this;

    var _ref = this.$props,
        prefixCls = _ref.prefixCls,
        id = _ref.id,
        inputElement = _ref.inputElement,
        disabled = _ref.disabled,
        tabindex = _ref.tabindex,
        autofocus = _ref.autofocus,
        autocomplete = _ref.autocomplete,
        editable = _ref.editable,
        accessibilityIndex = _ref.accessibilityIndex,
        value = _ref.value,
        _onKeydown = _ref.onKeydown,
        _onMousedown = _ref.onMousedown,
        onChange = _ref.onChange,
        onPaste = _ref.onPaste,
        _onCompositionstart = _ref.onCompositionstart,
        _onCompositionend = _ref.onCompositionend,
        _onFocus = _ref.onFocus,
        _onBlur = _ref.onBlur,
        open = _ref.open,
        inputRef = _ref.inputRef,
        attrs = _ref.attrs;
    var inputNode = inputElement || withDirectives(_createVNode("input", null, null), [[antInput]]);
    var inputProps = inputNode.props || {};
    var onOriginKeyDown = inputProps.onKeydown,
        onOriginInput = inputProps.onInput,
        onOriginFocus = inputProps.onFocus,
        onOriginBlur = inputProps.onBlur,
        onOriginMouseDown = inputProps.onMousedown,
        onOriginCompositionStart = inputProps.onCompositionstart,
        onOriginCompositionEnd = inputProps.onCompositionend,
        style = inputProps.style;
    inputNode = cloneElement(inputNode, _extends(_objectSpread(_objectSpread({
      id: id,
      ref: inputRef,
      disabled: disabled,
      tabindex: tabindex,
      autocomplete: autocomplete || 'off',
      autofocus: autofocus,
      class: classNames("".concat(prefixCls, "-selection-search-input"), (_inputNode = inputNode) === null || _inputNode === void 0 ? void 0 : (_inputNode$props = _inputNode.props) === null || _inputNode$props === void 0 ? void 0 : _inputNode$props.className),
      style: _objectSpread(_objectSpread({}, style), {}, {
        opacity: editable ? null : 0
      }),
      role: 'combobox',
      'aria-expanded': open,
      'aria-haspopup': 'listbox',
      'aria-owns': "".concat(id, "_list"),
      'aria-autocomplete': 'list',
      'aria-controls': "".concat(id, "_list"),
      'aria-activedescendant': "".concat(id, "_list_").concat(accessibilityIndex)
    }, attrs), {}, {
      value: editable ? value : '',
      readonly: !editable,
      unselectable: !editable ? 'on' : null,
      onKeydown: function onKeydown(event) {
        _onKeydown(event);

        if (onOriginKeyDown) {
          onOriginKeyDown(event);
        }
      },
      onMousedown: function onMousedown(event) {
        _onMousedown(event);

        if (onOriginMouseDown) {
          onOriginMouseDown(event);
        }
      },
      onInput: function onInput(event) {
        onChange(event);

        if (onOriginInput) {
          onOriginInput(event);
        }
      },
      onCompositionstart: function onCompositionstart(event) {
        _onCompositionstart(event);

        if (onOriginCompositionStart) {
          onOriginCompositionStart(event);
        }
      },
      onCompositionend: function onCompositionend(event) {
        _onCompositionend(event);

        if (onOriginCompositionEnd) {
          onOriginCompositionEnd(event);
        }
      },
      onPaste: onPaste,
      onFocus: function onFocus() {
        var _this$VCSelectContain;

        clearTimeout(_this.blurTimeout);
        onOriginFocus && onOriginFocus(arguments.length <= 0 ? undefined : arguments[0]);
        _onFocus && _onFocus(arguments.length <= 0 ? undefined : arguments[0]);
        (_this$VCSelectContain = _this.VCSelectContainerEvent) === null || _this$VCSelectContain === void 0 ? void 0 : _this$VCSelectContain.focus(arguments.length <= 0 ? undefined : arguments[0]);
      },
      onBlur: function onBlur() {
        for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
          args[_key] = arguments[_key];
        }

        _this.blurTimeout = setTimeout(function () {
          var _this$VCSelectContain2;

          onOriginBlur && onOriginBlur(args[0]);
          _onBlur && _onBlur(args[0]);
          (_this$VCSelectContain2 = _this.VCSelectContainerEvent) === null || _this$VCSelectContain2 === void 0 ? void 0 : _this$VCSelectContain2.blur(args[0]);
        }, 200);
      }
    }), inputNode.type === 'textarea' ? {} : {
      type: 'search'
    }), true, true);
    return inputNode;
  }
}); // Input.props = {
//   inputRef: PropTypes.any,
//   prefixCls: PropTypes.string,
//   id: PropTypes.string,
//   inputElement: PropTypes.any,
//   disabled: PropTypes.looseBool,
//   autofocus: PropTypes.looseBool,
//   autocomplete: PropTypes.string,
//   editable: PropTypes.looseBool,
//   accessibilityIndex: PropTypes.number,
//   value: PropTypes.string,
//   open: PropTypes.looseBool,
//   tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
//   /** Pass accessibility props to input */
//   attrs: PropTypes.object,
//   onKeydown: PropTypes.func,
//   onMousedown: PropTypes.func,
//   onChange: PropTypes.func,
//   onPaste: PropTypes.func,
//   onCompositionstart: PropTypes.func,
//   onCompositionend: PropTypes.func,
//   onFocus: PropTypes.func,
//   onBlur: PropTypes.func,
// };

export default Input;