var _excluded = ["text", "y", "isBold"],
    _excluded2 = ["name"];

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import React, { memo } from 'react';
import { getWrapBounds, getPathAttr, getStrokeWidth, arraySum } from "./util";
var BASE_COLOR = '#e3e3e3';
export var DrawArc = function DrawArc(_ref) {
  var d = _ref.d,
      stroke = _ref.stroke,
      strokeWidth = _ref.strokeWidth;
  return /*#__PURE__*/React.createElement("path", {
    fill: "none",
    stroke: stroke,
    strokeWidth: strokeWidth,
    d: d
  });
};
export var DrawText = function DrawText(_ref2) {
  var text = _ref2.text,
      y = _ref2.y,
      isBold = _ref2.isBold,
      props = _objectWithoutProperties(_ref2, _excluded);

  return /*#__PURE__*/React.createElement("text", Object.assign({
    x: "50%",
    y: y
  }, props), isBold ? /*#__PURE__*/React.createElement("tspan", {
    fontWeight: "bold"
  }, text) : text);
};
DrawText.defaultProps = {
  y: 0,
  isBold: false
};
export var DrawSvg = function DrawSvg(_ref3) {
  var bounds = _ref3.bounds,
      children = _ref3.children;
  return /*#__PURE__*/React.createElement("svg", Object.assign({
    xmlns: "http://www.w3.org/2000/svg"
  }, bounds), children);
};
DrawSvg.defaultProps = {
  bounds: {}
};
export var DrawCircle = function DrawCircle(_ref4) {
  var bounds = _ref4.bounds,
      radius = _ref4.radius,
      _ref4$color = _ref4.color,
      color = _ref4$color === void 0 ? BASE_COLOR : _ref4$color;
  var strokeWidth = getStrokeWidth(radius);
  var realRadius = radius - strokeWidth;
  return /*#__PURE__*/React.createElement(DrawSvg, {
    bounds: bounds
  }, /*#__PURE__*/React.createElement("circle", {
    cx: "50%",
    cy: "50%",
    fill: "none",
    r: realRadius,
    stroke: color,
    strokeWidth: strokeWidth
  }));
};
DrawCircle.defaultProps = {
  bounds: {}
};
/**
 * 圆环有两种：circle 绘制的圆 | path 绘制圆弧拼接
 * 只有一种数据源不为0时使用 circle
 * 多种数据都不为0时使用 path
 */

var PodCircle = /*#__PURE__*/memo(function (_ref5) {
  var size = _ref5.size,
      style = _ref5.style,
      dataSource = _ref5.dataSource;

  var bounds = _objectSpread(_objectSpread({}, getWrapBounds(size)), style);

  var width = bounds.width;
  var radius = width / 2;

  if (!Array.isArray(dataSource) || !dataSource.length) {
    return /*#__PURE__*/React.createElement(DrawCircle, {
      bounds: bounds,
      radius: radius
    });
  }

  var values = dataSource.map(function (_ref6) {
    var value = _ref6.value;
    return value;
  });
  var total = arraySum(values);

  if (!total) {
    return /*#__PURE__*/React.createElement(DrawCircle, {
      bounds: bounds,
      radius: radius
    });
  } else if (values.includes(total)) {
    var circle = dataSource.find(function (_ref7) {
      var value = _ref7.value;
      return value === total;
    });
    return /*#__PURE__*/React.createElement(DrawCircle, {
      bounds: bounds,
      radius: radius,
      color: circle.stroke
    });
  } else {
    var pathAttr = getPathAttr(radius, dataSource, total);
    return /*#__PURE__*/React.createElement(DrawSvg, {
      bounds: bounds
    }, pathAttr.map(function (_ref8) {
      var name = _ref8.name,
          props = _objectWithoutProperties(_ref8, _excluded2);

      return /*#__PURE__*/React.createElement(DrawArc, Object.assign({
        key: name
      }, props));
    }));
  }
});
PodCircle.defaultProps = {
  style: {},
  dataSource: []
};
export default /*#__PURE__*/memo(PodCircle);