/**
 * vue-cesium - https://github.com/zouyaoji/vue-cesium
 * Vue 2.x components for CesiumJS.
 *
 * @package VueCesium
 * @author zouyaoji <370681295@qq.com>
 * @version 2.3.12
 * @license MIT
 * @homepage https://zouyaoji.top/vue-cesium
 * @copyright (c) 2018-2022, zouyaoji <370681295@qq.com>
 */
import _asyncToGenerator from '@babel/runtime-corejs2/helpers/esm/asyncToGenerator';
import _regeneratorRuntime from '@babel/runtime-corejs2/regenerator';
import { show, id, positions, classificationType, polygonHierarchy, clampToGround, appearance, depthFailAppearance, ellipsoid, aaMixin } from '../../mixins/mixinProps';
import mixinPrimitiveCollectionItem from '../../mixins/primitives/mixinPrimitiveCollectionItem';
import PolygonPrimitive from '../../exts/PolygonPrimitive';
import { makeCartesian3Array, makePolygonHierarchy, makeAppearance } from '../../utils/cesiumHelpers';

var script = {
  name: 'vc-polygon',
  mixins: [show, id, positions, classificationType, polygonHierarchy, clampToGround, appearance, depthFailAppearance, ellipsoid, aaMixin, mixinPrimitiveCollectionItem],
  watch: {
    clampToGround: function clampToGround(val) {
      var polygonPrimitive = this.cesiumObject;
      polygonPrimitive && (polygonPrimitive.clampToGround = val);
    },
    positions: function positions(val) {
      var polygonPrimitive = this.cesiumObject;
      polygonPrimitive && (polygonPrimitive.positions = makeCartesian3Array(val));
    },
    polygonHierarchy: function polygonHierarchy(val) {
      var polygonPrimitive = this.cesiumObject;
      polygonPrimitive && (polygonPrimitive.polygonHierarchy = makePolygonHierarchy(val));
    },
    appearance: function appearance(val) {
      var polygonPrimitive = this.cesiumObject;
      polygonPrimitive && (polygonPrimitive.appearance = makeAppearance.call(this, val));
    },
    depthFailAppearance: function depthFailAppearance(val) {
      var polygonPrimitive = this.cesiumObject;
      polygonPrimitive && (polygonPrimitive.depthFailAppearance = makeAppearance.call(this, val));
    },
    show: function show(val) {
      var polygonPrimitive = this.cesiumObject;
      polygonPrimitive && (polygonPrimitive.classificationType = val);
    }
  },
  methods: {
    createCesiumObject: function createCesiumObject() {
      var _this = this;

      return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        var $props, transformProps, options;
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                $props = _this.$props, transformProps = _this.transformProps;
                options = transformProps($props);
                return _context.abrupt("return", new PolygonPrimitive(options));

              case 3:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }))();
    },
    mount: function mount() {
      var _this2 = this;

      return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
        var primitives, primitive, registerEvents;
        return _regeneratorRuntime.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                primitives = _this2.primitives, primitive = _this2.primitive, registerEvents = _this2.registerEvents;
                registerEvents(true);
                primitive._vcParent = primitives;
                return _context2.abrupt("return", primitives && primitives.add(primitive));

              case 4:
              case "end":
                return _context2.stop();
            }
          }
        }, _callee2);
      }))();
    },
    unmount: function unmount() {
      var _this3 = this;

      return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
        var primitives, primitive, registerEvents;
        return _regeneratorRuntime.wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                primitives = _this3.primitives, primitive = _this3.primitive, registerEvents = _this3.registerEvents;
                registerEvents(false);
                return _context3.abrupt("return", primitives && !primitives.isDestroyed() && primitives.remove(primitive));

              case 3:
              case "end":
                return _context3.stop();
            }
          }
        }, _callee3);
      }))();
    }
  }
};

/* 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 = "Polygon.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 Polygon = __vue_normalize__({}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__);

/*
 * @Author: zouyaoji@https://github.com/zouyaoji
 * @Date: 2022-05-06 10:34:27
 * @LastEditTime: 2022-05-06 10:34:48
 * @LastEditors: zouyaoji
 * @Description:
 * @FilePath: \vue-cesium-v2\src\components\primitive\polygon\index.js
 */

function plugin(Vue) {

  if (plugin.installed) {
    return;
  }

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

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