import { T as A } from "./lit-element.jLBm65_O.js";
import { e as M, i as b, t as j } from "./directive.oAbCiebi.js";
import { p as C, v as h, s as v, M as x, m as D } from "./directive-helpers.Dm4rc594.js";
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
const w = (s, c, a) => {
  const p = /* @__PURE__ */ new Map();
  for (let e = c; e <= a; e++) p.set(s[e], e);
  return p;
}, L = M(class extends b {
  constructor(s) {
    if (super(s), s.type !== j.CHILD) throw Error("repeat() can only be used in text expressions");
  }
  dt(s, c, a) {
    let p;
    a === void 0 ? a = c : c !== void 0 && (p = c);
    const e = [], i = [];
    let l = 0;
    for (const u of s) e[l] = p ? p(u, l) : l, i[l] = a(u, l), l++;
    return { values: i, keys: e };
  }
  render(s, c, a) {
    return this.dt(s, c, a).values;
  }
  update(s, [c, a, p]) {
    const e = C(s), { values: i, keys: l } = this.dt(c, a, p);
    if (!Array.isArray(e)) return this.ut = l, i;
    const u = this.ut ??= [], f = [];
    let m, g, t = 0, o = e.length - 1, r = 0, n = i.length - 1;
    for (; t <= o && r <= n; ) if (e[t] === null) t++;
    else if (e[o] === null) o--;
    else if (u[t] === l[r]) f[r] = h(e[t], i[r]), t++, r++;
    else if (u[o] === l[n]) f[n] = h(e[o], i[n]), o--, n--;
    else if (u[t] === l[n]) f[n] = h(e[t], i[n]), v(s, f[n + 1], e[t]), t++, n--;
    else if (u[o] === l[r]) f[r] = h(e[o], i[r]), v(s, e[t], e[o]), o--, r++;
    else if (m === void 0 && (m = w(l, r, n), g = w(u, t, o)), m.has(u[t])) if (m.has(u[o])) {
      const d = g.get(l[r]), y = d !== void 0 ? e[d] : null;
      if (y === null) {
        const k = v(s, e[t]);
        h(k, i[r]), f[r] = k;
      } else f[r] = h(y, i[r]), v(s, e[t], y), e[d] = null;
      r++;
    } else x(e[o]), o--;
    else x(e[t]), t++;
    for (; r <= n; ) {
      const d = v(s, f[n + 1]);
      h(d, i[r]), f[r++] = d;
    }
    for (; t <= o; ) {
      const d = e[t++];
      d !== null && x(d);
    }
    return this.ut = l, D(s, f), A;
  }
});
export {
  L as c
};
