import _extends from 'babel-runtime/helpers/extends';
/**
 * @文件说明: Map.Interactions - 地图交互组件
 * @创建人: pjtools@vip.qq.com
 * @创建时间: 2020-05-18 13:56:44
 */

import { PropTypes } from '../../_util/antdv';
import { isNotEmptyArray } from '../../_util/methods-util';
import MouseTooltip from './mouse-tooltip';

var Interactions = {
  name: 'PjMap.Interactions',
  props: {
    data: PropTypes.array
  },
  data: function data() {
    return {
      interactions: {}
    };
  },

  inject: {
    mapProvider: { 'default': function _default() {} }
  },
  methods: {
    // 动态渲染地图交互式组件
    renderInteractionsComponents: function renderInteractionsComponents() {
      var _this = this;

      var h = this.$createElement;
      var data = this.data;

      return data && isNotEmptyArray(data) && data.map(function (item, idx) {
        var attrs = _extends({}, item);
        !attrs.props && (attrs.props = {});
        attrs.props.key = item.id || String(idx);
        attrs.props.id = attrs.props.key;

        var component = null;
        switch (item.type) {
          case 'MouseTooltip':
            {
              component = h(MouseTooltip, attrs);
              break;
            }
        }
        _this.interactions[item.id] = component;
        return component;
      });
    }
  },
  render: function render() {
    var h = arguments[0];

    return h(
      'section',
      {
        attrs: { 'data-type': 'interaction' }
      },
      [this.renderInteractionsComponents()]
    );
  }
};

export default Interactions;