import _extends from 'babel-runtime/helpers/extends';
import _toConsumableArray from 'babel-runtime/helpers/toConsumableArray';
/**
 * @文件说明: 定义地图控件的基础Mixin
 * @创建人: pjtools@vip.qq.com
 * @创建时间: 2020-04-01 10:34:34
 */

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

      var cls = [];
      if (className) {
        cls = className.split(',');
        cls = cls && cls.length && cls.map(function (item) {
          return item.trim();
        }) || [];
      }
      var componentName = this.$options.name.replace('PjMap.Controls.', '').toLowerCase();
      return [prefixCls + '-control-' + componentName].concat(_toConsumableArray(cls));
    },
    ctrlStyles: function ctrlStyles() {
      var offset = this.offset,
          position = this.position,
          styles = this.styles;

      var x = offset[0] || 0;
      var y = offset[1] || 0;
      var pos = position.split('-');
      x = pos[1] === 'left' ? x : 0 - x;
      y = pos[0] === 'top' ? y : 0 - y;
      return _extends({}, styles, {
        transform: 'translate(' + x + 'px, ' + y + 'px)'
      });
    },
    iMapApi: function iMapApi() {
      var iMapApi = this.mapProvider.iMapApi;

      return iMapApi;
    }
  },
  methods: {
    /**
     * 根据偏移量对地图控件进行对应偏移值更新
     * @param {Array} offset 待更新的偏移量
     */
    updateOffset: function updateOffset(offset) {
      this.$emit('update:offset', [offset && offset[0] ? Number(offset[0]) : 0, offset && offset[1] ? Number(offset[1]) : 0]);
    }
  }
};