/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @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 iconsVue = require('@ldesign/icons-vue');
var utils_helper = require('../utils/helper.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../utils/mixins.js');
var progress_props = require('./props.js');
var progress_constants = require('./constants.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');
require('vue');
require('@vue/composition-api');
require('lodash/kebabCase');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-7c884501.js');
require('dayjs');

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

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 classPrefixMixins = configProvider_configReceiver.getClassPrefixMixins("progress");
var _Progress = utils_mixins["default"](classPrefixMixins, configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "TProgress",
  props: _objectSpread({}, progress_props["default"]),
  computed: {
    statusStyle: function statusStyle() {
      if (!this.status && 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");
      var Plump = progress_constants.PRO_THEME.PLUMP;
      if (this.theme === Plump) height = "";
      return {
        height: height,
        backgroundColor: this.trackColor,
        borderRadius: height
      };
    },
    circleStrokeStyle: function circleStrokeStyle() {
      return {
        stroke: this.trackColor
      };
    },
    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 - this.circleStrokeWidth) / 2;
      var perimeter = Math.PI * 2 * radius;
      var percent = this.percentage / 100;
      return "".concat(perimeter * percent, "  ").concat(perimeter * (1 - percent));
    },
    plumpStyles: function plumpStyles() {
      return {};
    }
  },
  methods: {
    getIconMap: function getIconMap() {
      var _this$useGlobalIcon = this.useGlobalIcon({
          CloseCircleFilledIcon: iconsVue.CloseCircleFilledIcon,
          CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon,
          ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon,
          CloseIcon: iconsVue.CloseIcon,
          CheckIcon: iconsVue.CheckIcon,
          ErrorIcon: iconsVue.ErrorIcon
        }),
        CloseCircleFilledIcon = _this$useGlobalIcon.CloseCircleFilledIcon,
        CheckCircleFilledIcon = _this$useGlobalIcon.CheckCircleFilledIcon,
        ErrorCircleFilledIcon = _this$useGlobalIcon.ErrorCircleFilledIcon,
        CloseIcon = _this$useGlobalIcon.CloseIcon,
        CheckIcon = _this$useGlobalIcon.CheckIcon,
        ErrorIcon = _this$useGlobalIcon.ErrorIcon;
      var CIRCLE_ICONS = {
        success: CheckIcon,
        warning: ErrorIcon,
        error: CloseIcon
      };
      var NORMAL_ICONS = {
        success: CheckCircleFilledIcon,
        warning: ErrorCircleFilledIcon,
        error: 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(this.componentName, "__icon")]
        });
      }
      return labelContent;
    }
  },
  render: function render() {
    var h = arguments[0];
    var labelContent = h("div", {
      "class": "".concat(this.componentName, "__info")
    }, [utils_renderTnode.renderTNodeJSX(this, "label", this.getLabelContent())]);
    var PLUMP_SEPARATE = 10;
    var separateClasses = this.percentage > PLUMP_SEPARATE ? "".concat(this.componentName, "--over-ten") : "".concat(this.componentName, "--under-ten");
    return h("div", {
      "class": this.componentName
    }, [this.theme === progress_constants.PRO_THEME.LINE && h("div", {
      "class": "".concat(this.componentName, "--thin ").concat(this.componentName, "--status--").concat(this.statusStyle)
    }, [h("div", {
      "class": "".concat(this.componentName, "__bar"),
      "style": this.trackBgStyle
    }, [h("div", {
      "class": "".concat(this.componentName, "__inner"),
      "style": this.barStyle
    })]), labelContent]), this.theme === progress_constants.PRO_THEME.PLUMP && h("div", {
      "class": ["".concat(this.componentName, "__bar ").concat(this.componentName, "--plump ").concat(separateClasses), _defineProperty__default["default"]({}, "".concat(this.componentName, "--status--").concat(this.statusStyle), this.statusStyle)],
      "style": this.trackBgStyle
    }, [h("div", {
      "class": "".concat(this.componentName, "__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(this.componentName, "--circle ").concat(this.componentName, "--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(this.componentName, "__circle-outer"),
      "style": this.circleStrokeStyle
    }), this.percentage > 0 && 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(this.componentName, "__circle-inner"),
      "style": this.circlePathStyle
    })])])]);
  }
});

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