import * as _vue from "vue";

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; }

import { Circle as VCCircle } from '../vc-progress';
import { validProgress } from './utils';
var statusColorMap = {
  normal: '#108ee9',
  exception: '#ff5500',
  success: '#87d068'
};

function getPercentage(_ref) {
  var percent = _ref.percent,
      successPercent = _ref.successPercent;
  var ptg = validProgress(percent);
  if (!successPercent) return ptg;
  var successPtg = validProgress(successPercent);
  return [successPercent, validProgress(ptg - successPtg)];
}

function getStrokeColor(_ref2) {
  var progressStatus = _ref2.progressStatus,
      successPercent = _ref2.successPercent,
      strokeColor = _ref2.strokeColor;
  var color = strokeColor || statusColorMap[progressStatus];
  if (!successPercent) return color;
  return [statusColorMap.success, color];
}

var Circle = function Circle(_, _ref3) {
  var _wrapperClassName;

  var attrs = _ref3.attrs,
      slots = _ref3.slots;
  var prefixCls = attrs.prefixCls,
      width = attrs.width,
      strokeWidth = attrs.strokeWidth,
      trailColor = attrs.trailColor,
      strokeLinecap = attrs.strokeLinecap,
      gapPosition = attrs.gapPosition,
      gapDegree = attrs.gapDegree,
      type = attrs.type;
  var circleSize = width || 120;
  var circleStyle = {
    width: typeof circleSize === 'number' ? "".concat(circleSize, "px") : circleSize,
    height: typeof circleSize === 'number' ? "".concat(circleSize, "px") : circleSize,
    fontSize: "".concat(circleSize * 0.15 + 6, "px")
  };
  var circleWidth = strokeWidth || 6;
  var gapPos = gapPosition || type === 'dashboard' && 'bottom' || 'top';
  var gapDeg = gapDegree || type === 'dashboard' && 75;
  var strokeColor = getStrokeColor(attrs);
  var isGradient = Object.prototype.toString.call(strokeColor) === '[object Object]';
  var wrapperClassName = (_wrapperClassName = {}, _defineProperty(_wrapperClassName, "".concat(prefixCls, "-inner"), true), _defineProperty(_wrapperClassName, "".concat(prefixCls, "-circle-gradient"), isGradient), _wrapperClassName);
  return _vue.createVNode("div", {
    "class": wrapperClassName,
    "style": circleStyle
  }, [_vue.createVNode(VCCircle, {
    "percent": getPercentage(attrs),
    "strokeWidth": circleWidth,
    "trailWidth": circleWidth,
    "strokeColor": strokeColor,
    "strokeLinecap": strokeLinecap,
    "trailColor": trailColor,
    "prefixCls": prefixCls,
    "gapDegree": gapDeg,
    "gapPosition": gapPos
  }, null), slots === null || slots === void 0 ? void 0 : slots.default()]);
};

export default Circle;