import "core-js/modules/es6.number.constructor";
import _createClass from "@babel/runtime-corejs2/helpers/createClass";
import _inheritsLoose from "../../inheritsLoose";
import _defineProperty from "@babel/runtime-corejs2/helpers/defineProperty";

/**
 * Created by sylvia on 2017/10/16.
 */
import Intact from 'intact-angular';
import template from './index.vdt';
import '../../styles/kpc.styl';
import './index.styl';

function fixPercent(percent) {
  if (percent > 100) percent = 100;
  if (percent < 0) percent = 0;
  return percent;
}

var Progress =
/*#__PURE__*/
function (_Intact) {
  _inheritsLoose(Progress, _Intact);

  function Progress() {
    return _Intact.apply(this, arguments) || this;
  }

  var _proto = Progress.prototype;

  _proto.defaults = function defaults() {
    return {
      type: 'bar',
      // bar circle
      percent: 0,
      // 0~100
      size: 'default',
      // small mini
      isOuterText: true,
      isInnerText: false,
      status: 'active',
      strokeWidth: 4
    };
  };

  _proto._init = function _init() {
    var _this = this;

    this._initStatus = this.get('status');
    this.on('$change:percent', function (c, percent) {
      percent = fixPercent(percent);
      var status = percent === 100 ? 'success' : _this._initStatus;

      _this.set({
        status: status,
        percent: percent
      });
    });
    this.on('$change:status', function (c, status) {
      if (status !== 'success') _this._initStatus = status;
    });
    this.set('percent', fixPercent(this.get('percent')));

    if (this.get('percent') == 100) {
      this.set('status', 'success');
    }
  };

  _createClass(Progress, [{
    key: "template",
    get: function get() {
      return template;
    }
  }]);

  return Progress;
}(Intact);

_defineProperty(Progress, "propTypes", {
  type: ['bar', 'circle'],
  percent: [Number, String],
  size: ['default', 'small', 'mini'],
  isOuterText: Boolean,
  isInnerText: Boolean,
  status: ['active', 'success', 'error', 'normal', 'warning'],
  strokeWidth: Number
});

export { Progress as default };
export { Progress };