/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { CloseCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, CloseIcon, CheckIcon, ErrorIcon } from '@ldesign/icons-vue';
import { getBackgroundColor } from '../../utils/helper.js';
import { STATUS_ICON, CIRCLE_SIZE_PX, PRO_THEME, CIRCLE_FONT_SIZE_RATIO, CIRCLE_SIZE } from './const.js';
import props from './props.js';
import { renderLNodeJSX } from '../../utils/render-node.js';
import { getClassPrefixMixins, getGlobalIconMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import 'vue';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../_chunks/dep-a0f2090c.js';

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(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 = getClassPrefixMixins("progress");
var _Progress = mixins(classPrefixMixins, getGlobalIconMixins()).extend({
  name: "LProgress",
  props: _objectSpread({}, props),
  computed: {
    statusStyle: function statusStyle() {
      if (this.percentage >= 100) {
        return "success";
      }

      return this.status;
    },
    themeClass: function themeClass() {
      var Line = 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 = 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 && getBackgroundColor(this.color)
      };
    },
    circlePathStyle: function circlePathStyle() {
      var strokeColor = _typeof(this.color) === "object" ? "" : this.color;
      return {
        stroke: strokeColor
      };
    },
    isShowIcon: function isShowIcon() {
      return STATUS_ICON.includes(this.status) && typeof this.label === "boolean";
    },
    diameter: function diameter() {
      var diameter = CIRCLE_SIZE_PX.MEDIUM;

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

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

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

        case MEDIUM:
          diameter = CIRCLE_SIZE_PX.MEDIUM;
          break;

        case LARGE:
          diameter = 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 !== PRO_THEME.CIRCLE) {
        return {};
      }

      var fontSize = this.diameter * CIRCLE_FONT_SIZE_RATIO.MEDIUM;

      if (this.diameter <= CIRCLE_SIZE_PX.SMALL) {
        fontSize = this.diameter * CIRCLE_FONT_SIZE_RATIO.SMALL;
      } else if (this.diameter >= CIRCLE_SIZE_PX.LARGE) {
        fontSize = this.diameter * 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 === 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: CloseCircleFilledIcon,
        CheckCircleFilledIcon: CheckCircleFilledIcon,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon,
        CloseIcon: CloseIcon,
        CheckIcon: CheckIcon,
        ErrorIcon: ErrorIcon
      }),
          CloseCircleFilledIcon$1 = _this$useGlobalIcon.CloseCircleFilledIcon,
          CheckCircleFilledIcon$1 = _this$useGlobalIcon.CheckCircleFilledIcon,
          ErrorCircleFilledIcon$1 = _this$useGlobalIcon.ErrorCircleFilledIcon,
          CloseIcon$1 = _this$useGlobalIcon.CloseIcon,
          CheckIcon$1 = _this$useGlobalIcon.CheckIcon,
          ErrorIcon$1 = _this$useGlobalIcon.ErrorIcon;

      var CIRCLE_ICONS = {
        success: CheckIcon$1,
        warning: ErrorIcon$1,
        error: CloseIcon$1
      };
      var NORMAL_ICONS = {
        success: CheckCircleFilledIcon$1,
        warning: ErrorCircleFilledIcon$1,
        error: CloseCircleFilledIcon$1
      };
      return this.theme === PRO_THEME.CIRCLE ? CIRCLE_ICONS : NORMAL_ICONS;
    },
    getLabelContent: function getLabelContent() {
      var h = this.$createElement;
      var labelContent = "".concat(this.percentage, "%");
      var status = this.status || "";

      if (STATUS_ICON.includes(status) && this.theme !== 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")
    }, [renderLNodeJSX(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 === 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 === PRO_THEME.PLUMP && h("div", {
      "class": ["".concat(this.componentName, "__bar ").concat(this.componentName, "--plump ").concat(separateClasses), _defineProperty({}, "".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 === 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
    })])])]);
  }
});

export { _Progress as default };
//# sourceMappingURL=progress.js.map
