import Shape from './Shape';
import { bbox, createPointFeature, createPolygonFeature } from '../../utils/common';
import { RectanglePainter } from '../../modules/painters/RectanglePainter';
/**
 * Rectangle props
 *
 * @category Props
 */

/**
  @category Component
 */
const Rectangle = props => {
  const {
    id,
    children,
    outCircleStyle,
    innerCircleStyle,
    anchorStyle,
    fillStyle,
    onError,
    onFinish
  } = props;
  const painter = new RectanglePainter();
  const toFeatures = async points => {
    const features = [];
    points.forEach(p => features.push(createPointFeature(p, {
      type: 0
    })));
    if (points.length > 1) {
      const bounds = bbox(points);
      const [[minX, minY], [maxX, maxY]] = bounds;
      const polygonPoints = [[minX, minY], [minX, maxY], [maxX, maxY], [maxX, minY], [minX, minY]];
      features.push(createPolygonFeature(polygonPoints, {
        type: 0
      }));
    }
    return features;
  };
  return /*#__PURE__*/React.createElement(Shape, {
    id: id,
    paintner: painter,
    outCircleStyle: outCircleStyle,
    innerCircleStyle: innerCircleStyle,
    anchorStyle: anchorStyle,
    fillStyle: fillStyle,
    toFeatures: toFeatures,
    onError: onError,
    onFinish: onFinish
  }, children);
};
export default Rectangle;
//# sourceMappingURL=Rectangle.js.map