"use strict";

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

exports.__esModule = true;
exports.default = void 0;

require("./index.css");

var _iconSprite = _interopRequireDefault(require("./icon-sprite"));

var _component = require("../_utils/component");

var _dom = require("../_utils/dom");

var _constant = require("../_utils/constant");

var _vueNormalizeComponent = _interopRequireDefault(require("../_utils/vue-normalize-component.js"));

/* script */
//
//
//
//
//
//
//
//
//
var loaded = false;

function loadSprite() {
  if (!loaded) {
    loaded = true;
    var div = document.createElement('div');
    div.id = '__GD_SVG_ICONS__';
    div.style.display = 'none';
    div.innerHTML = _iconSprite.default;
    document.body.appendChild(div, document.body.firstChild);
  }
}

if (!(0, _constant.isSSR)()) {
  loadSprite();
}

var __vue_script__ = {
  name: (0, _component.createComponentName)('icon'),
  mixins: [_component.componentMixin],
  props: {
    // 图标名
    name: {
      type: String,
      required: true
    },
    hoverName: {
      type: String
    },
    size: {
      type: String
    }
  },

  data() {
    return {
      hover: false
    };
  },

  computed: {
    iconName() {
      if (!this.hoverName) return this.name;
      return this.hover ? this.hoverName : this.name;
    }

  },

  mounted() {
    if (!this.isSSR()) {
      if (this.hoverName) {
        (0, _dom.on)(this.$el, 'mouseenter', this.mouseenter);
        (0, _dom.on)(this.$el, 'mouseleave', this.mouseleave);
      }
    }
  },

  beforeDestroy() {
    if (!this.isSSR() && this.hoverName) {
      (0, _dom.off)(this.$el, 'mouseenter', this.mouseenter);
      (0, _dom.off)(this.$el, 'mouseleave', this.mouseleave);
    }
  },

  methods: {
    mouseenter() {
      this.hover = true;
    },

    mouseleave() {
      this.hover = false;
    }

  }
};
/* template */

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

  var _h = _vm.$createElement;

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

  return _c("svg", {
    class: _vm.bem([_vm.size, _vm.iconName]),
    attrs: {
      width: "1em",
      color: "currentColor",
      height: "1em"
    }
  }, [_c("use", {
    attrs: {
      "xlink:href": "#gd-icons-" + _vm.iconName
    }
  })]);
};

var __vue_staticRenderFns__ = [];
__vue_render__._withStripped = true;
/* 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;
/* component normalizer */

/* style inject */

/* style inject SSR */
var _default = (0, _vueNormalizeComponent.default)({
  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 = _default;