"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const types = require("../../../utils/types.js");
const index = require("../../../hooks/use-namespace/index.js");
const index$1 = require("../../icon/index.js");
const tokens = require("./tokens.js");
const item = require("./item.js");
const index$2 = require("../../../../../@element-plus/icons-vue/dist/index.js");
const vue = require("vue");
var item_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ vue.defineComponent({
  name: "ElStep",
  __name: "item",
  props: item.stepProps,
  setup(__props) {
    const props = __props;
    const ns = index.useNamespace("step");
    const index$3 = vue.ref(-1);
    const lineStyle = vue.ref({});
    const internalStatus = vue.ref("");
    const parent = vue.inject(tokens.STEPS_INJECTION_KEY);
    const currentInstance = vue.getCurrentInstance();
    let stepDiff = 0;
    let beforeActive = 0;
    vue.onMounted(() => {
      vue.watch([
        () => parent.props.active,
        () => parent.props.processStatus,
        () => parent.props.finishStatus
      ], ([active], [oldActive]) => {
        beforeActive = oldActive || 0;
        stepDiff = active - beforeActive;
        updateStatus(active);
      }, { immediate: true });
    });
    const currentStatus = vue.computed(() => {
      return props.status || internalStatus.value;
    });
    const prevInternalStatus = vue.computed(() => {
      const prevStep = parent.steps.value[index$3.value - 1];
      return prevStep ? prevStep.internalStatus.value : "wait";
    });
    const isCenter = vue.computed(() => {
      return parent.props.alignCenter;
    });
    const isVertical = vue.computed(() => {
      return parent.props.direction === "vertical";
    });
    const isSimple = vue.computed(() => {
      return parent.props.simple;
    });
    const stepsCount = vue.computed(() => {
      return parent.steps.value.length;
    });
    const isLast = vue.computed(() => {
      var _a;
      return ((_a = parent.steps.value[stepsCount.value - 1]) == null ? void 0 : _a.uid) === currentInstance.uid;
    });
    const space = vue.computed(() => {
      return isSimple.value ? "" : parent.props.space;
    });
    const containerKls = vue.computed(() => {
      return [
        ns.b(),
        ns.is(isSimple.value ? "simple" : parent.props.direction),
        ns.is("flex", isLast.value && !space.value && !isCenter.value),
        ns.is("center", isCenter.value && !isVertical.value && !isSimple.value)
      ];
    });
    const style = vue.computed(() => {
      const style2 = { flexBasis: types.isNumber(space.value) ? `${space.value}px` : space.value ? space.value : `${100 / (stepsCount.value - (isCenter.value ? 0 : 1))}%` };
      if (isVertical.value) return style2;
      if (isLast.value) style2.maxWidth = `${100 / stepsCount.value}%`;
      return style2;
    });
    const setIndex = (val) => {
      index$3.value = val;
    };
    const calcProgress = (status) => {
      const isWait = status === "wait";
      const style2 = { transitionDelay: `${Math.abs(stepDiff) === 1 ? 0 : stepDiff > 0 ? (index$3.value + 1 - beforeActive) * 150 : -(index$3.value + 1 - parent.props.active) * 150}ms` };
      const step = status === parent.props.processStatus || isWait ? 0 : 100;
      style2.borderWidth = step && !isSimple.value ? "1px" : 0;
      style2[parent.props.direction === "vertical" ? "height" : "width"] = `${step}%`;
      lineStyle.value = style2;
    };
    const updateStatus = (activeIndex) => {
      if (activeIndex > index$3.value) internalStatus.value = parent.props.finishStatus;
      else if (activeIndex === index$3.value && prevInternalStatus.value !== "error") internalStatus.value = parent.props.processStatus;
      else internalStatus.value = "wait";
      const prevChild = parent.steps.value[index$3.value - 1];
      if (prevChild) prevChild.calcProgress(internalStatus.value);
    };
    const stepItemState = {
      uid: currentInstance.uid,
      getVnode: () => currentInstance.vnode,
      currentStatus,
      internalStatus,
      setIndex,
      calcProgress
    };
    parent.addStep(stepItemState);
    vue.onBeforeUnmount(() => {
      parent.removeStep(stepItemState);
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock("div", {
        style: vue.normalizeStyle(style.value),
        class: vue.normalizeClass(containerKls.value)
      }, [
        vue.createCommentVNode(" icon & line "),
        vue.createElementVNode("div", { class: vue.normalizeClass([vue.unref(ns).e("head"), vue.unref(ns).is(currentStatus.value)]) }, [!isSimple.value ? (vue.openBlock(), vue.createElementBlock("div", {
          key: 0,
          class: vue.normalizeClass(vue.unref(ns).e("line"))
        }, [vue.createElementVNode("i", {
          class: vue.normalizeClass(vue.unref(ns).e("line-inner")),
          style: vue.normalizeStyle(lineStyle.value)
        }, null, 6)], 2)) : vue.createCommentVNode("v-if", true), vue.createElementVNode("div", { class: vue.normalizeClass([vue.unref(ns).e("icon"), vue.unref(ns).is(__props.icon || _ctx.$slots.icon ? "icon" : "text")]) }, [vue.renderSlot(_ctx.$slots, "icon", {}, () => [__props.icon ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), {
          key: 0,
          class: vue.normalizeClass(vue.unref(ns).e("icon-inner"))
        }, {
          default: vue.withCtx(() => [(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.icon)))]),
          _: 1
        }, 8, ["class"])) : currentStatus.value === "success" ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), {
          key: 1,
          class: vue.normalizeClass([vue.unref(ns).e("icon-inner"), vue.unref(ns).is("status")])
        }, {
          default: vue.withCtx(() => [vue.createVNode(vue.unref(index$2.Check))]),
          _: 1
        }, 8, ["class"])) : currentStatus.value === "error" ? (vue.openBlock(), vue.createBlock(vue.unref(index$1.ElIcon), {
          key: 2,
          class: vue.normalizeClass([vue.unref(ns).e("icon-inner"), vue.unref(ns).is("status")])
        }, {
          default: vue.withCtx(() => [vue.createVNode(vue.unref(index$2.Close))]),
          _: 1
        }, 8, ["class"])) : !isSimple.value ? (vue.openBlock(), vue.createElementBlock("div", {
          key: 3,
          class: vue.normalizeClass(vue.unref(ns).e("icon-inner"))
        }, vue.toDisplayString(index$3.value + 1), 3)) : vue.createCommentVNode("v-if", true)])], 2)], 2),
        vue.createCommentVNode(" title & description "),
        vue.createElementVNode("div", { class: vue.normalizeClass(vue.unref(ns).e("main")) }, [vue.createElementVNode("div", { class: vue.normalizeClass([vue.unref(ns).e("title"), vue.unref(ns).is(currentStatus.value)]) }, [vue.renderSlot(_ctx.$slots, "title", {}, () => [vue.createTextVNode(vue.toDisplayString(__props.title), 1)])], 2), isSimple.value ? (vue.openBlock(), vue.createElementBlock("div", {
          key: 0,
          class: vue.normalizeClass(vue.unref(ns).e("arrow"))
        }, null, 2)) : (vue.openBlock(), vue.createElementBlock("div", {
          key: 1,
          class: vue.normalizeClass([vue.unref(ns).e("description"), vue.unref(ns).is(currentStatus.value)])
        }, [vue.renderSlot(_ctx.$slots, "description", {}, () => [vue.createTextVNode(vue.toDisplayString(__props.description), 1)])], 2))], 2)
      ], 6);
    };
  }
});
exports.default = item_vue_vue_type_script_setup_true_lang_default;
