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