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