<template>
  <el-tooltip
    :value="value"
    v-bind="trimAttrs($attrs)"
    :visible-arrow="isArrowVisible"
    :manual="isManual"
    :enterable="isMouseEnterable"
    :effect="tooltipTheme"
  >
    <template slot="content">
      <slot name="content" />
    </template>
    <slot />
  </el-tooltip>
</template>
<script>
import { Tooltip } from 'element-ui';
export default {
  name: 'JskTooltip',
  components: {
    ElTooltip: Tooltip
  },
  inheritAttrs: false,
  props: {
    isVisible: {
      type: Boolean,
      default: false
    },
    isArrowVisible: {
      type: Boolean,
      default: true
    },
    isManual: {
      type: Boolean,
      default: false
    },
    isMouseEnterable: {
      type: Boolean,
      default: true
    },
    tooltipTheme: {
      type: String,
      default: 'dark'
    }
  },
  created: function() {
    this.value = this.isVisible;
  },
  methods: {
    trimAttrs: function(attrs) {
      Object.keys(attrs).forEach((key) => {
        let prefixes = ['is-', 'has-', 'tooltip-'];
        prefixes.forEach((prefix) => {
          if (key.substr(0, prefix.length) === prefix) {
            attrs[key.substr(prefix.length)] = attrs[key];
          }
        })
      })
      return attrs;
    }
  }
}
</script>

<style lang="scss" src="../../theme/tooltip.scss"></style>
