"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 = exports.ProgressProps = exports.ProgressSize = exports.ProgressType = void 0;

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

var _classNames2 = _interopRequireDefault(require("../_util/classNames"));

var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));

var _propsUtil = require("../_util/props-util");

var _configProvider = require("../config-provider");

var _CloseOutlined = _interopRequireDefault(require("@ant-design/icons-vue/CloseOutlined"));

var _CheckOutlined = _interopRequireDefault(require("@ant-design/icons-vue/CheckOutlined"));

var _CheckCircleFilled = _interopRequireDefault(require("@ant-design/icons-vue/CheckCircleFilled"));

var _CloseCircleFilled = _interopRequireDefault(require("@ant-design/icons-vue/CloseCircleFilled"));

var _line = _interopRequireDefault(require("./line"));

var _circle = _interopRequireDefault(require("./circle"));

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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

var ProgressStatuses = ['normal', 'exception', 'active', 'success'];

var ProgressType = _vueTypes.default.oneOf(['line', 'circle', 'dashboard']);

exports.ProgressType = ProgressType;

var ProgressSize = _vueTypes.default.oneOf(['default', 'small']);

exports.ProgressSize = ProgressSize;
var ProgressProps = {
  prefixCls: _vueTypes.default.string,
  type: ProgressType,
  percent: _vueTypes.default.number,
  successPercent: _vueTypes.default.number,
  format: _vueTypes.default.func,
  status: _vueTypes.default.oneOf(ProgressStatuses),
  showInfo: _vueTypes.default.bool,
  strokeWidth: _vueTypes.default.number,
  strokeLinecap: _vueTypes.default.oneOf(['butt', 'round', 'square']),
  strokeColor: _vueTypes.default.oneOfType([_vueTypes.default.string, _vueTypes.default.object]),
  trailColor: _vueTypes.default.string,
  width: _vueTypes.default.number,
  gapDegree: _vueTypes.default.number,
  gapPosition: _vueTypes.default.oneOf(['top', 'bottom', 'left', 'right']),
  size: ProgressSize
};
exports.ProgressProps = ProgressProps;
var _default2 = {
  name: 'AProgress',
  props: (0, _propsUtil.initDefaultProps)(ProgressProps, {
    type: 'line',
    percent: 0,
    showInfo: true,
    trailColor: '#f3f3f3',
    size: 'default',
    gapDegree: 0,
    strokeLinecap: 'round'
  }),
  setup: function setup() {
    return {
      configProvider: (0, _vue.inject)('configProvider', _configProvider.ConfigConsumerProps)
    };
  },
  methods: {
    getPercentNumber: function getPercentNumber() {
      var _this$$props = this.$props,
          successPercent = _this$$props.successPercent,
          _this$$props$percent = _this$$props.percent,
          percent = _this$$props$percent === void 0 ? 0 : _this$$props$percent;
      return parseInt(successPercent !== undefined ? successPercent.toString() : percent.toString(), 10);
    },
    getProgressStatus: function getProgressStatus() {
      var status = this.$props.status;

      if (ProgressStatuses.indexOf(status) < 0 && this.getPercentNumber() >= 100) {
        return 'success';
      }

      return status || 'normal';
    },
    renderProcessInfo: function renderProcessInfo(prefixCls, progressStatus) {
      var _this$$props2 = this.$props,
          showInfo = _this$$props2.showInfo,
          format = _this$$props2.format,
          type = _this$$props2.type,
          percent = _this$$props2.percent,
          successPercent = _this$$props2.successPercent;
      if (!showInfo) return null;
      var text;

      var textFormatter = format || this.$slots.format || function (percentNumber) {
        return "".concat(percentNumber, "%");
      };

      var isLineType = type === 'line';

      if (format || this.$slots.format || progressStatus !== 'exception' && progressStatus !== 'success') {
        text = textFormatter((0, _utils.validProgress)(percent), (0, _utils.validProgress)(successPercent));
      } else if (progressStatus === 'exception') {
        text = isLineType ? _vue.createVNode(_CloseCircleFilled.default, null, null) : _vue.createVNode(_CloseOutlined.default, null, null);
      } else if (progressStatus === 'success') {
        text = isLineType ? _vue.createVNode(_CheckCircleFilled.default, null, null) : _vue.createVNode(_CheckOutlined.default, null, null);
      }

      return _vue.createVNode("span", {
        "class": "".concat(prefixCls, "-text"),
        "title": typeof text === 'string' ? text : undefined
      }, [text]);
    }
  },
  render: function render() {
    var _classNames;

    var props = (0, _propsUtil.getOptionProps)(this);
    var customizePrefixCls = props.prefixCls,
        size = props.size,
        type = props.type,
        showInfo = props.showInfo;
    var getPrefixCls = this.configProvider.getPrefixCls;
    var prefixCls = getPrefixCls('progress', customizePrefixCls);
    var progressStatus = this.getProgressStatus();
    var progressInfo = this.renderProcessInfo(prefixCls, progressStatus);
    var progress; // Render progress shape

    if (type === 'line') {
      var lineProps = _objectSpread(_objectSpread({}, props), {}, {
        prefixCls: prefixCls
      });

      progress = _vue.createVNode(_line.default, lineProps, {
        default: function _default() {
          return [progressInfo];
        }
      });
    } else if (type === 'circle' || type === 'dashboard') {
      var circleProps = _objectSpread(_objectSpread({}, props), {}, {
        prefixCls: prefixCls,
        progressStatus: progressStatus
      });

      progress = _vue.createVNode(_circle.default, circleProps, {
        default: function _default() {
          return [progressInfo];
        }
      });
    }

    var classString = (0, _classNames2.default)(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(type === 'dashboard' && 'circle' || type), true), _defineProperty(_classNames, "".concat(prefixCls, "-status-").concat(progressStatus), true), _defineProperty(_classNames, "".concat(prefixCls, "-show-info"), showInfo), _defineProperty(_classNames, "".concat(prefixCls, "-").concat(size), size), _classNames));
    var progressProps = {
      class: classString
    };
    return _vue.createVNode("div", progressProps, [progress]);
  }
};
exports.default = _default2;