/*! bxs-vue-ui v3.3.0 */
import { $, y as entryVirtual } from '../utils/entry-virtual.js';
import { C as create, F as _concatInstanceProperty, _ as __vue_normalize__ } from '../utils/normalize-component.js';
import '../utils/object-create.js';
import '../utils/html.js';
import '../utils/es.number.constructor.js';
import { r as require$$0 } from '../utils/array-iteration.js';
import { s as sloppyArrayMethod } from '../utils/sloppy-array-method.js';
import { _ as _indexOfInstanceProperty } from '../utils/index-of.js';
import '../utils/string-trim.js';
import { _ as _filterInstanceProperty } from '../utils/filter.js';
import '../utils/slice.js';
import '../utils/extends.js';
import '../utils/env.js';
import '../icon/index.js';
import { _ as _trimInstanceProperty } from '../utils/trim.js';
import '../utils/emitter.js';
import { _ as _includesInstanceProperty } from '../utils/includes.js';
import Input from '../input/index.js';

var $every = require$$0.every;


// `Array.prototype.every` method
// https://tc39.github.io/ecma262/#sec-array.prototype.every
$({ target: 'Array', proto: true, forced: sloppyArrayMethod('every') }, {
  every: function every(callbackfn /* , thisArg */) {
    return $every(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  }
});

var every = entryVirtual('Array').every;

var ArrayPrototype = Array.prototype;

var every_1 = function (it) {
  var own = it.every;
  return it === ArrayPrototype || (it instanceof Array && own === ArrayPrototype.every) ? every : own;
};

var every$1 = every_1;

var every$2 = every$1;

var _components;

var getName = function getName(value) {
  return value.substring(0, _indexOfInstanceProperty(value).call(value, '@'));
};

var getSuffix = function getSuffix(value) {
  return value.substring(_indexOfInstanceProperty(value).call(value, '@'));
};

var script = create({
  name: 'mail-input',
  filters: {
    filterEmailValue: function filterEmailValue(email) {
      if (_indexOfInstanceProperty(email).call(email, '@') > -1) {
        return getName(email);
      }

      return email;
    }
  },
  props: {
    value: {
      type: String,
      default: ''
    },
    emailArr: {
      type: Array,
      default: function _default() {
        return ['@qq.com', '@163.com', '@126.com', '@139.com'];
      },
      validator: function validator(emails) {
        return every$2(emails).call(emails, function (email) {
          return typeof email === 'string' && /^@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(email);
        });
      }
    }
  },
  data: function data() {
    var _context;

    return {
      hintShow: false,
      isFocus: false,
      suffixList: _concatInstanceProperty(_context = []).call(_context, this.emailArr)
    };
  },
  computed: {
    currentValue: {
      get: function get() {
        return this.value;
      },
      set: function set(val) {
        this.$emit('input', val);
      }
    },
    showPopperHint: function showPopperHint() {
      return this.hintShow && this.isFocus && this.suffixList.length;
    }
  },
  watch: {
    currentValue: function currentValue(val) {
      var _context2, _context3;

      if (!val) {
        this.hintShow = false;
        return;
      }

      this.hintShow = true;
      var suffix = getSuffix(val);
      this.suffixList = _indexOfInstanceProperty(val).call(val, '@') > -1 ? _filterInstanceProperty(_context2 = this.emailArr).call(_context2, function (item) {
        return _includesInstanceProperty(item).call(item, suffix) && item.length > suffix.length;
      }) : _concatInstanceProperty(_context3 = []).call(_context3, this.emailArr);
    }
  },
  methods: {
    clickItem: function clickItem(data) {
      var _context4;

      var index = _indexOfInstanceProperty(_context4 = this.currentValue).call(_context4, '@');

      var html = index > -1 ? getName(this.currentValue) + data : this.currentValue + data;
      this.currentValue = html;
      this.$emit('select', html);
      this.hintShow = false;
    },
    onFocus: function onFocus(event) {
      this.isFocus = true;
      this.$emit('focus', event);
    },
    onBlur: function onBlur(event) {
      this.isFocus = false;
      this.hintShow = false;
      this.$emit('blur', event);
    }
  },
  components: (_components = {}, _components[Input.name] = Input, _components)
});

var __vue_script__ = script;
/* template */

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c('div', {
    staticClass: "bx-mail-input"
  }, [_c('bxs-input', _vm._b({
    ref: "input",
    on: {
      "focus": _vm.onFocus,
      "blur": _vm.onBlur
    },
    model: {
      value: _vm.currentValue,
      callback: function callback($$v) {
        _vm.currentValue = typeof $$v === 'string' ? _trimInstanceProperty($$v).call($$v) : $$v;
      },
      expression: "currentValue"
    }
  }, 'bxs-input', _vm.$attrs, false), [_c('div', {
    directives: [{
      name: "show",
      rawName: "v-show",
      value: _vm.showPopperHint,
      expression: "showPopperHint"
    }],
    ref: "popperHint",
    staticClass: "bx-popper-hint bx-hairline--surround",
    attrs: {
      "slot": "extra"
    },
    slot: "extra"
  }, [_c('div', {
    staticClass: "bx-popper-hint--wrap"
  }, [_c('div', {
    staticClass: "bx-popper-hint--left"
  }, _vm._l(_vm.suffixList, function (item, index) {
    return _c('div', {
      key: 'popper_' + index,
      staticClass: "bx-popper-hint-list bx-hairline--bottom",
      on: {
        "touchstart": function touchstart($event) {
          $event.preventDefault();

          _vm.clickItem(item);
        }
      }
    }, [_vm._v("\n            " + _vm._s(_vm._f("filterEmailValue")(_vm.value)) + "\n          ")]);
  })), _c('div', {
    staticClass: "bx-popper-hint--right"
  }, _vm._l(_vm.suffixList, function (item, index) {
    return _c('div', {
      key: 'popper_' + index,
      staticClass: "bx-popper-hint-list bx-hairline--bottom",
      on: {
        "touchstart": function touchstart($event) {
          $event.preventDefault();

          _vm.clickItem(item);
        }
      }
    }, [_vm._v("\n            " + _vm._s(item) + "\n          ")]);
  }))])])])], 1);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

var index = __vue_normalize__({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);

export default index;
