import { s as D, h as R, ay as W, ab as O, a as Z, b as $, E as B, V as j, aS as ee, H as re, d as Y, e as F, a6 as k, a8 as ne, aN as ae, f as K, aP as fe, a9 as L, c0 as ie, aR as le, c1 as U, aL as q, aV as ue, g as P, m as se, c2 as oe, c3 as te, c4 as ve, c5 as m, aQ as X, aa as y, c6 as z, q as de, aH as ce, c7 as pe, c8 as _e, aK as he, ao as ge } from "./index-CoRcfuX4.js";
function Ce(e, i) {
  return i;
}
function Ee(e, i, l) {
  for (var d = [], g = i.length, s, u = i.length, p = 0; p < g; p++) {
    let E = i[p];
    y(
      E,
      () => {
        if (s) {
          if (s.pending.delete(E), s.done.add(E), s.pending.size === 0) {
            var o = (
              /** @type {Set<EachOutroGroup>} */
              e.outrogroups
            );
            V(q(s.done)), o.delete(s), o.size === 0 && (e.outrogroups = null);
          }
        } else
          u -= 1;
      },
      !1
    );
  }
  if (u === 0) {
    var f = d.length === 0 && l !== null;
    if (f) {
      var t = (
        /** @type {Element} */
        l
      ), n = (
        /** @type {Element} */
        t.parentNode
      );
      he(n), n.append(t), e.items.clear();
    }
    V(i, !f);
  } else
    s = {
      pending: new Set(i),
      done: /* @__PURE__ */ new Set()
    }, (e.outrogroups ??= /* @__PURE__ */ new Set()).add(s);
}
function V(e, i = !0) {
  for (var l = 0; l < e.length; l++)
    ge(e[l], i);
}
var Q;
function Ne(e, i, l, d, g, s = null) {
  var u = e, p = /* @__PURE__ */ new Map(), f = (i & U) !== 0;
  if (f) {
    var t = (
      /** @type {Element} */
      e
    );
    u = R ? D(W(t)) : t.appendChild(O());
  }
  R && Z();
  var n = null, E = j(() => {
    var a = l();
    return ue(a) ? a : a == null ? [] : q(a);
  }), o, c = !0;
  function A() {
    r.fallback = n, me(r, o, u, i, d), n !== null && (o.length === 0 ? (n.f & m) === 0 ? X(n) : (n.f ^= m, M(n, null, u)) : y(n, () => {
      n = null;
    }));
  }
  var S = $(() => {
    o = /** @type {V[]} */
    B(E);
    var a = o.length;
    let w = !1;
    if (R) {
      var I = ee(u) === re;
      I !== (a === 0) && (u = Y(), D(u), F(!1), w = !0);
    }
    for (var h = /* @__PURE__ */ new Set(), C = (
      /** @type {Batch} */
      fe
    ), x = le(), _ = 0; _ < a; _ += 1) {
      R && k.nodeType === ne && /** @type {Comment} */
      k.data === ae && (u = /** @type {Comment} */
      k, w = !0, F(!1));
      var N = o[_], H = d(N, _), v = c ? null : p.get(H);
      v ? (v.v && K(v.v, N), v.i && K(v.i, _), x && C.unskip_effect(v.e)) : (v = Te(
        p,
        c ? u : Q ??= O(),
        N,
        H,
        _,
        g,
        i,
        l
      ), c || (v.e.f |= m), p.set(H, v)), h.add(H);
    }
    if (a === 0 && s && !n && (c ? n = L(() => s(u)) : (n = L(() => s(Q ??= O())), n.f |= m)), a > h.size && ie(), R && a > 0 && D(Y()), !c)
      if (x) {
        for (const [G, J] of p)
          h.has(G) || C.skip_effect(J.e);
        C.oncommit(A), C.ondiscard(() => {
        });
      } else
        A();
    w && F(!0), B(E);
  }), r = { effect: S, items: p, outrogroups: null, fallback: n };
  c = !1, R && (u = k);
}
function b(e) {
  for (; e !== null && (e.f & pe) === 0; )
    e = e.next;
  return e;
}
function me(e, i, l, d, g) {
  var s = (d & _e) !== 0, u = i.length, p = e.items, f = b(e.effect.first), t, n = null, E, o = [], c = [], A, S, r, a;
  if (s)
    for (a = 0; a < u; a += 1)
      A = i[a], S = g(A, a), r = /** @type {EachItem} */
      p.get(S).e, (r.f & m) === 0 && (r.nodes?.a?.measure(), (E ??= /* @__PURE__ */ new Set()).add(r));
  for (a = 0; a < u; a += 1) {
    if (A = i[a], S = g(A, a), r = /** @type {EachItem} */
    p.get(S).e, e.outrogroups !== null)
      for (const v of e.outrogroups)
        v.pending.delete(r), v.done.delete(r);
    if ((r.f & m) !== 0)
      if (r.f ^= m, r === f)
        M(r, null, l);
      else {
        var w = n ? n.next : f;
        r === e.effect.last && (e.effect.last = r.prev), r.prev && (r.prev.next = r.next), r.next && (r.next.prev = r.prev), T(e, n, r), T(e, r, w), M(r, w, l), n = r, o = [], c = [], f = b(n.next);
        continue;
      }
    if ((r.f & z) !== 0 && (X(r), s && (r.nodes?.a?.unfix(), (E ??= /* @__PURE__ */ new Set()).delete(r))), r !== f) {
      if (t !== void 0 && t.has(r)) {
        if (o.length < c.length) {
          var I = c[0], h;
          n = I.prev;
          var C = o[0], x = o[o.length - 1];
          for (h = 0; h < o.length; h += 1)
            M(o[h], I, l);
          for (h = 0; h < c.length; h += 1)
            t.delete(c[h]);
          T(e, C.prev, x.next), T(e, n, C), T(e, x, I), f = I, n = x, a -= 1, o = [], c = [];
        } else
          t.delete(r), M(r, f, l), T(e, r.prev, r.next), T(e, r, n === null ? e.effect.first : n.next), T(e, n, r), n = r;
        continue;
      }
      for (o = [], c = []; f !== null && f !== r; )
        (t ??= /* @__PURE__ */ new Set()).add(f), c.push(f), f = b(f.next);
      if (f === null)
        continue;
    }
    (r.f & m) === 0 && o.push(r), n = r, f = b(r.next);
  }
  if (e.outrogroups !== null) {
    for (const v of e.outrogroups)
      v.pending.size === 0 && (V(q(v.done)), e.outrogroups?.delete(v));
    e.outrogroups.size === 0 && (e.outrogroups = null);
  }
  if (f !== null || t !== void 0) {
    var _ = [];
    if (t !== void 0)
      for (r of t)
        (r.f & z) === 0 && _.push(r);
    for (; f !== null; )
      (f.f & z) === 0 && f !== e.fallback && _.push(f), f = b(f.next);
    var N = _.length;
    if (N > 0) {
      var H = (d & U) !== 0 && u === 0 ? l : null;
      if (s) {
        for (a = 0; a < N; a += 1)
          _[a].nodes?.a?.measure();
        for (a = 0; a < N; a += 1)
          _[a].nodes?.a?.fix();
      }
      Ee(e, _, H);
    }
  }
  s && de(() => {
    if (E !== void 0)
      for (r of E)
        r.nodes?.a?.apply();
  });
}
function Te(e, i, l, d, g, s, u, p) {
  var f = (u & te) !== 0 ? (u & ve) === 0 ? se(l, !1, !1) : P(l) : null, t = (u & oe) !== 0 ? P(g) : null;
  return {
    v: f,
    i: t,
    e: L(() => (s(i, f ?? l, t ?? g, p), () => {
      e.delete(d);
    }))
  };
}
function M(e, i, l) {
  if (e.nodes)
    for (var d = e.nodes.start, g = e.nodes.end, s = i && (i.f & m) === 0 ? (
      /** @type {EffectNodes} */
      i.nodes.start
    ) : l; d !== null; ) {
      var u = (
        /** @type {TemplateNode} */
        ce(d)
      );
      if (s.before(d), d === g)
        return;
      d = u;
    }
}
function T(e, i, l) {
  i === null ? e.effect.first = l : i.next = l, l === null ? e.effect.last = i : l.prev = i;
}
export {
  Ne as e,
  Ce as i
};
//# sourceMappingURL=each-BbpL54E9.js.map
