"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const shared_esmBundler = require("../../../../../@vue/shared/dist/shared.esm-bundler.js");
const index = require("../../../hooks/use-namespace/index.js");
const index$2 = require("../../icon/index.js");
const progress = require("./progress.js");
const index$1 = require("../../../../../@element-plus/icons-vue/dist/index.js");
const Vue = require("vue");
const _hoisted_1 = ["aria-valuenow"];
const _hoisted_2 = { viewBox: "0 0 100 100" };
const _hoisted_3 = [
  "d",
  "stroke",
  "stroke-linecap",
  "stroke-width"
];
const _hoisted_4 = [
  "d",
  "stroke",
  "opacity",
  "stroke-linecap",
  "stroke-width"
];
const _hoisted_5 = { key: 0 };
var progress_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ Vue.defineComponent({
  name: "ElProgress",
  __name: "progress",
  props: progress.progressProps,
  setup(__props) {
    const STATUS_COLOR_MAP = {
      success: "#13ce66",
      exception: "#ff4949",
      warning: "#e6a23c",
      default: "#20a0ff"
    };
    const props = __props;
    const ns = index.useNamespace("progress");
    const barStyle = Vue.computed(() => {
      const barStyle2 = {
        width: `${props.percentage}%`,
        animationDuration: `${props.duration}s`
      };
      const color = getCurrentColor(props.percentage);
      if (color.includes("gradient")) barStyle2.background = color;
      else barStyle2.backgroundColor = color;
      return barStyle2;
    });
    const relativeStrokeWidth = Vue.computed(() => (props.strokeWidth / props.width * 100).toFixed(1));
    const radius = Vue.computed(() => {
      if (["circle", "dashboard"].includes(props.type)) return Number.parseInt(`${50 - Number.parseFloat(relativeStrokeWidth.value) / 2}`, 10);
      return 0;
    });
    const trackPath = Vue.computed(() => {
      const r = radius.value;
      const isDashboard = props.type === "dashboard";
      return `
          M 50 50
          m 0 ${isDashboard ? "" : "-"}${r}
          a ${r} ${r} 0 1 1 0 ${isDashboard ? "-" : ""}${r * 2}
          a ${r} ${r} 0 1 1 0 ${isDashboard ? "" : "-"}${r * 2}
          `;
    });
    const perimeter = Vue.computed(() => 2 * Math.PI * radius.value);
    const rate = Vue.computed(() => props.type === "dashboard" ? 0.75 : 1);
    const strokeDashoffset = Vue.computed(() => {
      return `${-1 * perimeter.value * (1 - rate.value) / 2}px`;
    });
    const trailPathStyle = Vue.computed(() => ({
      strokeDasharray: `${perimeter.value * rate.value}px, ${perimeter.value}px`,
      strokeDashoffset: strokeDashoffset.value
    }));
    const circlePathStyle = Vue.computed(() => ({
      strokeDasharray: `${perimeter.value * rate.value * (props.percentage / 100)}px, ${perimeter.value}px`,
      strokeDashoffset: strokeDashoffset.value,
      transition: "stroke-dasharray 0.6s ease 0s, stroke 0.6s ease, opacity ease 0.6s"
    }));
    const stroke = Vue.computed(() => {
      let ret;
      if (props.color) ret = getCurrentColor(props.percentage);
      else ret = STATUS_COLOR_MAP[props.status] || STATUS_COLOR_MAP.default;
      return ret;
    });
    const statusIcon = Vue.computed(() => {
      if (props.status === "warning") return index$1.WarningFilled;
      if (props.type === "line") return props.status === "success" ? index$1.CircleCheck : index$1.CircleClose;
      else return props.status === "success" ? index$1.Check : index$1.Close;
    });
    const progressTextSize = Vue.computed(() => {
      return props.type === "line" ? 12 + props.strokeWidth * 0.4 : props.width * 0.111111 + 2;
    });
    const content = Vue.computed(() => props.format(props.percentage));
    function getColors(color) {
      const span = 100 / color.length;
      return color.map((seriesColor, index2) => {
        if (shared_esmBundler.isString(seriesColor)) return {
          color: seriesColor,
          percentage: (index2 + 1) * span
        };
        return seriesColor;
      }).sort((a, b) => a.percentage - b.percentage);
    }
    const getCurrentColor = (percentage) => {
      var _a;
      const { color } = props;
      if (shared_esmBundler.isFunction(color)) return color(percentage);
      else if (shared_esmBundler.isString(color)) return color;
      else {
        const colors = getColors(color);
        for (const color2 of colors) if (color2.percentage > percentage) return color2.color;
        return (_a = colors[colors.length - 1]) == null ? void 0 : _a.color;
      }
    };
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createElementBlock("div", {
        class: Vue.normalizeClass([
          Vue.unref(ns).b(),
          Vue.unref(ns).m(__props.type),
          Vue.unref(ns).is(__props.status),
          {
            [Vue.unref(ns).m("without-text")]: !__props.showText,
            [Vue.unref(ns).m("text-inside")]: __props.textInside
          }
        ]),
        role: "progressbar",
        "aria-valuenow": __props.percentage,
        "aria-valuemin": "0",
        "aria-valuemax": "100"
      }, [__props.type === "line" ? (Vue.openBlock(), Vue.createElementBlock("div", {
        key: 0,
        class: Vue.normalizeClass(Vue.unref(ns).b("bar"))
      }, [Vue.createElementVNode("div", {
        class: Vue.normalizeClass(Vue.unref(ns).be("bar", "outer")),
        style: Vue.normalizeStyle({ height: `${__props.strokeWidth}px` })
      }, [Vue.createElementVNode("div", {
        class: Vue.normalizeClass([
          Vue.unref(ns).be("bar", "inner"),
          { [Vue.unref(ns).bem("bar", "inner", "indeterminate")]: __props.indeterminate },
          { [Vue.unref(ns).bem("bar", "inner", "striped")]: __props.striped },
          { [Vue.unref(ns).bem("bar", "inner", "striped-flow")]: __props.stripedFlow }
        ]),
        style: Vue.normalizeStyle(barStyle.value)
      }, [(__props.showText || _ctx.$slots.default) && __props.textInside ? (Vue.openBlock(), Vue.createElementBlock("div", {
        key: 0,
        class: Vue.normalizeClass(Vue.unref(ns).be("bar", "innerText"))
      }, [Vue.renderSlot(_ctx.$slots, "default", { percentage: __props.percentage }, () => [Vue.createElementVNode("span", null, Vue.toDisplayString(content.value), 1)])], 2)) : Vue.createCommentVNode("v-if", true)], 6)], 6)], 2)) : (Vue.openBlock(), Vue.createElementBlock("div", {
        key: 1,
        class: Vue.normalizeClass(Vue.unref(ns).b("circle")),
        style: Vue.normalizeStyle({
          height: `${__props.width}px`,
          width: `${__props.width}px`
        })
      }, [(Vue.openBlock(), Vue.createElementBlock("svg", _hoisted_2, [Vue.createElementVNode("path", {
        class: Vue.normalizeClass(Vue.unref(ns).be("circle", "track")),
        d: trackPath.value,
        stroke: `var(${Vue.unref(ns).cssVarName("fill-color-light")}, #e5e9f2)`,
        "stroke-linecap": __props.strokeLinecap,
        "stroke-width": relativeStrokeWidth.value,
        fill: "none",
        style: Vue.normalizeStyle(trailPathStyle.value)
      }, null, 14, _hoisted_3), Vue.createElementVNode("path", {
        class: Vue.normalizeClass(Vue.unref(ns).be("circle", "path")),
        d: trackPath.value,
        stroke: stroke.value,
        fill: "none",
        opacity: __props.percentage ? 1 : 0,
        "stroke-linecap": __props.strokeLinecap,
        "stroke-width": relativeStrokeWidth.value,
        style: Vue.normalizeStyle(circlePathStyle.value)
      }, null, 14, _hoisted_4)]))], 6)), (__props.showText || _ctx.$slots.default) && !__props.textInside ? (Vue.openBlock(), Vue.createElementBlock("div", {
        key: 2,
        class: Vue.normalizeClass(Vue.unref(ns).e("text")),
        style: Vue.normalizeStyle({ fontSize: `${progressTextSize.value}px` })
      }, [Vue.renderSlot(_ctx.$slots, "default", { percentage: __props.percentage }, () => [!__props.status ? (Vue.openBlock(), Vue.createElementBlock("span", _hoisted_5, Vue.toDisplayString(content.value), 1)) : (Vue.openBlock(), Vue.createBlock(Vue.unref(index$2.ElIcon), { key: 1 }, {
        default: Vue.withCtx(() => [(Vue.openBlock(), Vue.createBlock(Vue.resolveDynamicComponent(statusIcon.value)))]),
        _: 1
      }))])], 6)) : Vue.createCommentVNode("v-if", true)], 10, _hoisted_1);
    };
  }
});
exports.default = progress_vue_vue_type_script_setup_true_lang_default;
