import "./index.css";
/* script */
//
//
//
//
//
//
//
//
//
import svgSprite from './icon-sprite';
import { createComponentName, componentMixin } from '../../utils/base';
import { on, off } from '../../utils/dom';
let loaded = false;

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

const __vue_script__ = {
  name: createComponentName('icon'),
  mixins: [componentMixin],
  props: {
    // 图标名
    name: {
      type: String,
      required: true
    },
    hoverName: {
      type: String
    },
    spin: {
      type: Boolean,
      default: false
    },
    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()) {
      loadSprite();

      if (this.hoverName) {
        on(this.$el, 'mouseenter', this.mouseenter);
        on(this.$el, 'mouseleave', this.mouseleave);
      }
    }
  },

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

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

    mouseleave() {
      this.hover = false;
    }

  }
};
/* template */

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

  var _h = _vm.$createElement;

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

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

var __vue_staticRenderFns__ = [];
__vue_render__._withStripped = true;
/* style */

const __vue_inject_styles__ = undefined;
/* scoped */

const __vue_scope_id__ = undefined;
/* module identifier */

const __vue_module_identifier__ = undefined;
/* functional template */

const __vue_is_functional_template__ = false;
/* component normalizer */

import __vue_normalize__ from '../../utils/vue-normalize-component.js';
/* style inject */

/* style inject SSR */

export default __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);