import _extends from "@babel/runtime/helpers/esm/extends";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
var VIEW_BOX_SIZE = 100;
var posMap = {
  top: -90,
  right: 0,
  bottom: 90,
  left: 180
};
/**
 * CircularProgress
 */

export default function CircularProgress(props) {
  var _classNames;

  var infoFormat = props.infoFormat,
      className = props.className,
      value = props.value,
      max = props.max,
      min = props.min,
      prefixCls = props.prefixCls,
      showInfo = props.showInfo,
      strokeWidth = props.strokeWidth,
      size = props.size,
      style = props.style,
      gapDegree = props.gapDegree,
      gapPosition = props.gapPosition,
      showShadow = props.showShadow,
      pathProps = props.pathProps,
      pathColor = props.pathColor,
      color = props.color,
      other = _objectWithoutProperties(props, ["infoFormat", "className", "value", "max", "min", "prefixCls", "showInfo", "strokeWidth", "size", "style", "gapDegree", "gapPosition", "showShadow", "pathProps", "pathColor", "color"]);

  var classes = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-color-").concat(color), value !== max), _defineProperty(_classNames, "".concat(prefixCls, "-color-success"), value === max), _classNames), className);
  var radius = (VIEW_BOX_SIZE - strokeWidth - 8) / 2;
  var trailLength = 2 * Math.PI * radius * (360 - gapDegree) / 360;
  var trailStyle = {
    strokeDasharray: Math.round(trailLength * 1000) / 1000,
    transform: "rotateZ(".concat(posMap[gapPosition] + gapDegree / 2, "deg)")
  };

  var pathStyle = _objectSpread({
    strokeDashoffset: "".concat(Math.round((max - value) / (max - min) * trailLength * 1000) / 1000, "px")
  }, trailStyle, pathProps.style || {});

  if (pathColor) {
    pathStyle.stroke = pathColor;
  }

  return React.createElement("div", _extends({
    className: classes,
    style: _objectSpread({
      width: size,
      height: size
    }, style),
    role: "progressbar",
    "aria-valuenow": value,
    "aria-valuemin": min,
    "aria-valuemax": max
  }, other), React.createElement("svg", {
    viewBox: "0 0 ".concat(VIEW_BOX_SIZE, " ").concat(VIEW_BOX_SIZE)
  }, React.createElement("circle", {
    style: trailStyle,
    className: "".concat(prefixCls, "-trail"),
    cx: VIEW_BOX_SIZE / 2,
    cy: VIEW_BOX_SIZE / 2,
    r: radius,
    fill: "none",
    strokeWidth: strokeWidth
  }), showShadow ? React.createElement("filter", {
    id: "dropshadow",
    height: "150%"
  }, React.createElement("feGaussianBlur", {
    in: "SourceAlpha",
    stdDeviation: "2"
  }), React.createElement("feOffset", {
    dx: "-1",
    dy: "1",
    result: "offsetblur"
  }), React.createElement("feComponentTransfer", null, React.createElement("feFuncA", {
    type: "linear",
    slope: "0.2"
  })), React.createElement("feMerge", null, React.createElement("feMergeNode", null), React.createElement("feMergeNode", {
    in: "SourceGraphic"
  }))) : null, React.createElement("circle", _extends({
    style: pathStyle,
    className: "".concat(prefixCls, "-path"),
    cx: VIEW_BOX_SIZE / 2,
    cy: VIEW_BOX_SIZE / 2,
    r: radius,
    fill: "none",
    strokeWidth: strokeWidth,
    filter: showShadow ? 'url(#dropshadow)' : undefined
  }, pathProps))), showInfo ? React.createElement("div", {
    className: "".concat(prefixCls, "-info")
  }, infoFormat(value)) : null);
}
CircularProgress.propTypes = {
  prefixCls: PropTypes.string,
  className: PropTypes.string,

  /** 当前值 */
  value: PropTypes.number,

  /** 最大值 */
  max: PropTypes.number,

  /** 最小值 */
  min: PropTypes.number,

  /** 进度信息 function(percent) => node */
  infoFormat: PropTypes.func,

  /** 是否显示进度信息 */
  showInfo: PropTypes.bool,

  /** 宽度 */
  strokeWidth: PropTypes.number,

  /** 半径 */
  radius: PropTypes.number,

  /** 缺口位置 */
  gapPosition: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),

  /** 缺口大小（单位：角度） */
  gapDegree: PropTypes.number,

  /** 显示阴影 */
  showShadow: PropTypes.bool,

  /** 进度条元素属性 */
  pathProps: PropTypes.object,

  /** 进度条颜色 */
  pathColor: PropTypes.string,
  // showTrail: PropTypes.bool,
  color: PropTypes.oneOf(['primary', 'success', 'warning', 'info', 'error'])
};
CircularProgress.defaultProps = {
  prefixCls: 'ne-circular-progress',
  value: 0,
  infoFormat: function infoFormat(percent) {
    return "".concat(percent, "%");
  },
  showInfo: true,
  strokeWidth: 4,
  max: 100,
  min: 0,
  size: 100,
  gapDegree: 0,
  gapPosition: 'top',
  showShadow: true,
  pathColor: '',
  color: 'primary',
  pathProps: {}
};