import _typeof from 'babel-runtime/helpers/typeof';
/**
 * @文件说明: 定义默认Popup气泡弹窗组件
 * @创建人: pjtools@vip.qq.com
 * @创建时间: 2020-06-15 14:43:53
 */

import { PropTypes, getComponentFromProp, filterEmpty } from '../../../_util/antdv';
import { isBooleanFlase, isFunction, isString } from '../../../_util/methods-util';
import { Icon } from 'ant-design-vue';

var DefaultPopup = {
  props: {
    // 地图iMapApi实例对象
    iMapApi: PropTypes.any,
    // Popup对象
    popup: PropTypes.any,
    // Popup对象的参数选项
    options: PropTypes.object.def({}),
    // Slot插槽传递的数据
    data: PropTypes.any
  },
  computed: {
    slotContent: function slotContent() {
      return this.$scopedSlots && this.$scopedSlots['default'] ? this.$scopedSlots['default']() : null;
    }
  },
  methods: {
    // 根据Slots插槽渲染Popup标注内容
    renderPopupContent: function renderPopupContent(h) {
      var iMapApi = this.iMapApi,
          popup = this.popup,
          data = this.data,
          slots = this.options.slots;


      if (isFunction(slots)) {
        return h(
          'div',
          { 'class': 'popup-inner-content' },
          [slots(h)]
        );
      } else if ((typeof slots === 'undefined' ? 'undefined' : _typeof(slots)) === 'object' && slots instanceof HTMLElement) {
        return h('div', { 'class': 'popup-inner-content', domProps: {
            'innerHTML': slots.outerHTML
          }
        });
      } else if (isString(slots)) {
        var slotNodes = getComponentFromProp(iMapApi.component, 'popup.' + slots, {}, false);
        return h(
          'div',
          { 'class': 'popup-inner-content' },
          [slotNodes ? filterEmpty(slotNodes({ iMapApi: iMapApi, popup: popup, data: data })) : slots]
        );
      }
      return h('div', { 'class': 'popup-inner-content' });
    },


    // 执行Popup气泡弹窗的关闭按钮单击Click事件
    handlePopupClose: function handlePopupClose() {
      this.popup && this.popup.remove();
    }
  },
  render: function render(h) {
    var options = this.options;


    return h('div', [options.anchor && options.anchor === 'center' || isBooleanFlase(options.defaultSkin) ? null : h('div', { 'class': 'popup-arrow' }), h(
      'div',
      { 'class': 'popup-inner' },
      [isBooleanFlase(options.closeButton) || isBooleanFlase(options.defaultSkin) ? null : h(
        'div',
        { 'class': 'popup-inner-close', on: {
            'click': this.handlePopupClose
          }
        },
        [h(Icon, {
          attrs: { type: 'close' }
        })]
      ), this.renderPopupContent(h)]
    )]);
  }
};

export default DefaultPopup;