"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vue = require("vue");

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _vnode = require("../../_util/vnode");

var _vueTypes = _interopRequireDefault(require("../../_util/vue-types"));

var _antInputDirective = _interopRequireDefault(require("../../_util/antInputDirective"));

var _classNames = _interopRequireDefault(require("../../_util/classNames"));

var Input = (0, _vue.defineComponent)({
  name: 'Input',
  inheritAttrs: false,
  props: {
    inputRef: _vueTypes.default.any,
    prefixCls: _vueTypes.default.string,
    id: _vueTypes.default.string,
    inputElement: _vueTypes.default.any,
    disabled: _vueTypes.default.looseBool,
    autofocus: _vueTypes.default.looseBool,
    autocomplete: _vueTypes.default.string,
    editable: _vueTypes.default.looseBool,
    accessibilityIndex: _vueTypes.default.number,
    value: _vueTypes.default.string,
    open: _vueTypes.default.looseBool,
    tabindex: _vueTypes.default.oneOfType([_vueTypes.default.number, _vueTypes.default.string]),

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

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

    return {
      blurTimeout: null,
      VCSelectContainerEvent: (0, _vue.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 || (0, _vue.withDirectives)((0, _vue.createVNode)("input", null, null), [[_antInputDirective.default]]);
    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 = (0, _vnode.cloneElement)(inputNode, (0, _extends2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({
      id: id,
      ref: inputRef,
      disabled: disabled,
      tabindex: tabindex,
      autocomplete: autocomplete || 'off',
      autofocus: autofocus,
      class: (0, _classNames.default)("".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: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, 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,
// };

var _default = Input;
exports.default = _default;