"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _Shape = _interopRequireDefault(require("./Shape"));
var _PolygonPainter = require("../../modules/painters/PolygonPainter");
var _common = require("../../utils/common");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
/**
 * Polygon props
 *
 * @category Props
 */

/**
  @category Component
 */
const Polygon = props => {
  const {
    id,
    onError,
    onFinish,
    ...styles
  } = props;
  const painter = new _PolygonPainter.PolygonPainter();
  const toFeatures = async points => {
    const drawingFeatures = [];
    if (points.length) {
      drawingFeatures.push(...points.map(p => (0, _common.createPointFeature)(p, {
        type: 0
      })));
      if (points.length > 1) {
        drawingFeatures.push((0, _common.createLineFeature)(points, {
          type: 0
        }));
      }
      if (points.length > 2) {
        drawingFeatures.push((0, _common.createPolygonFeature)(points, {
          type: 0
        }));
      }
    }
    return drawingFeatures;
  };
  return /*#__PURE__*/React.createElement(_Shape.default, _extends({
    id: id
  }, styles, {
    paintner: painter,
    toFeatures: toFeatures,
    onError: onError,
    onFinish: onFinish
  }));
};
var _default = exports.default = Polygon;
//# sourceMappingURL=Polygon.js.map