import _toConsumableArray from 'babel-runtime/helpers/toConsumableArray';
/**
 * @文件说明: 定义地图交互组件的基础Mixin
 * @创建人: pjtools@vip.qq.com
 * @创建时间: 2020-05-18 15:46:39
 */

import { isArray } from '../../_util/methods-util';
import { getComponentFromProp, filterEmpty } from '../../_util/antdv';

export default {
  inject: {
    mapProvider: { 'default': function _default() {} }
  },
  computed: {
    classes: function classes() {
      var prefixCls = this.mapProvider.prefixCls,
          className = this.className;

      var cls = [prefixCls + '-interactions-wrapper'];
      if (className) {
        if (isArray(className)) {
          cls.push.apply(cls, _toConsumableArray(className));
        } else {
          cls.push(className);
        }
      }
      return cls;
    },
    iMapApi: function iMapApi() {
      var iMapApi = this.mapProvider.iMapApi;

      return iMapApi;
    }
  },
  methods: {
    // 根据定义的Prop属性值获取Slot插槽对象
    getSlotFromProp: function getSlotFromProp(name) {
      var prefix = this.$options.name.replace('PjMap.Interactions.', '');
      prefix = prefix.toLowerCase() + '.' + name;
      // 查找具名插槽对象
      return getComponentFromProp(this.iMapApi.component, prefix, {}, false) || null;
    },


    // 渲染指定具名Slot插槽
    renderSlotScopeNodes: function renderSlotScopeNodes(name) {
      var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

      var slotNodes = this.getSlotFromProp(name);
      return slotNodes ? filterEmpty(slotNodes(options)) : null;
    }
  }
};