import { ref as f, computed as p, readonly as w } from "vue";
function E(v = {
  linear: !1,
  activeStep: -1,
  activeSubstep: -1,
  steps: []
}) {
  const a = f(v.steps ? v.steps : []), o = p(() => a.value.length), e = f(
    v.activeStep !== null && v.activeStep !== void 0 ? v.activeStep : -1
  ), l = f(
    v.activeSubstep !== null && v.activeSubstep !== void 0 ? v.activeSubstep : -1
  ), S = p(() => {
    var u, t;
    return Array.from(((t = (u = v.ref) == null ? void 0 : u.value) == null ? void 0 : t.children) || []);
  }), m = p(() => S.value[e.value]);
  function s(u) {
    return !!a.value[u].substeps.length;
  }
  function b() {
    const u = e.value === -1, t = e.value === a.value.length - 1;
    if (u)
      e.value++, s(e.value) && l.value++;
    else if (t)
      if (s(e.value)) {
        const i = l.value === -1, c = l.value === a.value[e.value].substeps.length - 1;
        i ? l.value++ : c ? (a.value[e.value].substeps[l.value].completed = !0, l.value = -1, a.value[e.value].completed = !0, e.value = -1) : (a.value[e.value].substeps[l.value].completed = !0, l.value++);
      } else
        a.value[e.value].completed = !0, e.value = -1;
    else if (s(e.value)) {
      const i = l.value === -1, c = l.value === a.value[e.value].substeps.length - 1;
      i ? l.value++ : c ? (a.value[e.value].substeps[l.value].completed = !0, l.value = -1, a.value[e.value].completed = !0, e.value++, s(e.value) && l.value === -1 && l.value++) : (a.value[e.value].substeps[l.value].completed = !0, l.value++);
    } else
      a.value[e.value].completed = !0, e.value++, s(e.value) && l.value === -1 && l.value++;
  }
  function h() {
    e.value !== -1 && (s(e.value) ? l.value === 0 ? (e.value--, l.value--, e.value >= 0 && s(e.value) && (l.value = a.value[e.value].substeps.length - 1)) : l.value-- : (e.value--, e.value >= 0 && s(e.value) && (l.value = a.value[e.value].substeps.length - 1)));
  }
  function g(u, t = -1) {
    v.linear ? (r(u - 1) || u === 0) && (s(u) && (t <= 0 ? l.value = 0 : r(u, t - 1) && (l.value = t)), e.value = u) : (e.value = u, s(u) && (t < 0 ? l.value = 0 : l.value = t));
  }
  function r(u, t = -1) {
    var i, c, n;
    return t >= 0 ? (c = (i = a.value[u]) == null ? void 0 : i.substeps[t]) == null ? void 0 : c.completed : (n = a.value[u]) == null ? void 0 : n.completed;
  }
  function d(u, t = -1) {
    return t >= 0 ? e.value === u && l.value === t : e.value === u;
  }
  function A(u = !1) {
    if (u && !a.value.length)
      throw new Error("Cannot register a substep without a parent step.");
    u ? a.value[a.value.length - 1].substeps.push({ completed: !1 }) : a.value.push({ completed: !1, substeps: [] });
  }
  return {
    steps: w(a),
    stepCount: o,
    activeStepElement: m,
    activeStepIndex: e,
    activeSubstepIndex: l,
    registerStep: A,
    next: b,
    back: h,
    goTo: g,
    isStepActive: d,
    isStepCompleted: r
  };
}
export {
  E as default
};
//# sourceMappingURL=useStepper.js.map
