/*! bxs-vue-ui v3.3.0 */
'use strict';

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

var entryVirtual = require('../utils/entry-virtual.js');
var normalizeComponent = require('../utils/normalize-component.js');
require('../utils/object-create.js');
require('../utils/html.js');
require('../utils/es.number.constructor.js');
var arrayIteration = require('../utils/array-iteration.js');
var sloppyArrayMethod = require('../utils/sloppy-array-method.js');
var indexOf = require('../utils/index-of.js');
require('../utils/string-trim.js');
var filter = require('../utils/filter.js');
require('../utils/slice.js');
require('../utils/extends.js');
require('../utils/env.js');
require('../icon/index.js');
var trim = require('../utils/trim.js');
require('../utils/emitter.js');
var includes = require('../utils/includes.js');
var input = require('../input/index.js');

var $every = arrayIteration.require$$0.every;


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

var every = entryVirtual.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, indexOf._indexOfInstanceProperty(value).call(value, '@'));
};

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

var script = normalizeComponent.create({
  name: 'mail-input',
  filters: {
    filterEmailValue: function filterEmailValue(email) {
      if (indexOf._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: normalizeComponent._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 = indexOf._indexOfInstanceProperty(val).call(val, '@') > -1 ? filter._filterInstanceProperty(_context2 = this.emailArr).call(_context2, function (item) {
        return includes._includesInstanceProperty(item).call(item, suffix) && item.length > suffix.length;
      }) : normalizeComponent._concatInstanceProperty(_context3 = []).call(_context3, this.emailArr);
    }
  },
  methods: {
    clickItem: function clickItem(data) {
      var _context4;

      var index = indexOf._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.default.name] = input.default, _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' ? trim._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 = normalizeComponent.__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);

exports.default = index;
