/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _typeof = require('@babel/runtime/helpers/typeof');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var Vue = require('vue');
var tdesignIconsVue = require('tdesign-icons-vue');
var config = require('../config.js');
var utils_helper = require('../utils/helper.js');
var progress_constants = require('./constants.js');
var progress_props = require('./props.js');
var utils_renderTnode = require('../utils/render-tnode.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var name = "".concat(config.prefix, "-progress");
var _Progress = Vue__default["default"].extend({
  name: "TProgress",
  props: _objectSpread({}, progress_props["default"]),
  data: function data() {
    return {
      name: name
    };
  },
  computed: {
    statusStyle: function statusStyle() {
      if (this.percentage >= 100) {
        return "success";
      }

      return this.status;
    },
    themeClass: function themeClass() {
      var Line = progress_constants.PRO_THEME.LINE;

      if (this.theme === Line) {
        return "thin";
      }

      return this.theme;
    },
    trackBgStyle: function trackBgStyle() {
      var strokeWidth = this.strokeWidth;
      var height = typeof strokeWidth === "string" ? strokeWidth : "".concat(strokeWidth, "px");
      return {
        height: height,
        backgroundColor: this.trackColor,
        borderRadius: height
      };
    },
    barStyle: function barStyle() {
      return {
        width: "".concat(this.percentage, "%"),
        background: this.color && utils_helper.getBackgroundColor(this.color)
      };
    },
    circlePathStyle: function circlePathStyle() {
      var strokeColor = _typeof__default["default"](this.color) === "object" ? "" : this.color;
      return {
        stroke: strokeColor
      };
    },
    isShowIcon: function isShowIcon() {
      return progress_constants.STATUS_ICON.includes(this.status) && typeof this.label === "boolean";
    },
    diameter: function diameter() {
      var diameter = progress_constants.CIRCLE_SIZE_PX.MEDIUM;

      if (!this.size) {
        return diameter;
      }

      var SMALL = progress_constants.CIRCLE_SIZE.SMALL,
          LARGE = progress_constants.CIRCLE_SIZE.LARGE,
          MEDIUM = progress_constants.CIRCLE_SIZE.MEDIUM;

      switch (this.size) {
        case SMALL:
          diameter = progress_constants.CIRCLE_SIZE_PX.SMALL;
          break;

        case MEDIUM:
          diameter = progress_constants.CIRCLE_SIZE_PX.MEDIUM;
          break;

        case LARGE:
          diameter = progress_constants.CIRCLE_SIZE_PX.LARGE;
          break;

        default:
          diameter = Number(this.size);
          break;
      }

      return diameter;
    },
    rPoints: function rPoints() {
      return this.diameter / 2;
    },
    radius: function radius() {
      return this.rPoints - this.circleStrokeWidth / 2;
    },
    circleStyle: function circleStyle() {
      if (this.theme !== progress_constants.PRO_THEME.CIRCLE) {
        return {};
      }

      var fontSize = this.diameter * progress_constants.CIRCLE_FONT_SIZE_RATIO.MEDIUM;

      if (this.diameter <= progress_constants.CIRCLE_SIZE_PX.SMALL) {
        fontSize = this.diameter * progress_constants.CIRCLE_FONT_SIZE_RATIO.SMALL;
      } else if (this.diameter >= progress_constants.CIRCLE_SIZE_PX.LARGE) {
        fontSize = this.diameter * progress_constants.CIRCLE_FONT_SIZE_RATIO.LARGE;
      }

      return {
        width: "".concat(this.diameter, "px"),
        height: "".concat(this.diameter, "px"),
        fontSize: "".concat(fontSize, "px")
      };
    },
    circleStrokeWidth: function circleStrokeWidth() {
      var defaultWidth = this.size === progress_constants.CIRCLE_SIZE.SMALL ? 4 : 6;
      return this.strokeWidth ? Number(this.strokeWidth) : defaultWidth;
    },
    strokeDashArr: function strokeDashArr() {
      var radius = this.diameter / 2;
      var perimeter = Math.PI * 2 * (radius - this.circleStrokeWidth);
      var percent = this.percentage / 100;
      return "".concat(perimeter * percent, "  ").concat(perimeter * (1 - percent));
    },
    plumpStyles: function plumpStyles() {
      return {};
    }
  },
  methods: {
    getIconMap: function getIconMap() {
      var CIRCLE_ICONS = {
        success: tdesignIconsVue.CheckIcon,
        warning: tdesignIconsVue.ErrorIcon,
        error: tdesignIconsVue.CloseIcon
      };
      var NORMAL_ICONS = {
        success: tdesignIconsVue.CheckCircleFilledIcon,
        warning: tdesignIconsVue.ErrorCircleFilledIcon,
        error: tdesignIconsVue.CloseCircleFilledIcon
      };
      return this.theme === progress_constants.PRO_THEME.CIRCLE ? CIRCLE_ICONS : NORMAL_ICONS;
    },
    getLabelContent: function getLabelContent() {
      var h = this.$createElement;
      var labelContent = "".concat(this.percentage, "%");
      var status = this.status || "";

      if (progress_constants.STATUS_ICON.includes(status) && this.theme !== progress_constants.PRO_THEME.PLUMP) {
        var components = this.getIconMap();
        var component = components[status];

        if (component) {
          labelContent = h(component, {
            "class": ["".concat(name, "__icon")]
          });
        }
      }

      return labelContent;
    }
  },
  render: function render() {
    var h = arguments[0];
    var labelContent = h("div", {
      "class": "".concat(name, "__info")
    }, [utils_renderTnode.renderTNodeJSX(this, "label", this.getLabelContent())]);
    var PLUMP_SEPARATE = 10;
    var separateClasses = this.percentage > PLUMP_SEPARATE ? "".concat(name, "--over-ten") : "".concat(name, "--under-ten");
    return h("div", {
      "class": name
    }, [this.theme === progress_constants.PRO_THEME.LINE && h("div", {
      "class": "".concat(name, "--thin ").concat(name, "--status--").concat(this.statusStyle)
    }, [h("div", {
      "class": "".concat(name, "__bar"),
      "style": this.trackBgStyle
    }, [h("div", {
      "class": "".concat(name, "__inner"),
      "style": this.barStyle
    })]), labelContent]), this.theme === progress_constants.PRO_THEME.PLUMP && h("div", {
      "class": ["".concat(name, "__bar ").concat(name, "--plump ").concat(separateClasses), _defineProperty__default["default"]({}, "".concat(name, "--status--").concat(this.statusStyle), this.statusStyle)],
      "style": this.trackBgStyle
    }, [h("div", {
      "class": "".concat(name, "__inner"),
      "style": this.barStyle
    }, [this.percentage > PLUMP_SEPARATE && labelContent]), this.percentage < PLUMP_SEPARATE && labelContent]), this.theme === progress_constants.PRO_THEME.CIRCLE && h("div", {
      "class": "".concat(name, "--circle ").concat(name, "--status--").concat(this.statusStyle),
      "style": this.circleStyle
    }, [labelContent, h("svg", {
      "attrs": {
        "width": this.diameter,
        "height": this.diameter,
        "viewBox": "0 0 ".concat(this.diameter, " ").concat(this.diameter)
      }
    }, [h("circle", {
      "attrs": {
        "cx": this.rPoints,
        "cy": this.rPoints,
        "r": this.radius,
        "stroke-width": this.circleStrokeWidth,
        "stroke": this.trackColor,
        "fill": "none"
      },
      "class": "".concat(name, "__circle-outer")
    }), h("circle", {
      "attrs": {
        "cx": this.rPoints,
        "cy": this.rPoints,
        "r": this.radius,
        "stroke-width": this.circleStrokeWidth,
        "fill": "none",
        "stroke-linecap": "round",
        "transform": "matrix(0,-1,1,0,0,".concat(this.diameter, ")"),
        "stroke-dasharray": this.strokeDashArr
      },
      "class": "".concat(name, "__circle-inner"),
      "style": this.circlePathStyle
    })])])]);
  }
});

exports["default"] = _Progress;
//# sourceMappingURL=progress.js.map
