"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

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

var _vue = _interopRequireWildcard(require("vue"));

var _vcProgress = require("../vc-progress");

var _utils = require("./utils");

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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

var statusColorMap = {
  normal: '#108ee9',
  exception: '#ff5500',
  success: '#87d068'
};

function getPercentage(_ref) {
  var percent = _ref.percent,
      successPercent = _ref.successPercent;
  var ptg = (0, _utils.validProgress)(percent);
  if (!successPercent) return ptg;
  var successPtg = (0, _utils.validProgress)(successPercent);
  return [successPercent, (0, _utils.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(_vcProgress.Circle, {
    "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()]);
};

var _default = Circle;
exports.default = _default;