/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { CloseCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, CloseIcon, CheckIcon, ErrorIcon } from '@ldesign/icons-vue';
import { getBackgroundColor } from '../../utils/helper.js';
import { renderLNodeJSX } from '../../utils/render-node.js';
import { getClassPrefixMixins, getGlobalIconMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import props from './props.js';
import { PRO_THEME, STATUS_ICON, CIRCLE_SIZE_PX, CIRCLE_SIZE, CIRCLE_FONT_SIZE_RATIO } from './const.js';
import 'lodash/camelCase';
import 'vue';
import 'lodash';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';

const classPrefixMixins = getClassPrefixMixins("progress");
var _Progress = mixins(classPrefixMixins, getGlobalIconMixins()).extend({
  name: "LProgress",
  props: {
    ...props
  },
  computed: {
    statusStyle() {
      if (this.percentage >= 100) return "success";
      return this.status;
    },
    themeClass() {
      const Line = PRO_THEME.LINE;
      if (this.theme === Line) return "thin";
      return this.theme;
    },
    trackBgStyle() {
      const {
        strokeWidth
      } = this;
      let height = typeof strokeWidth === "string" ? strokeWidth : `${strokeWidth}px`;
      const Plump = PRO_THEME.PLUMP;
      if (this.theme === Plump) height = "";
      return {
        height,
        backgroundColor: this.trackColor,
        borderRadius: height
      };
    },
    circleStrokeStyle() {
      return {
        stroke: this.trackColor
      };
    },
    barStyle() {
      return {
        width: `${this.percentage}%`,
        background: this.color && getBackgroundColor(this.color)
      };
    },
    circlePathStyle() {
      const strokeColor = typeof this.color === "object" ? "" : this.color;
      return {
        stroke: strokeColor
      };
    },
    isShowIcon() {
      return STATUS_ICON.includes(this.status) && typeof this.label === "boolean";
    },
    diameter() {
      let diameter = CIRCLE_SIZE_PX.MEDIUM;
      if (!this.size) return diameter;
      const {
        SMALL,
        LARGE,
        MEDIUM
      } = CIRCLE_SIZE;
      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() {
      return this.diameter / 2;
    },
    radius() {
      return this.rPoints - this.circleStrokeWidth / 2;
    },
    circleStyle() {
      if (this.theme !== PRO_THEME.CIRCLE) return {};
      let 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: `${this.diameter}px`,
        height: `${this.diameter}px`,
        fontSize: `${fontSize}px`
      };
    },
    circleStrokeWidth() {
      const defaultWidth = this.size === CIRCLE_SIZE.SMALL ? 4 : 6;
      return this.strokeWidth ? Number(this.strokeWidth) : defaultWidth;
    },
    strokeDashArr() {
      const radius = (this.diameter - this.circleStrokeWidth) / 2;
      const perimeter = Math.PI * 2 * radius;
      const percent = this.percentage / 100;
      return `${perimeter * percent}  ${perimeter * (1 - percent)}`;
    },
    plumpStyles() {
      return {};
    }
  },
  methods: {
    getIconMap() {
      const {
        CloseCircleFilledIcon: CloseCircleFilledIcon$1,
        CheckCircleFilledIcon: CheckCircleFilledIcon$1,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon$1,
        CloseIcon: CloseIcon$1,
        CheckIcon: CheckIcon$1,
        ErrorIcon: ErrorIcon$1
      } = this.useGlobalIcon({
        CloseCircleFilledIcon: CloseCircleFilledIcon,
        CheckCircleFilledIcon: CheckCircleFilledIcon,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon,
        CloseIcon: CloseIcon,
        CheckIcon: CheckIcon,
        ErrorIcon: ErrorIcon
      });
      const CIRCLE_ICONS = {
        success: CheckIcon$1,
        warning: ErrorIcon$1,
        error: CloseIcon$1
      };
      const NORMAL_ICONS = {
        success: CheckCircleFilledIcon$1,
        warning: ErrorCircleFilledIcon$1,
        error: CloseCircleFilledIcon$1
      };
      return this.theme === PRO_THEME.CIRCLE ? CIRCLE_ICONS : NORMAL_ICONS;
    },
    getLabelContent() {
      const h = this.$createElement;
      let labelContent = `${this.percentage}%`;
      const status = this.status || "";
      if (STATUS_ICON.includes(status) && this.theme !== PRO_THEME.PLUMP) {
        const components = this.getIconMap();
        const component = components[status];
        if (component) labelContent = h(component, {
          "class": [`${this.componentName}__icon`]
        });
      }
      return labelContent;
    }
  },
  render() {
    const h = arguments[0];
    const labelContent = h("div", {
      "class": `${this.componentName}__info`
    }, [renderLNodeJSX(this, "label", this.getLabelContent())]);
    const PLUMP_SEPARATE = 10;
    const separateClasses = this.percentage > PLUMP_SEPARATE ? `${this.componentName}--over-ten` : `${this.componentName}--under-ten`;
    return h("div", {
      "class": this.componentName
    }, [this.theme === PRO_THEME.LINE && h("div", {
      "class": `${this.componentName}--thin ${this.componentName}--status--${this.statusStyle}`
    }, [h("div", {
      "class": `${this.componentName}__bar`,
      "style": this.trackBgStyle
    }, [h("div", {
      "class": `${this.componentName}__inner`,
      "style": this.barStyle
    })]), labelContent]), this.theme === PRO_THEME.PLUMP && h("div", {
      "class": [`${this.componentName}__bar ${this.componentName}--plump ${separateClasses}`, {
        [`${this.componentName}--status--${this.statusStyle}`]: this.statusStyle
      }],
      "style": this.trackBgStyle
    }, [h("div", {
      "class": `${this.componentName}__inner`,
      "style": this.barStyle
    }, [this.percentage > PLUMP_SEPARATE && labelContent]), this.percentage <= PLUMP_SEPARATE && labelContent]), this.theme === PRO_THEME.CIRCLE && h("div", {
      "class": `${this.componentName}--circle ${this.componentName}--status--${this.statusStyle}`,
      "style": this.circleStyle
    }, [labelContent, h("svg", {
      "attrs": {
        "width": this.diameter,
        "height": this.diameter,
        "viewBox": `0 0 ${this.diameter} ${this.diameter}`
      }
    }, [h("circle", {
      "attrs": {
        "cx": this.rPoints,
        "cy": this.rPoints,
        "r": this.radius,
        "stroke-width": this.circleStrokeWidth,
        "stroke": this.trackColor,
        "fill": "none"
      },
      "class": `${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,${this.diameter})`,
        "stroke-dasharray": this.strokeDashArr
      },
      "class": `${this.componentName}__circle-inner`,
      "style": this.circlePathStyle
    })])])]);
  }
});

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