'use strict';

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

var _typeof2 = require('babel-runtime/helpers/typeof');

var _typeof3 = _interopRequireDefault(_typeof2);

var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _baseProps = require('../baseProps');

var _baseProps2 = _interopRequireDefault(_baseProps);

var _baseMixin = require('../baseMixin');

var _baseMixin2 = _interopRequireDefault(_baseMixin);

var _antdv = require('../../../_util/antdv');

var _methodsUtil = require('../../../_util/methods-util');

var _antDesignVue = require('ant-design-vue');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var MouseTooltip = {
  name: 'PjMap.Interactions.MouseTooltip',
  inheritAttrs: false,
  mixins: [_baseMixin2['default']],
  props: (0, _baseProps2['default'])(),
  data: function data() {
    return {
      // 组件是否可见
      visible: false,
      // 组件容器Class类名
      wrapClassName: null,
      // 提示框的偏移量
      position: null,
      // 提示框的显隐状态
      show: false,
      // 提示图标
      icon: null,
      // 提示内容
      content: null
    };
  },

  computed: {
    // 是否渲染组件
    isRenderComponent: function isRenderComponent() {
      return !!(this.visible && (this.icon || this.content));
    },

    // 是否为纯图标模式
    isPureIconMode: function isPureIconMode() {
      return !!(this.icon && !this.content);
    },

    // 组件的样式
    cptStyles: function cptStyles() {
      var styles = this.styles,
          position = this.position,
          show = this.show;

      var componentStyle = {};
      styles && (0, _extends3['default'])(componentStyle, styles);
      position && (0, _extends3['default'])(componentStyle, position);
      !show && (componentStyle.display = 'none');
      return componentStyle;
    },

    // 组件Class类名
    classNames: function classNames() {
      var classes = this.classes,
          prefixCls = this.mapProvider.prefixCls,
          isPureIconMode = this.isPureIconMode;

      var cls = [].concat((0, _toConsumableArray3['default'])(classes), [prefixCls + '-interactions-mousetooltip', {
        'pure-icon': isPureIconMode
      }]);
      this.wrapClassName && cls.push(this.wrapClassName);
      return cls;
    }
  },
  methods: {
    // 渲染默认的提示框文本
    renderTooltipContent: function renderTooltipContent(h) {
      var content = (0, _antdv.getComponentFromProp)(this, 'content', {}, false);
      if ((0, _methodsUtil.isFunction)(content)) {
        return h(
          'span',
          { 'class': 'content' },
          [content(h)]
        );
      } else if ((typeof content === 'undefined' ? 'undefined' : (0, _typeof3['default'])(content)) === 'object' && content instanceof HTMLElement) {
        return h('span', { 'class': 'content', domProps: {
            'innerHTML': content.outerHTML
          }
        });
      } else {
        return this.renderSlotScopeNodes(content, this.$data) || h(
          'span',
          { 'class': 'content' },
          [content]
        );
      }
    },


    // 渲染默认的提示框图标
    renderTooltipIcon: function renderTooltipIcon(h) {
      var icon = (0, _antdv.getComponentFromProp)(this, 'icon', {}, false);
      // 判断是否为Function函数类型
      if ((0, _methodsUtil.isFunction)(icon)) {
        return h(
          'span',
          { 'class': 'icon' },
          [icon(h)]
        );
      } else if ((typeof icon === 'undefined' ? 'undefined' : (0, _typeof3['default'])(icon)) === 'object' && icon instanceof HTMLElement) {
        return h('span', { 'class': 'icon', domProps: {
            'innerHTML': icon.outerHTML
          }
        });
      } else {
        // 判断是否有具名插槽
        var slotNodes = this.renderSlotScopeNodes(icon, this.$data);
        if (slotNodes) {
          return slotNodes;
        } else {
          var theme = 'outlined';
          var iconName = icon;
          if (icon.indexOf(':') !== -1) {
            var iconSplit = icon.split(':');
            theme = iconSplit[1];
            iconName = iconSplit[0];
          }
          return h(_antDesignVue.Icon, { 'class': 'icon', attrs: { type: iconName, theme: theme }
          });
        }
      }
    },


    // 激活光标跟随气泡提示框
    enable: function enable() {
      var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

      this.icon = options.icon || null;
      this.content = options.content || null;
      this.wrapClassName = options.className || null;
      this.position = options.position || this.position || null;
      this.show = true;
      this.visible = true;
    },


    // 禁用光标跟随气泡提示框
    disable: function disable() {
      this.wrapClassName = null;
      this.position = null;
      this.show = false;
      this.icon = null;
      this.content = null;
      this.visible = false;
    },


    // 更新光标提示框的偏移量
    updateMousePostion: function updateMousePostion(position) {
      this.position = position;
    },


    // 更新关闭提示框的Icon图标
    updateMouseIcon: function updateMouseIcon(icon) {
      this.icon = icon;
    },


    // 更新关闭提示框的内容
    updateMouseContent: function updateMouseContent(content) {
      this.content = content;
    },


    // 更新光标提示框的显隐状态
    updateVisible: function updateVisible() {
      var show = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;

      this.show = (0, _methodsUtil.isBooleanTrue)(show);
    }
  },
  render: function render(h) {
    var id = this.id,
        cptStyles = this.cptStyles,
        classNames = this.classNames,
        isRenderComponent = this.isRenderComponent,
        icon = this.icon,
        content = this.content;

    return isRenderComponent ? h(
      'div',
      {
        attrs: { 'data-id': id },
        'class': classNames, style: cptStyles },
      [icon ? this.renderTooltipIcon(h) : null, content ? this.renderTooltipContent(h) : null]
    ) : null;
  }
}; /**
    * @文件说明: Interactions.MouseTooltip - 光标跟随气泡提示框
    * @创建人: pjtools@vip.qq.com
    * @创建时间: 2020-05-18 14:13:35
    */

exports['default'] = MouseTooltip;