/**
 * vue-cesium - https://github.com/zouyaoji/vue-cesium
 * Vue 2.x components for CesiumJS.
 *
 * @package VueCesium
 * @author zouyaoji <370681295@qq.com>
 * @version 2.2.12
 * @license MIT
 * @homepage https://zouyaoji.top/vue-cesium
 * @copyright (c) 2018-2021, zouyaoji <370681295@qq.com>
 */
import _Object$defineProperties from '@babel/runtime-corejs2/core-js/object/define-properties';
import _regeneratorRuntime from '@babel/runtime-corejs2/regenerator';
import cmp from '../mixins/virtualCmp';
import mixinPickEvent from '../mixins/event/mixinPickEvent';
import { position, plane } from '../mixins/mixinProps';
import mergeDescriptors from '../utils/mergeDescriptors';
import bindEvents from '../utils/bindEvent';
import { Events } from '../utils/events';

var script = {
  name: 'vc-entity',
  mixins: [cmp, position, plane, mixinPickEvent],
  props: {
    id: String,
    name: String,
    availability: Object,
    show: {
      type: Boolean,
      default: true
    },
    description: [String, Object],
    orientation: Object,
    viewFrom: Object,
    parent: Object,
    billboard: Object,
    corridor: Object,
    cylinder: Object,
    ellipse: Object,
    ellipsoid: Object,
    box: Object,
    label: Object,
    model: Object,
    tileset: Object,
    path: Object,
    point: Object,
    polygon: Object,
    polyline: Object,
    properties: Object,
    polylineVolume: Object,
    rectangle: Object,
    wall: Object,
    enableEvent: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    mount: function mount() {
      var entities, entity, registerEvents;
      return _regeneratorRuntime.async(function mount$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              entities = this.entities, entity = this.entity, registerEvents = this.registerEvents;
              registerEvents(true);
              bindEvents.call(this, entity, Events['entity-events']);
              return _context.abrupt("return", entities && entities.add(entity));

            case 4:
            case "end":
              return _context.stop();
          }
        }
      }, null, this);
    },
    unmount: function unmount() {
      var entities, entity, registerEvents;
      return _regeneratorRuntime.async(function unmount$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              entities = this.entities, entity = this.entity, registerEvents = this.registerEvents;
              bindEvents.call(this, entity, Events['entity-events'], false);
              registerEvents(false);
              return _context2.abrupt("return", entities && entities.remove(entity));

            case 4:
            case "end":
              return _context2.stop();
          }
        }
      }, null, this);
    },
    setGraphics: function setGraphics(graphics, type) {
      var listener = this.$listeners['update:' + type];

      if (listener) {
        this.$emit('update:' + type, graphics);
      } else {
        this.entity[type] = graphics;
      }

      return true;
    },
    getServices: function getServices() {
      var vm = this;
      return mergeDescriptors(cmp.methods.getServices.call(this), {
        get entity() {
          return vm.entity;
        },

        get graphicsContainer() {
          return vm;
        }

      });
    }
  },
  stubVNode: {
    attrs: function attrs() {
      return {
        class: this.$options.name
      };
    }
  },
  created: function created() {
    var _this = this;

    _Object$defineProperties(this, {
      entity: {
        enumerable: true,
        get: function get() {
          return _this.cesiumObject;
        }
      },
      entities: {
        enumerable: true,
        get: function get() {
          return _this.$services && _this.$services.entities;
        }
      }
    });
  }
};

/* script */
var __vue_script__ = script;
/* template */

/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* functional template */

var __vue_is_functional_template__ = undefined;
/* component normalizer */

function __vue_normalize__(template, style, script, scope, functional, moduleIdentifier, createInjector, createInjectorSSR) {
  var component = (typeof script === 'function' ? script.options : script) || {}; // For security concerns, we use only base name in production mode.

  component.__file = "Entity.vue";

  if (!component.render) {
    component.render = template.render;
    component.staticRenderFns = template.staticRenderFns;
    component._compiled = true;
    if (functional) component.functional = true;
  }

  component._scopeId = scope;

  return component;
}
/* style inject */

/* style inject SSR */


var Entity = __vue_normalize__({}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__);

function plugin(Vue) {

  if (plugin.installed) {
    return;
  }

  plugin.installed = true;
  Vue.component(Entity.name, Entity);
}

export default plugin;
export { Entity, plugin as install };
