import { s as k, h as H, as as G, a5 as D, a as Q, b as y, E as V, F as j, aM as ee, H as re, d as Y, e as O, a0 as F, a2 as ne, aH as ae, f as X, aJ as fe, a3 as L, bV as ie, aL as le, bW as P, aF as B, aP as ue, g as J, m as se, bX as oe, bY as te, bZ as ve, b_ as m, aK as U, a4 as W, b$ as z, q as de, aB as ce, c0 as pe, c1 as _e, aE as he, ai as ge } from "./index-DRgrWhNH.js";
function Ae(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];
    W(
      E,
      () => {
        if (s) {
          if (s.pending.delete(E), s.done.add(E), s.pending.size === 0) {
            var o = (
              /** @type {Set<EachOutroGroup>} */
              e.outrogroups
            );
            q(B(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 K;
function Ce(e, i, l, d, g, s = null) {
  var u = e, p = /* @__PURE__ */ new Map(), f = (i & P) !== 0;
  if (f) {
    var t = (
      /** @type {Element} */
      e
    );
    u = H ? k(G(t)) : t.appendChild(D());
  }
  H && Q();
  var n = null, E = j(() => {
    var a = l();
    return ue(a) ? a : a == null ? [] : B(a);
  }), o, c = !0;
  function b() {
    r.fallback = n, me(r, o, u, i, d), n !== null && (o.length === 0 ? (n.f & m) === 0 ? U(n) : (n.f ^= m, R(n, null, u)) : W(n, () => {
      n = null;
    }));
  }
  var w = y(() => {
    o = /** @type {V[]} */
    V(E);
    var a = o.length;
    let I = !1;
    if (H) {
      var N = ee(u) === re;
      N !== (a === 0) && (u = Y(), k(u), O(!1), I = !0);
    }
    for (var h = /* @__PURE__ */ new Set(), A = (
      /** @type {Batch} */
      fe
    ), S = le(), _ = 0; _ < a; _ += 1) {
      H && F.nodeType === ne && /** @type {Comment} */
      F.data === ae && (u = /** @type {Comment} */
      F, I = !0, O(!1));
      var C = o[_], x = d(C, _), v = c ? null : p.get(x);
      v ? (v.v && X(v.v, C), v.i && X(v.i, _), S && A.unskip_effect(v.e)) : (v = Te(
        p,
        c ? u : K ??= D(),
        C,
        x,
        _,
        g,
        i,
        l
      ), c || (v.e.f |= m), p.set(x, v)), h.add(x);
    }
    if (a === 0 && s && !n && (c ? n = L(() => s(u)) : (n = L(() => s(K ??= D())), n.f |= m)), a > h.size && ie(), H && a > 0 && k(Y()), !c)
      if (S) {
        for (const [Z, $] of p)
          h.has(Z) || A.skip_effect($.e);
        A.oncommit(b), A.ondiscard(() => {
        });
      } else
        b();
    I && O(!0), V(E);
  }), r = { effect: w, items: p, outrogroups: null, fallback: n };
  c = !1, H && (u = F);
}
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 = [], b, w, r, a;
  if (s)
    for (a = 0; a < u; a += 1)
      b = i[a], w = g(b, a), r = /** @type {EachItem} */
      p.get(w).e, (r.f & m) === 0 && (r.nodes?.a?.measure(), (E ??= /* @__PURE__ */ new Set()).add(r));
  for (a = 0; a < u; a += 1) {
    if (b = i[a], w = g(b, a), r = /** @type {EachItem} */
    p.get(w).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)
        R(r, null, l);
      else {
        var I = 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, I), R(r, I, l), n = r, o = [], c = [], f = M(n.next);
        continue;
      }
    if ((r.f & z) !== 0 && (U(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 N = c[0], h;
          n = N.prev;
          var A = o[0], S = o[o.length - 1];
          for (h = 0; h < o.length; h += 1)
            R(o[h], N, l);
          for (h = 0; h < c.length; h += 1)
            t.delete(c[h]);
          T(e, A.prev, S.next), T(e, n, A), T(e, S, N), f = N, n = S, a -= 1, o = [], c = [];
        } else
          t.delete(r), R(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(B(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 C = _.length;
    if (C > 0) {
      var x = (d & P) !== 0 && u === 0 ? l : null;
      if (s) {
        for (a = 0; a < C; a += 1)
          _[a].nodes?.a?.measure();
        for (a = 0; a < C; a += 1)
          _[a].nodes?.a?.fix();
      }
      Ee(e, _, x);
    }
  }
  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) : J(l) : null, t = (u & oe) !== 0 ? J(g) : null;
  return {
    v: f,
    i: t,
    e: L(() => (s(i, f ?? l, t ?? g, p), () => {
      e.delete(d);
    }))
  };
}
function R(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 {
  Ce as e,
  Ae as i
};
//# sourceMappingURL=each-C_AuyVTL.js.map
