"use strict";

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

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

var _vue = require("vue");

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

var _initDefaultProps = _interopRequireDefault(require("../_util/props-util/initDefaultProps"));

var _CloseCircleFilled = _interopRequireDefault(require("@ant-design/icons-vue/lib/icons/CloseCircleFilled"));

var _SearchOutlined = _interopRequireDefault(require("@ant-design/icons-vue/lib/icons/SearchOutlined"));

var _input = _interopRequireDefault(require("../input"));

var transferSearchProps = {
  prefixCls: _vueTypes.default.string,
  placeholder: _vueTypes.default.string,
  value: _vueTypes.default.string,
  handleClear: _vueTypes.default.func,
  disabled: _vueTypes.default.looseBool,
  onChange: _vueTypes.default.func
};
exports.transferSearchProps = transferSearchProps;

var _default = (0, _vue.defineComponent)({
  name: 'Search',
  inheritAttrs: false,
  props: (0, _initDefaultProps.default)(transferSearchProps, {
    placeholder: ''
  }),
  emits: ['change'],
  setup: function setup(props, _ref) {
    var emit = _ref.emit;

    var handleChange = function handleChange(e) {
      emit('change', e);
    };

    var handleClearFn = function handleClearFn(e) {
      var handleClear = props.handleClear,
          disabled = props.disabled;

      if (!disabled && handleClear) {
        handleClear(e);
      }
    };

    return function () {
      var placeholder = props.placeholder,
          value = props.value,
          prefixCls = props.prefixCls,
          disabled = props.disabled;
      var icon = value && value.length > 0 ? (0, _vue.createVNode)("a", {
        "class": "".concat(prefixCls, "-action"),
        "onClick": handleClearFn
      }, [(0, _vue.createVNode)(_CloseCircleFilled.default, null, null)]) : (0, _vue.createVNode)("span", {
        "class": "".concat(prefixCls, "-action")
      }, [(0, _vue.createVNode)(_SearchOutlined.default, null, null)]);
      return (0, _vue.createVNode)(_vue.Fragment, null, [(0, _vue.createVNode)(_input.default, {
        "placeholder": placeholder,
        "class": prefixCls,
        "value": value,
        "onChange": handleChange,
        "disabled": disabled
      }, null), icon]);
    };
  }
});

exports.default = _default;