const z = globalThis, F = z.ShadowRoot && (z.ShadyCSS === void 0 || z.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, G = /* @__PURE__ */ Symbol(), Y = /* @__PURE__ */ new WeakMap();
let pt = class {
  constructor(t, e, s) {
    if (this._$cssResult$ = !0, s !== G) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
    this.cssText = t, this.t = e;
  }
  get styleSheet() {
    let t = this.o;
    const e = this.t;
    if (F && t === void 0) {
      const s = e !== void 0 && e.length === 1;
      s && (t = Y.get(e)), t === void 0 && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), s && Y.set(e, t));
    }
    return t;
  }
  toString() {
    return this.cssText;
  }
};
const mt = (r) => new pt(typeof r == "string" ? r : r + "", void 0, G), gt = (r, ...t) => {
  const e = r.length === 1 ? r[0] : t.reduce(((s, i, n) => s + ((o) => {
    if (o._$cssResult$ === !0) return o.cssText;
    if (typeof o == "number") return o;
    throw Error("Value passed to 'css' function must be a 'css' function result: " + o + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.");
  })(i) + r[n + 1]), r[0]);
  return new pt(e, r, G);
}, _t = (r, t) => {
  if (F) r.adoptedStyleSheets = t.map(((e) => e instanceof CSSStyleSheet ? e : e.styleSheet));
  else for (const e of t) {
    const s = document.createElement("style"), i = z.litNonce;
    i !== void 0 && s.setAttribute("nonce", i), s.textContent = e.cssText, r.appendChild(s);
  }
}, tt = F ? (r) => r : (r) => r instanceof CSSStyleSheet ? ((t) => {
  let e = "";
  for (const s of t.cssRules) e += s.cssText;
  return mt(e);
})(r) : r;
const { is: yt, defineProperty: At, getOwnPropertyDescriptor: vt, getOwnPropertyNames: bt, getOwnPropertySymbols: wt, getPrototypeOf: xt } = Object, k = globalThis, et = k.trustedTypes, St = et ? et.emptyScript : "", Et = k.reactiveElementPolyfillSupport, T = (r, t) => r, j = { toAttribute(r, t) {
  switch (t) {
    case Boolean:
      r = r ? St : null;
      break;
    case Object:
    case Array:
      r = r == null ? r : JSON.stringify(r);
  }
  return r;
}, fromAttribute(r, t) {
  let e = r;
  switch (t) {
    case Boolean:
      e = r !== null;
      break;
    case Number:
      e = r === null ? null : Number(r);
      break;
    case Object:
    case Array:
      try {
        e = JSON.parse(r);
      } catch {
        e = null;
      }
  }
  return e;
} }, Z = (r, t) => !yt(r, t), it = { attribute: !0, type: String, converter: j, reflect: !1, useDefault: !1, hasChanged: Z };
Symbol.metadata ??= /* @__PURE__ */ Symbol("metadata"), k.litPropertyMetadata ??= /* @__PURE__ */ new WeakMap();
let S = class extends HTMLElement {
  static addInitializer(t) {
    this._$Ei(), (this.l ??= []).push(t);
  }
  static get observedAttributes() {
    return this.finalize(), this._$Eh && [...this._$Eh.keys()];
  }
  static createProperty(t, e = it) {
    if (e.state && (e.attribute = !1), this._$Ei(), this.prototype.hasOwnProperty(t) && ((e = Object.create(e)).wrapped = !0), this.elementProperties.set(t, e), !e.noAccessor) {
      const s = /* @__PURE__ */ Symbol(), i = this.getPropertyDescriptor(t, s, e);
      i !== void 0 && At(this.prototype, t, i);
    }
  }
  static getPropertyDescriptor(t, e, s) {
    const { get: i, set: n } = vt(this.prototype, t) ?? { get() {
      return this[e];
    }, set(o) {
      this[e] = o;
    } };
    return { get: i, set(o) {
      const a = i?.call(this);
      n?.call(this, o), this.requestUpdate(t, a, s);
    }, configurable: !0, enumerable: !0 };
  }
  static getPropertyOptions(t) {
    return this.elementProperties.get(t) ?? it;
  }
  static _$Ei() {
    if (this.hasOwnProperty(T("elementProperties"))) return;
    const t = xt(this);
    t.finalize(), t.l !== void 0 && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties);
  }
  static finalize() {
    if (this.hasOwnProperty(T("finalized"))) return;
    if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(T("properties"))) {
      const e = this.properties, s = [...bt(e), ...wt(e)];
      for (const i of s) this.createProperty(i, e[i]);
    }
    const t = this[Symbol.metadata];
    if (t !== null) {
      const e = litPropertyMetadata.get(t);
      if (e !== void 0) for (const [s, i] of e) this.elementProperties.set(s, i);
    }
    this._$Eh = /* @__PURE__ */ new Map();
    for (const [e, s] of this.elementProperties) {
      const i = this._$Eu(e, s);
      i !== void 0 && this._$Eh.set(i, e);
    }
    this.elementStyles = this.finalizeStyles(this.styles);
  }
  static finalizeStyles(t) {
    const e = [];
    if (Array.isArray(t)) {
      const s = new Set(t.flat(1 / 0).reverse());
      for (const i of s) e.unshift(tt(i));
    } else t !== void 0 && e.push(tt(t));
    return e;
  }
  static _$Eu(t, e) {
    const s = e.attribute;
    return s === !1 ? void 0 : typeof s == "string" ? s : typeof t == "string" ? t.toLowerCase() : void 0;
  }
  constructor() {
    super(), this._$Ep = void 0, this.isUpdatePending = !1, this.hasUpdated = !1, this._$Em = null, this._$Ev();
  }
  _$Ev() {
    this._$ES = new Promise(((t) => this.enableUpdating = t)), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), this.constructor.l?.forEach(((t) => t(this)));
  }
  addController(t) {
    (this._$EO ??= /* @__PURE__ */ new Set()).add(t), this.renderRoot !== void 0 && this.isConnected && t.hostConnected?.();
  }
  removeController(t) {
    this._$EO?.delete(t);
  }
  _$E_() {
    const t = /* @__PURE__ */ new Map(), e = this.constructor.elementProperties;
    for (const s of e.keys()) this.hasOwnProperty(s) && (t.set(s, this[s]), delete this[s]);
    t.size > 0 && (this._$Ep = t);
  }
  createRenderRoot() {
    const t = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
    return _t(t, this.constructor.elementStyles), t;
  }
  connectedCallback() {
    this.renderRoot ??= this.createRenderRoot(), this.enableUpdating(!0), this._$EO?.forEach(((t) => t.hostConnected?.()));
  }
  enableUpdating(t) {
  }
  disconnectedCallback() {
    this._$EO?.forEach(((t) => t.hostDisconnected?.()));
  }
  attributeChangedCallback(t, e, s) {
    this._$AK(t, s);
  }
  _$ET(t, e) {
    const s = this.constructor.elementProperties.get(t), i = this.constructor._$Eu(t, s);
    if (i !== void 0 && s.reflect === !0) {
      const n = (s.converter?.toAttribute !== void 0 ? s.converter : j).toAttribute(e, s.type);
      this._$Em = t, n == null ? this.removeAttribute(i) : this.setAttribute(i, n), this._$Em = null;
    }
  }
  _$AK(t, e) {
    const s = this.constructor, i = s._$Eh.get(t);
    if (i !== void 0 && this._$Em !== i) {
      const n = s.getPropertyOptions(i), o = typeof n.converter == "function" ? { fromAttribute: n.converter } : n.converter?.fromAttribute !== void 0 ? n.converter : j;
      this._$Em = i, this[i] = o.fromAttribute(e, n.type) ?? this._$Ej?.get(i) ?? null, this._$Em = null;
    }
  }
  requestUpdate(t, e, s) {
    if (t !== void 0) {
      const i = this.constructor, n = this[t];
      if (s ??= i.getPropertyOptions(t), !((s.hasChanged ?? Z)(n, e) || s.useDefault && s.reflect && n === this._$Ej?.get(t) && !this.hasAttribute(i._$Eu(t, s)))) return;
      this.C(t, e, s);
    }
    this.isUpdatePending === !1 && (this._$ES = this._$EP());
  }
  C(t, e, { useDefault: s, reflect: i, wrapped: n }, o) {
    s && !(this._$Ej ??= /* @__PURE__ */ new Map()).has(t) && (this._$Ej.set(t, o ?? e ?? this[t]), n !== !0 || o !== void 0) || (this._$AL.has(t) || (this.hasUpdated || s || (e = void 0), this._$AL.set(t, e)), i === !0 && this._$Em !== t && (this._$Eq ??= /* @__PURE__ */ new Set()).add(t));
  }
  async _$EP() {
    this.isUpdatePending = !0;
    try {
      await this._$ES;
    } catch (e) {
      Promise.reject(e);
    }
    const t = this.scheduleUpdate();
    return t != null && await t, !this.isUpdatePending;
  }
  scheduleUpdate() {
    return this.performUpdate();
  }
  performUpdate() {
    if (!this.isUpdatePending) return;
    if (!this.hasUpdated) {
      if (this.renderRoot ??= this.createRenderRoot(), this._$Ep) {
        for (const [i, n] of this._$Ep) this[i] = n;
        this._$Ep = void 0;
      }
      const s = this.constructor.elementProperties;
      if (s.size > 0) for (const [i, n] of s) {
        const { wrapped: o } = n, a = this[i];
        o !== !0 || this._$AL.has(i) || a === void 0 || this.C(i, void 0, n, a);
      }
    }
    let t = !1;
    const e = this._$AL;
    try {
      t = this.shouldUpdate(e), t ? (this.willUpdate(e), this._$EO?.forEach(((s) => s.hostUpdate?.())), this.update(e)) : this._$EM();
    } catch (s) {
      throw t = !1, this._$EM(), s;
    }
    t && this._$AE(e);
  }
  willUpdate(t) {
  }
  _$AE(t) {
    this._$EO?.forEach(((e) => e.hostUpdated?.())), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(t)), this.updated(t);
  }
  _$EM() {
    this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1;
  }
  get updateComplete() {
    return this.getUpdateComplete();
  }
  getUpdateComplete() {
    return this._$ES;
  }
  shouldUpdate(t) {
    return !0;
  }
  update(t) {
    this._$Eq &&= this._$Eq.forEach(((e) => this._$ET(e, this[e]))), this._$EM();
  }
  updated(t) {
  }
  firstUpdated(t) {
  }
};
S.elementStyles = [], S.shadowRootOptions = { mode: "open" }, S[T("elementProperties")] = /* @__PURE__ */ new Map(), S[T("finalized")] = /* @__PURE__ */ new Map(), Et?.({ ReactiveElement: S }), (k.reactiveElementVersions ??= []).push("2.1.0");
const J = globalThis, I = J.trustedTypes, st = I ? I.createPolicy("lit-html", { createHTML: (r) => r }) : void 0, dt = "$lit$", y = `lit$${Math.random().toFixed(9).slice(2)}$`, ut = "?" + y, Ct = `<${ut}>`, w = document, M = () => w.createComment(""), N = (r) => r === null || typeof r != "object" && typeof r != "function", K = Array.isArray, Pt = (r) => K(r) || typeof r?.[Symbol.iterator] == "function", q = `[ 	
\f\r]`, P = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, rt = /-->/g, nt = />/g, A = RegExp(`>|${q}(?:([^\\s"'>=/]+)(${q}*=${q}*(?:[^ 	
\f\r"'\`<>=]|("|')|))|$)`, "g"), ot = /'/g, ht = /"/g, $t = /^(?:script|style|textarea|title)$/i, Ut = (r) => (t, ...e) => ({ _$litType$: r, strings: t, values: e }), U = Ut(1), x = /* @__PURE__ */ Symbol.for("lit-noChange"), $ = /* @__PURE__ */ Symbol.for("lit-nothing"), at = /* @__PURE__ */ new WeakMap(), b = w.createTreeWalker(w, 129);
function ft(r, t) {
  if (!K(r) || !r.hasOwnProperty("raw")) throw Error("invalid template strings array");
  return st !== void 0 ? st.createHTML(t) : t;
}
const Ot = (r, t) => {
  const e = r.length - 1, s = [];
  let i, n = t === 2 ? "<svg>" : t === 3 ? "<math>" : "", o = P;
  for (let a = 0; a < e; a++) {
    const h = r[a];
    let c, u, l = -1, d = 0;
    for (; d < h.length && (o.lastIndex = d, u = o.exec(h), u !== null); ) d = o.lastIndex, o === P ? u[1] === "!--" ? o = rt : u[1] !== void 0 ? o = nt : u[2] !== void 0 ? ($t.test(u[2]) && (i = RegExp("</" + u[2], "g")), o = A) : u[3] !== void 0 && (o = A) : o === A ? u[0] === ">" ? (o = i ?? P, l = -1) : u[1] === void 0 ? l = -2 : (l = o.lastIndex - u[2].length, c = u[1], o = u[3] === void 0 ? A : u[3] === '"' ? ht : ot) : o === ht || o === ot ? o = A : o === rt || o === nt ? o = P : (o = A, i = void 0);
    const p = o === A && r[a + 1].startsWith("/>") ? " " : "";
    n += o === P ? h + Ct : l >= 0 ? (s.push(c), h.slice(0, l) + dt + h.slice(l) + y + p) : h + y + (l === -2 ? a : p);
  }
  return [ft(r, n + (r[e] || "<?>") + (t === 2 ? "</svg>" : t === 3 ? "</math>" : "")), s];
};
class D {
  constructor({ strings: t, _$litType$: e }, s) {
    let i;
    this.parts = [];
    let n = 0, o = 0;
    const a = t.length - 1, h = this.parts, [c, u] = Ot(t, e);
    if (this.el = D.createElement(c, s), b.currentNode = this.el.content, e === 2 || e === 3) {
      const l = this.el.content.firstChild;
      l.replaceWith(...l.childNodes);
    }
    for (; (i = b.nextNode()) !== null && h.length < a; ) {
      if (i.nodeType === 1) {
        if (i.hasAttributes()) for (const l of i.getAttributeNames()) if (l.endsWith(dt)) {
          const d = u[o++], p = i.getAttribute(l).split(y), f = /([.?@])?(.*)/.exec(d);
          h.push({ type: 1, index: n, name: f[2], strings: p, ctor: f[1] === "." ? Ht : f[1] === "?" ? Mt : f[1] === "@" ? Nt : L }), i.removeAttribute(l);
        } else l.startsWith(y) && (h.push({ type: 6, index: n }), i.removeAttribute(l));
        if ($t.test(i.tagName)) {
          const l = i.textContent.split(y), d = l.length - 1;
          if (d > 0) {
            i.textContent = I ? I.emptyScript : "";
            for (let p = 0; p < d; p++) i.append(l[p], M()), b.nextNode(), h.push({ type: 2, index: ++n });
            i.append(l[d], M());
          }
        }
      } else if (i.nodeType === 8) if (i.data === ut) h.push({ type: 2, index: n });
      else {
        let l = -1;
        for (; (l = i.data.indexOf(y, l + 1)) !== -1; ) h.push({ type: 7, index: n }), l += y.length - 1;
      }
      n++;
    }
  }
  static createElement(t, e) {
    const s = w.createElement("template");
    return s.innerHTML = t, s;
  }
}
function E(r, t, e = r, s) {
  if (t === x) return t;
  let i = s !== void 0 ? e._$Co?.[s] : e._$Cl;
  const n = N(t) ? void 0 : t._$litDirective$;
  return i?.constructor !== n && (i?._$AO?.(!1), n === void 0 ? i = void 0 : (i = new n(r), i._$AT(r, e, s)), s !== void 0 ? (e._$Co ??= [])[s] = i : e._$Cl = i), i !== void 0 && (t = E(r, i._$AS(r, t.values), i, s)), t;
}
let Tt = class {
  constructor(t, e) {
    this._$AV = [], this._$AN = void 0, this._$AD = t, this._$AM = e;
  }
  get parentNode() {
    return this._$AM.parentNode;
  }
  get _$AU() {
    return this._$AM._$AU;
  }
  u(t) {
    const { el: { content: e }, parts: s } = this._$AD, i = (t?.creationScope ?? w).importNode(e, !0);
    b.currentNode = i;
    let n = b.nextNode(), o = 0, a = 0, h = s[0];
    for (; h !== void 0; ) {
      if (o === h.index) {
        let c;
        h.type === 2 ? c = new C(n, n.nextSibling, this, t) : h.type === 1 ? c = new h.ctor(n, h.name, h.strings, this, t) : h.type === 6 && (c = new Dt(n, this, t)), this._$AV.push(c), h = s[++a];
      }
      o !== h?.index && (n = b.nextNode(), o++);
    }
    return b.currentNode = w, i;
  }
  p(t) {
    let e = 0;
    for (const s of this._$AV) s !== void 0 && (s.strings !== void 0 ? (s._$AI(t, s, e), e += s.strings.length - 2) : s._$AI(t[e])), e++;
  }
};
class C {
  get _$AU() {
    return this._$AM?._$AU ?? this._$Cv;
  }
  constructor(t, e, s, i) {
    this.type = 2, this._$AH = $, this._$AN = void 0, this._$AA = t, this._$AB = e, this._$AM = s, this.options = i, this._$Cv = i?.isConnected ?? !0;
  }
  get parentNode() {
    let t = this._$AA.parentNode;
    const e = this._$AM;
    return e !== void 0 && t?.nodeType === 11 && (t = e.parentNode), t;
  }
  get startNode() {
    return this._$AA;
  }
  get endNode() {
    return this._$AB;
  }
  _$AI(t, e = this) {
    t = E(this, t, e), N(t) ? t === $ || t == null || t === "" ? (this._$AH !== $ && this._$AR(), this._$AH = $) : t !== this._$AH && t !== x && this._(t) : t._$litType$ !== void 0 ? this.$(t) : t.nodeType !== void 0 ? this.T(t) : Pt(t) ? this.k(t) : this._(t);
  }
  O(t) {
    return this._$AA.parentNode.insertBefore(t, this._$AB);
  }
  T(t) {
    this._$AH !== t && (this._$AR(), this._$AH = this.O(t));
  }
  _(t) {
    this._$AH !== $ && N(this._$AH) ? this._$AA.nextSibling.data = t : this.T(w.createTextNode(t)), this._$AH = t;
  }
  $(t) {
    const { values: e, _$litType$: s } = t, i = typeof s == "number" ? this._$AC(t) : (s.el === void 0 && (s.el = D.createElement(ft(s.h, s.h[0]), this.options)), s);
    if (this._$AH?._$AD === i) this._$AH.p(e);
    else {
      const n = new Tt(i, this), o = n.u(this.options);
      n.p(e), this.T(o), this._$AH = n;
    }
  }
  _$AC(t) {
    let e = at.get(t.strings);
    return e === void 0 && at.set(t.strings, e = new D(t)), e;
  }
  k(t) {
    K(this._$AH) || (this._$AH = [], this._$AR());
    const e = this._$AH;
    let s, i = 0;
    for (const n of t) i === e.length ? e.push(s = new C(this.O(M()), this.O(M()), this, this.options)) : s = e[i], s._$AI(n), i++;
    i < e.length && (this._$AR(s && s._$AB.nextSibling, i), e.length = i);
  }
  _$AR(t = this._$AA.nextSibling, e) {
    for (this._$AP?.(!1, !0, e); t && t !== this._$AB; ) {
      const s = t.nextSibling;
      t.remove(), t = s;
    }
  }
  setConnected(t) {
    this._$AM === void 0 && (this._$Cv = t, this._$AP?.(t));
  }
}
class L {
  get tagName() {
    return this.element.tagName;
  }
  get _$AU() {
    return this._$AM._$AU;
  }
  constructor(t, e, s, i, n) {
    this.type = 1, this._$AH = $, this._$AN = void 0, this.element = t, this.name = e, this._$AM = i, this.options = n, s.length > 2 || s[0] !== "" || s[1] !== "" ? (this._$AH = Array(s.length - 1).fill(new String()), this.strings = s) : this._$AH = $;
  }
  _$AI(t, e = this, s, i) {
    const n = this.strings;
    let o = !1;
    if (n === void 0) t = E(this, t, e, 0), o = !N(t) || t !== this._$AH && t !== x, o && (this._$AH = t);
    else {
      const a = t;
      let h, c;
      for (t = n[0], h = 0; h < n.length - 1; h++) c = E(this, a[s + h], e, h), c === x && (c = this._$AH[h]), o ||= !N(c) || c !== this._$AH[h], c === $ ? t = $ : t !== $ && (t += (c ?? "") + n[h + 1]), this._$AH[h] = c;
    }
    o && !i && this.j(t);
  }
  j(t) {
    t === $ ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t ?? "");
  }
}
class Ht extends L {
  constructor() {
    super(...arguments), this.type = 3;
  }
  j(t) {
    this.element[this.name] = t === $ ? void 0 : t;
  }
}
class Mt extends L {
  constructor() {
    super(...arguments), this.type = 4;
  }
  j(t) {
    this.element.toggleAttribute(this.name, !!t && t !== $);
  }
}
class Nt extends L {
  constructor(t, e, s, i, n) {
    super(t, e, s, i, n), this.type = 5;
  }
  _$AI(t, e = this) {
    if ((t = E(this, t, e, 0) ?? $) === x) return;
    const s = this._$AH, i = t === $ && s !== $ || t.capture !== s.capture || t.once !== s.once || t.passive !== s.passive, n = t !== $ && (s === $ || i);
    i && this.element.removeEventListener(this.name, this, s), n && this.element.addEventListener(this.name, this, t), this._$AH = t;
  }
  handleEvent(t) {
    typeof this._$AH == "function" ? this._$AH.call(this.options?.host ?? this.element, t) : this._$AH.handleEvent(t);
  }
}
class Dt {
  constructor(t, e, s) {
    this.element = t, this.type = 6, this._$AN = void 0, this._$AM = e, this.options = s;
  }
  get _$AU() {
    return this._$AM._$AU;
  }
  _$AI(t) {
    E(this, t);
  }
}
const Rt = { I: C }, zt = J.litHtmlPolyfillSupport;
zt?.(D, C), (J.litHtmlVersions ??= []).push("3.3.0");
const jt = (r, t, e) => {
  const s = e?.renderBefore ?? t;
  let i = s._$litPart$;
  if (i === void 0) {
    const n = e?.renderBefore ?? null;
    s._$litPart$ = i = new C(t.insertBefore(M(), n), n, void 0, e ?? {});
  }
  return i._$AI(r), i;
};
const Q = globalThis;
let H = class extends S {
  constructor() {
    super(...arguments), this.renderOptions = { host: this }, this._$Do = void 0;
  }
  createRenderRoot() {
    const t = super.createRenderRoot();
    return this.renderOptions.renderBefore ??= t.firstChild, t;
  }
  update(t) {
    const e = this.render();
    this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(t), this._$Do = jt(e, this.renderRoot, this.renderOptions);
  }
  connectedCallback() {
    super.connectedCallback(), this._$Do?.setConnected(!0);
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this._$Do?.setConnected(!1);
  }
  render() {
    return x;
  }
};
H._$litElement$ = !0, H.finalized = !0, Q.litElementHydrateSupport?.({ LitElement: H });
const It = Q.litElementPolyfillSupport;
It?.({ LitElement: H });
(Q.litElementVersions ??= []).push("4.2.0");
const kt = { CHILD: 2 }, Lt = (r) => (...t) => ({ _$litDirective$: r, values: t });
class Bt {
  constructor(t) {
  }
  get _$AU() {
    return this._$AM._$AU;
  }
  _$AT(t, e, s) {
    this._$Ct = t, this._$AM = e, this._$Ci = s;
  }
  _$AS(t, e) {
    return this.update(t, e);
  }
  update(t, e) {
    return this.render(...e);
  }
}
const { I: Wt } = Rt, lt = () => document.createComment(""), O = (r, t, e) => {
  const s = r._$AA.parentNode, i = t === void 0 ? r._$AB : t._$AA;
  if (e === void 0) {
    const n = s.insertBefore(lt(), i), o = s.insertBefore(lt(), i);
    e = new Wt(n, o, r, r.options);
  } else {
    const n = e._$AB.nextSibling, o = e._$AM, a = o !== r;
    if (a) {
      let h;
      e._$AQ?.(r), e._$AM = r, e._$AP !== void 0 && (h = r._$AU) !== o._$AU && e._$AP(h);
    }
    if (n !== i || a) {
      let h = e._$AA;
      for (; h !== n; ) {
        const c = h.nextSibling;
        s.insertBefore(h, i), h = c;
      }
    }
  }
  return e;
}, v = (r, t, e = r) => (r._$AI(t, e), r), qt = {}, Vt = (r, t = qt) => r._$AH = t, Ft = (r) => r._$AH, V = (r) => {
  r._$AP?.(!1, !0);
  let t = r._$AA;
  const e = r._$AB.nextSibling;
  for (; t !== e; ) {
    const s = t.nextSibling;
    t.remove(), t = s;
  }
};
const ct = (r, t, e) => {
  const s = /* @__PURE__ */ new Map();
  for (let i = t; i <= e; i++) s.set(r[i], i);
  return s;
}, Gt = Lt(class extends Bt {
  constructor(r) {
    if (super(r), r.type !== kt.CHILD) throw Error("repeat() can only be used in text expressions");
  }
  dt(r, t, e) {
    let s;
    e === void 0 ? e = t : t !== void 0 && (s = t);
    const i = [], n = [];
    let o = 0;
    for (const a of r) i[o] = s ? s(a, o) : o, n[o] = e(a, o), o++;
    return { values: n, keys: i };
  }
  render(r, t, e) {
    return this.dt(r, t, e).values;
  }
  update(r, [t, e, s]) {
    const i = Ft(r), { values: n, keys: o } = this.dt(t, e, s);
    if (!Array.isArray(i)) return this.ut = o, n;
    const a = this.ut ??= [], h = [];
    let c, u, l = 0, d = i.length - 1, p = 0, f = n.length - 1;
    for (; l <= d && p <= f; ) if (i[l] === null) l++;
    else if (i[d] === null) d--;
    else if (a[l] === o[p]) h[p] = v(i[l], n[p]), l++, p++;
    else if (a[d] === o[f]) h[f] = v(i[d], n[f]), d--, f--;
    else if (a[l] === o[f]) h[f] = v(i[l], n[f]), O(r, h[f + 1], i[l]), l++, f--;
    else if (a[d] === o[p]) h[p] = v(i[d], n[p]), O(r, i[l], i[d]), d--, p++;
    else if (c === void 0 && (c = ct(o, p, f), u = ct(a, l, d)), c.has(a[l])) if (c.has(a[d])) {
      const _ = u.get(o[p]), W = _ !== void 0 ? i[_] : null;
      if (W === null) {
        const X = O(r, i[l]);
        v(X, n[p]), h[p] = X;
      } else h[p] = v(W, n[p]), O(r, i[l], W), i[_] = null;
      p++;
    } else V(i[d]), d--;
    else V(i[l]), l++;
    for (; p <= f; ) {
      const _ = O(r, h[f + 1]);
      v(_, n[p]), h[p++] = _;
    }
    for (; l <= d; ) {
      const _ = i[l++];
      _ !== null && V(_);
    }
    return this.ut = o, Vt(r, h), x;
  }
});
const Zt = (r) => r ?? $;
const Jt = (r) => (t, e) => {
  e !== void 0 ? e.addInitializer((() => {
    customElements.define(r, t);
  })) : customElements.define(r, t);
};
const Kt = { attribute: !0, type: String, converter: j, reflect: !1, hasChanged: Z }, Qt = (r = Kt, t, e) => {
  const { kind: s, metadata: i } = e;
  let n = globalThis.litPropertyMetadata.get(i);
  if (n === void 0 && globalThis.litPropertyMetadata.set(i, n = /* @__PURE__ */ new Map()), s === "setter" && ((r = Object.create(r)).wrapped = !0), n.set(e.name, r), s === "accessor") {
    const { name: o } = e;
    return { set(a) {
      const h = t.get.call(this);
      t.set.call(this, a), this.requestUpdate(o, h, r);
    }, init(a) {
      return a !== void 0 && this.C(o, void 0, r, a), a;
    } };
  }
  if (s === "setter") {
    const { name: o } = e;
    return function(a) {
      const h = this[o];
      t.call(this, a), this.requestUpdate(o, h, r);
    };
  }
  throw Error("Unsupported decorator location: " + s);
};
function B(r) {
  return (t, e) => typeof e == "object" ? Qt(r, t, e) : ((s, i, n) => {
    const o = i.hasOwnProperty(n);
    return i.constructor.createProperty(n, s), o ? Object.getOwnPropertyDescriptor(i, n) : void 0;
  })(r, t, e);
}
function R(r) {
  return B({ ...r, state: !0, attribute: !1 });
}
const Xt = (r, t, e) => (e.configurable = !0, e.enumerable = !0, Reflect.decorate && typeof t != "object" && Object.defineProperty(r, t, e), e);
function Yt(r, t) {
  return (e, s, i) => {
    const n = (o) => o.renderRoot?.querySelector(r) ?? null;
    return Xt(e, s, { get() {
      return n(this);
    } });
  };
}
var te = Object.defineProperty, ee = Object.getOwnPropertyDescriptor, g = (r, t, e, s) => {
  for (var i = s > 1 ? void 0 : s ? ee(t, e) : t, n = r.length - 1, o; n >= 0; n--)
    (o = r[n]) && (i = (s ? o(t, e, i) : o(i)) || i);
  return s && i && te(t, e, i), i;
};
let m = class extends H {
  constructor() {
    super(...arguments), this.elementWidth = 0, this.elementHeight = 0, this.version = "1.1.17";
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this.resizeObserver && this.resizeObserver.disconnect();
  }
  update(r) {
    (r.has("inputData") || r.has("timeRange")) && this.updateGridLayout(), r.has("theme") && this.registerTheme(this.theme), super.update(r);
  }
  firstUpdated(r) {
    this.registerTheme(this.theme), this.wrapper && (this.resizeObserver = new ResizeObserver(() => {
      this.updateGridLayout();
    }), this.resizeObserver.observe(this.wrapper), this.updateGridLayout());
  }
  registerTheme(r) {
    const t = getComputedStyle(this).getPropertyValue("--re-text-color").trim(), e = getComputedStyle(this).getPropertyValue("--re-tile-background-color").trim();
    this.themeBgColor = e || this.theme?.theme_object?.backgroundColor, this.themeTitleColor = t || this.theme?.theme_object?.title?.textStyle?.color, this.themeSubtitleColor = t || this.theme?.theme_object?.title?.subtextStyle?.color || this.themeTitleColor;
  }
  /**
   * Get images filtered by timeRange if available
   */
  getFilteredImages() {
    const r = this.inputData?.useUpload ? typeof this.inputData?.image == "string" ? this.inputData.image : "" : this.inputData?.imageUrl ?? "";
    let t = this.inputData?.multiImage ? this.inputData?.data ?? [] : [{ imageUrl: r, label: this.inputData?.title ?? "" }];
    if (this.timeRange && this.inputData?.multiImage) {
      const e = Number(this.timeRange.start), s = Number(this.timeRange.end);
      (!isNaN(e) || !isNaN(s)) && (t = t.filter((i) => {
        const n = i.timestamp;
        if (n == null) return !0;
        const o = Number(n);
        return isNaN(o) ? !0 : !(!isNaN(e) && o < e || !isNaN(s) && o > s);
      }));
    }
    return t;
  }
  /**
   * Update grid layout based on container size and number of elements
   */
  updateGridLayout() {
    if (!this.wrapper) return;
    const t = this.getFilteredImages().length;
    if (t === 0) return;
    const e = this.wrapper.getBoundingClientRect(), s = e.width * 0.04, i = e.height * 0.04, n = e.width - s, o = e.height - i;
    if (n <= 0 || o <= 0) return;
    const a = this.optimizeLayout(
      n,
      o,
      t,
      (c, u) => Math.abs(c / u - 1 / 1),
      this.inputData?.gap ?? 12
    );
    this.elementWidth = a.elementWidth, this.elementHeight = a.elementHeight, this.wrapper.querySelectorAll(".image-item").forEach((c) => {
      c.style.width = `${a.elementWidth}px`, c.style.height = `${a.elementHeight}px`;
    });
  }
  /**
   * Optimize grid layout by minimizing an error function
   * @param containerWidth - Available width for the grid
   * @param containerHeight - Available height for the grid
   * @param numElements - Number of elements to arrange
   * @param errorFn - Error function that takes (element_width, element_height) and returns error value
   * @param gap - Gap between elements (default: 12)
   * @returns Optimal layout configuration
   */
  optimizeLayout(r, t, e, s, i = 12) {
    let n = {
      elementWidth: 0,
      elementHeight: 0,
      numCols: 1,
      numRows: e,
      error: 1 / 0
    };
    for (let o = 1; o <= e; o++) {
      const a = Math.ceil(e / o), h = i * (o - 1), c = i * (a - 1), u = r - h, l = t - c;
      if (u <= 0 || l <= 0) continue;
      const d = u / o, p = l / a, f = s(d, p);
      f < n.error && (n = {
        elementWidth: d,
        elementHeight: p,
        numCols: o,
        numRows: a,
        error: f
      });
    }
    return n;
  }
  render() {
    const r = this.getFilteredImages(), t = r.length > 1, e = r.filter((i) => i.label).length > 0, s = r.some((i) => i.imageUrl);
    return U`
            <div
                class="wrapper"
                style="background-color: ${this.themeBgColor}; color: ${this.themeTitleColor}; gap: ${t ? `${this.inputData?.gap ?? 12}px` : "0px"}; ${t ? "" : "flex-direction: column;"}"
            >
                ${!t && this.inputData?.title ? U`
                          <h3
                              class="paging"
                              ?active=${this.inputData?.title}
                              style="color: ${this.themeTitleColor};"
                          >
                              ${this.inputData?.title}
                          </h3>
                      ` : $}
                ${!t && this.inputData?.subTitle ? U`
                          <p
                              class="paging"
                              ?active=${this.inputData?.subTitle}
                              style="color: ${this.themeSubtitleColor};"
                          >
                              ${this.inputData?.subTitle}
                          </p>
                      ` : $}
                <div class="paging no-data" ?active=${!s} style="color: ${this.themeTitleColor};">
                    No Image
                </div>
                ${Gt(
      r,
      (i) => i.imageUrl,
      (i) => U`
                        <div
                            class="image-item"
                            style="width: ${this.elementWidth}px; height: ${this.elementHeight}px;"
                        >
                            ${e ? U`<h2
                                      class="title"
                                      style="${this.inputData?.labelFontSize ? `font-size: ${this.inputData.labelFontSize}px;` : ""}"
                                  >
                                      ${i.label ?? ""}
                                  </h2>` : $}
                            <div class="img-container paging" ?active="${i.imageUrl}">
                                <img
                                    src="${Zt(i.imageUrl)}"
                                    alt="${i.label || "Image Widget"}"
                                    style="object-fit: ${this.inputData?.stretchToFit ? "fill" : "contain"}"
                                />
                            </div>
                        </div>
                    `
    )}
            </div>
        `;
  }
};
m.styles = gt`
        :host {
            display: block;
            font-family: sans-serif;
            box-sizing: border-box;
            margin: auto;
            container-type: size;
        }

        .paging:not([active]) {
            display: none !important;
        }

        .wrapper {
            display: flex;
            flex-wrap: wrap;
            height: 100%;
            width: 100%;
            padding: 2cqh 2cqw;
            box-sizing: border-box;
            gap: 12px;
            align-content: flex-start;
        }

        .wrapper > * {
            flex-shrink: 1;
            min-width: 0;
            min-height: 0;
        }

        .image-item {
            display: flex;
            flex-direction: column;
            box-sizing: border-box;
            max-width: 100%;
            max-height: 100%;
            overflow: hidden;
        }

        .title {
            height: 24px;
            font-size: 18px;
            margin: 0;
            padding: 0 4px;
            overflow: hidden;
            text-overflow: ellipsis;
            text-align: center;
            flex: 0 0 auto;
            white-space: nowrap;
        }

        h3 {
            margin: 0;
            max-width: 300px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        p {
            margin: 10px 0 0 0;
            max-width: 300px;
            font-size: 14px;
            line-height: 17px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .img-container {
            flex: 1;
            box-sizing: border-box;
            overflow: hidden;
            min-width: 0;
            min-height: 0;
        }

        img {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }
        .no-data {
            font-size: 20px;
            display: flex;
            height: 100%;
            width: 100%;
            text-align: center;
            align-items: center;
            justify-content: center;
        }
    `;
g([
  B({ type: Object })
], m.prototype, "inputData", 2);
g([
  B({ type: Object })
], m.prototype, "theme", 2);
g([
  B({ type: Object })
], m.prototype, "timeRange", 2);
g([
  R()
], m.prototype, "themeBgColor", 2);
g([
  R()
], m.prototype, "themeTitleColor", 2);
g([
  R()
], m.prototype, "themeSubtitleColor", 2);
g([
  R()
], m.prototype, "elementWidth", 2);
g([
  R()
], m.prototype, "elementHeight", 2);
g([
  Yt(".wrapper")
], m.prototype, "wrapper", 2);
m = g([
  Jt("widget-image-1.1.17")
], m);
export {
  m as WidgetImage
};
//# sourceMappingURL=widget-image.js.map
