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

'use strict';

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

var iconsVue = require('@ldesign/icons-vue');
var utils_helper = require('../../utils/helper.js');
var utils_renderNode = require('../../utils/render-node.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
var components_progress_props = require('./props.js');
var components_progress_const = require('./const.js');
require('lodash/camelCase');
require('vue');
require('lodash');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

const classPrefixMixins = components_configProvider_configReceiver.getClassPrefixMixins("progress");
var _Progress = utils_mixins["default"](classPrefixMixins, components_configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "LProgress",
  props: {
    ...components_progress_props["default"]
  },
  computed: {
    statusStyle() {
      if (this.percentage >= 100) return "success";
      return this.status;
    },
    themeClass() {
      const Line = components_progress_const.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 = components_progress_const.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 && utils_helper.getBackgroundColor(this.color)
      };
    },
    circlePathStyle() {
      const strokeColor = typeof this.color === "object" ? "" : this.color;
      return {
        stroke: strokeColor
      };
    },
    isShowIcon() {
      return components_progress_const.STATUS_ICON.includes(this.status) && typeof this.label === "boolean";
    },
    diameter() {
      let diameter = components_progress_const.CIRCLE_SIZE_PX.MEDIUM;
      if (!this.size) return diameter;
      const {
        SMALL,
        LARGE,
        MEDIUM
      } = components_progress_const.CIRCLE_SIZE;
      switch (this.size) {
        case SMALL:
          diameter = components_progress_const.CIRCLE_SIZE_PX.SMALL;
          break;
        case MEDIUM:
          diameter = components_progress_const.CIRCLE_SIZE_PX.MEDIUM;
          break;
        case LARGE:
          diameter = components_progress_const.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 !== components_progress_const.PRO_THEME.CIRCLE) return {};
      let fontSize = this.diameter * components_progress_const.CIRCLE_FONT_SIZE_RATIO.MEDIUM;
      if (this.diameter <= components_progress_const.CIRCLE_SIZE_PX.SMALL) fontSize = this.diameter * components_progress_const.CIRCLE_FONT_SIZE_RATIO.SMALL;else if (this.diameter >= components_progress_const.CIRCLE_SIZE_PX.LARGE) fontSize = this.diameter * components_progress_const.CIRCLE_FONT_SIZE_RATIO.LARGE;
      return {
        width: `${this.diameter}px`,
        height: `${this.diameter}px`,
        fontSize: `${fontSize}px`
      };
    },
    circleStrokeWidth() {
      const defaultWidth = this.size === components_progress_const.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,
        CheckCircleFilledIcon,
        ErrorCircleFilledIcon,
        CloseIcon,
        CheckIcon,
        ErrorIcon
      } = this.useGlobalIcon({
        CloseCircleFilledIcon: iconsVue.CloseCircleFilledIcon,
        CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon,
        ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon,
        CloseIcon: iconsVue.CloseIcon,
        CheckIcon: iconsVue.CheckIcon,
        ErrorIcon: iconsVue.ErrorIcon
      });
      const CIRCLE_ICONS = {
        success: CheckIcon,
        warning: ErrorIcon,
        error: CloseIcon
      };
      const NORMAL_ICONS = {
        success: CheckCircleFilledIcon,
        warning: ErrorCircleFilledIcon,
        error: CloseCircleFilledIcon
      };
      return this.theme === components_progress_const.PRO_THEME.CIRCLE ? CIRCLE_ICONS : NORMAL_ICONS;
    },
    getLabelContent() {
      const h = this.$createElement;
      let labelContent = `${this.percentage}%`;
      const status = this.status || "";
      if (components_progress_const.STATUS_ICON.includes(status) && this.theme !== components_progress_const.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`
    }, [utils_renderNode.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 === components_progress_const.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 === components_progress_const.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 === components_progress_const.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
    })])])]);
  }
});

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