/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var iconsVueNext = require('@ldesign/icons-vue-next');
var isObject = require('lodash/isObject');
var isString = require('lodash/isString');
var utils_helper = require('../utils/helper.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_useGlobalIcon = require('../hooks/useGlobalIcon.js');
var hooks_tnode = require('../hooks/tnode.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('lodash/isUndefined');
require('lodash/isNull');
require('lodash/isArray');
require('lodash/isNumber');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('dayjs');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);

var _Progress = vue.defineComponent({
  name: "TProgress",
  props: progress_props["default"],
  setup: function setup(props2) {
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("progress");
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        CloseCircleFilledIcon: iconsVueNext.CloseCircleFilledIcon,
        CheckCircleFilledIcon: iconsVueNext.CheckCircleFilledIcon,
        ErrorCircleFilledIcon: iconsVueNext.ErrorCircleFilledIcon,
        CloseIcon: iconsVueNext.CloseIcon,
        CheckIcon: iconsVueNext.CheckIcon,
        ErrorIcon: iconsVueNext.ErrorIcon
      }),
      CloseCircleFilledIcon = _useGlobalIcon.CloseCircleFilledIcon,
      CheckCircleFilledIcon = _useGlobalIcon.CheckCircleFilledIcon,
      ErrorCircleFilledIcon = _useGlobalIcon.ErrorCircleFilledIcon,
      CloseIcon = _useGlobalIcon.CloseIcon,
      CheckIcon = _useGlobalIcon.CheckIcon,
      ErrorIcon = _useGlobalIcon.ErrorIcon;
    var statusStyle = vue.computed(function () {
      if (props2.percentage >= 100) return "success";
      return props2.status || "default";
    });
    var trackBgStyle = vue.computed(function () {
      var style = {};
      if (props2.strokeWidth) {
        var height = isString__default["default"](props2.strokeWidth) ? props2.strokeWidth : "".concat(props2.strokeWidth, "px");
        style.height = height;
        style.borderRadius = height;
      }
      if (props2.trackColor) style.backgroundColor = props2.trackColor;
      return style;
    });
    var barStyle = vue.computed(function () {
      return {
        width: "".concat(props2.percentage, "%"),
        background: props2.color && utils_helper.getBackgroundColor(props2.color)
      };
    });
    var circlePathStyle = vue.computed(function () {
      var strokeColor = isObject__default["default"](props2.color) ? "" : props2.color;
      return {
        stroke: strokeColor
      };
    });
    var circleOuterStyle = vue.computed(function () {
      var strokeColor = isObject__default["default"](props2.trackColor) ? "" : props2.trackColor;
      return {
        stroke: strokeColor
      };
    });
    var diameter = vue.computed(function () {
      var diameter2 = progress_constants.CIRCLE_SIZE_PX.MEDIUM;
      if (!props2.size) return diameter2;
      var SMALL = progress_constants.CIRCLE_SIZE.SMALL,
        LARGE = progress_constants.CIRCLE_SIZE.LARGE,
        MEDIUM = progress_constants.CIRCLE_SIZE.MEDIUM;
      switch (props2.size) {
        case SMALL:
          diameter2 = progress_constants.CIRCLE_SIZE_PX.SMALL;
          break;
        case MEDIUM:
          diameter2 = progress_constants.CIRCLE_SIZE_PX.MEDIUM;
          break;
        case LARGE:
          diameter2 = progress_constants.CIRCLE_SIZE_PX.LARGE;
          break;
        default:
          diameter2 = Number(props2.size);
          break;
      }
      return diameter2;
    });
    var rPoints = vue.computed(function () {
      return diameter.value / 2;
    });
    var radius = vue.computed(function () {
      return rPoints.value - circleStrokeWidth.value / 2;
    });
    var circleStyle = vue.computed(function () {
      if (props2.theme !== progress_constants.PRO_THEME.CIRCLE) return {};
      var fontSize = diameter.value * progress_constants.CIRCLE_FONT_SIZE_RATIO.MEDIUM;
      if (diameter.value <= progress_constants.CIRCLE_SIZE_PX.SMALL) fontSize = diameter.value * progress_constants.CIRCLE_FONT_SIZE_RATIO.SMALL;else if (diameter.value >= progress_constants.CIRCLE_SIZE_PX.LARGE) fontSize = diameter.value * progress_constants.CIRCLE_FONT_SIZE_RATIO.LARGE;
      return {
        width: "".concat(diameter.value, "px"),
        height: "".concat(diameter.value, "px"),
        fontSize: "".concat(fontSize, "px")
      };
    });
    var circleStrokeWidth = vue.computed(function () {
      var defaultWidth = props2.size === progress_constants.CIRCLE_SIZE.SMALL ? 4 : 6;
      return props2.strokeWidth ? Number(props2.strokeWidth) : defaultWidth;
    });
    var strokeDashArr = vue.computed(function () {
      var radius2 = (diameter.value - circleStrokeWidth.value) / 2;
      var perimeter = Math.PI * 2 * radius2;
      var percent = props2.percentage / 100;
      return "".concat(perimeter * percent, "  ").concat(perimeter * (1 - percent));
    });
    var getIconMap = function getIconMap() {
      var CIRCLE_ICONS = {
        success: CheckIcon,
        warning: ErrorIcon,
        error: CloseIcon
      };
      var NORMAL_ICONS = {
        success: CheckCircleFilledIcon,
        warning: ErrorCircleFilledIcon,
        error: CloseCircleFilledIcon
      };
      return props2.theme === progress_constants.PRO_THEME.CIRCLE ? CIRCLE_ICONS : NORMAL_ICONS;
    };
    var getLabelContent = function getLabelContent() {
      var labelContent = "".concat(props2.percentage, "%");
      var status = props2.status || "";
      if (progress_constants.STATUS_ICON.includes(status) && props2.theme !== progress_constants.PRO_THEME.PLUMP) {
        var components = getIconMap();
        var component = components[status];
        if (component) labelContent = vue.createVNode(component, {
          "class": ["".concat(COMPONENT_NAME.value, "__icon")]
        }, null);
      }
      return labelContent;
    };
    return function () {
      var labelContent = vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__info")
      }, [renderTNodeJSX("label", getLabelContent())]);
      var PLUMP_SEPARATE = 10;
      var separateClasses = props2.percentage > PLUMP_SEPARATE ? "".concat(COMPONENT_NAME.value, "--over-ten") : "".concat(COMPONENT_NAME.value, "--under-ten");
      return vue.createVNode("div", {
        "class": COMPONENT_NAME.value
      }, [props2.theme === progress_constants.PRO_THEME.LINE && vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "--thin ").concat(COMPONENT_NAME.value, "--status--").concat(statusStyle.value)
      }, [vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__bar"),
        "style": trackBgStyle.value
      }, [vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__inner"),
        "style": barStyle.value
      }, null)]), labelContent]), props2.theme === progress_constants.PRO_THEME.PLUMP && vue.createVNode("div", {
        "class": ["".concat(COMPONENT_NAME.value, "__bar ").concat(COMPONENT_NAME.value, "--plump ").concat(separateClasses), _defineProperty__default["default"]({}, "".concat(COMPONENT_NAME.value, "--status--").concat(statusStyle.value), statusStyle.value)],
        "style": trackBgStyle.value
      }, [vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__inner"),
        "style": barStyle.value
      }, [props2.percentage > PLUMP_SEPARATE && labelContent]), props2.percentage <= PLUMP_SEPARATE && labelContent]), props2.theme === progress_constants.PRO_THEME.CIRCLE && vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "--circle ").concat(COMPONENT_NAME.value, "--status--").concat(statusStyle.value),
        "style": circleStyle.value
      }, [labelContent, vue.createVNode("svg", {
        "width": diameter.value,
        "height": diameter.value,
        "viewBox": "0 0 ".concat(diameter.value, " ").concat(diameter.value)
      }, [vue.createVNode("circle", {
        "cx": rPoints.value,
        "cy": rPoints.value,
        "r": radius.value,
        "stroke-width": circleStrokeWidth.value,
        "fill": "none",
        "class": ["".concat(COMPONENT_NAME.value, "__circle-outer")],
        "style": circleOuterStyle.value
      }, null), props2.percentage > 0 && vue.createVNode("circle", {
        "cx": rPoints.value,
        "cy": rPoints.value,
        "r": radius.value,
        "stroke-width": circleStrokeWidth.value,
        "fill": "none",
        "stroke-linecap": "round",
        "class": ["".concat(COMPONENT_NAME.value, "__circle-inner")],
        "transform": "matrix(0,-1,1,0,0,".concat(diameter.value, ")"),
        "stroke-dasharray": strokeDashArr.value,
        "style": circlePathStyle.value
      }, null)])])]);
    };
  }
});

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