"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireWildcard(require("react"));

var _enhancer = _interopRequireDefault(require("./enhancer"));

var _types = require("./types");

var _excluded = ["prefixCls", "strokeWidth", "trailWidth", "strokeColor", "percent", "trailColor", "strokeLinecap", "style", "className"];

var Circle = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(Circle, _Component);

  var _super = (0, _createSuper2["default"])(Circle);

  function Circle() {
    (0, _classCallCheck2["default"])(this, Circle);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(Circle, [{
    key: "getPathStyles",
    value: function getPathStyles() {
      var _this$props = this.props,
          percent = _this$props.percent,
          strokeWidth = _this$props.strokeWidth,
          _this$props$gapDegree = _this$props.gapDegree,
          gapDegree = _this$props$gapDegree === void 0 ? 0 : _this$props$gapDegree,
          gapPosition = _this$props.gapPosition;
      var radius = 50 - strokeWidth / 2;
      var beginPositionX = 0;
      var beginPositionY = -radius;
      var endPositionX = 0;
      var endPositionY = -2 * radius;

      switch (gapPosition) {
        case 'left':
          beginPositionX = -radius;
          beginPositionY = 0;
          endPositionX = 2 * radius;
          endPositionY = 0;
          break;

        case 'right':
          beginPositionX = radius;
          beginPositionY = 0;
          endPositionX = -2 * radius;
          endPositionY = 0;
          break;

        case 'bottom':
          beginPositionY = radius;
          endPositionY = 2 * radius;
          break;

        default:
      }

      var pathString = "M 50,50 m ".concat(beginPositionX, ",").concat(beginPositionY, "\n     a ").concat(radius, ",").concat(radius, " 0 1 1 ").concat(endPositionX, ",").concat(-endPositionY, "\n     a ").concat(radius, ",").concat(radius, " 0 1 1 ").concat(-endPositionX, ",").concat(endPositionY);
      var len = Math.PI * 2 * radius;
      var trailPathStyle = {
        strokeDasharray: "".concat(len - gapDegree, "px ").concat(len, "px"),
        strokeDashoffset: "-".concat(gapDegree / 2, "px"),
        transition: 'stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s'
      };
      var strokePathStyle = {
        strokeDasharray: "".concat(percent / 100 * (len - gapDegree), "px ").concat(len, "px"),
        strokeDashoffset: "-".concat(gapDegree / 2, "px"),
        transition: 'stroke-dashoffset .3s ease 0s, stroke-dasharray .3s ease 0s, stroke .3s, stroke-width .06s ease .3s' // eslint-disable-line

      };
      return {
        pathString: pathString,
        trailPathStyle: trailPathStyle,
        strokePathStyle: strokePathStyle
      };
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props2 = this.props,
          prefixCls = _this$props2.prefixCls,
          strokeWidth = _this$props2.strokeWidth,
          trailWidth = _this$props2.trailWidth,
          strokeColor = _this$props2.strokeColor,
          percent = _this$props2.percent,
          trailColor = _this$props2.trailColor,
          strokeLinecap = _this$props2.strokeLinecap,
          style = _this$props2.style,
          className = _this$props2.className,
          restProps = (0, _objectWithoutProperties2["default"])(_this$props2, _excluded);
      var pathStyles = this.getPathStyles();
      var pathString = pathStyles.pathString;
      var trailPathStyle = pathStyles.trailPathStyle,
          strokePathStyle = pathStyles.strokePathStyle;
      trailPathStyle = trailColor ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, trailPathStyle), {}, {
        stroke: trailColor
      }) : trailPathStyle;
      strokePathStyle = strokeColor ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, strokePathStyle), {}, {
        stroke: strokeColor
      }) : strokePathStyle;
      delete restProps.percent;
      delete restProps.gapDegree;
      delete restProps.gapPosition;
      return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
        className: "".concat(prefixCls, "-circle ").concat(className),
        viewBox: "0 0 100 100",
        style: style
      }, restProps), /*#__PURE__*/_react["default"].createElement("path", {
        className: "".concat(prefixCls, "-circle-trail"),
        d: pathString,
        stroke: trailColor,
        strokeWidth: trailWidth || strokeWidth,
        fillOpacity: "0",
        style: trailPathStyle
      }), /*#__PURE__*/_react["default"].createElement("path", {
        className: "".concat(prefixCls, "-circle-path"),
        d: pathString,
        strokeLinecap: strokeLinecap,
        stroke: strokeColor,
        strokeWidth: this.props.percent === 0 ? 0 : strokeWidth,
        fillOpacity: "0",
        ref: function ref(path) {
          _this.path = path;
        },
        style: strokePathStyle
      }));
    }
  }]);
  return Circle;
}(_react.Component);

(0, _defineProperty2["default"])(Circle, "defaultProps", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _types.defaultProps), {}, {
  gapPosition: 'top'
}));

var _default = (0, _enhancer["default"])(Circle);

exports["default"] = _default;
//# sourceMappingURL=Circle.js.map
