import { o as p } from "./rolldown-runtime.js";
import { i as l, n as h } from "./vendor/react.js";
import { t as d } from "./AIContainer.js";
var i = /* @__PURE__ */ p(l(), 1), u = h();
function m(e) {
  return { onMinimize: (t) => {
    e.dispatchEvent(new CustomEvent("minimize", {
      detail: t,
      bubbles: !0,
      composed: !0
    }));
  } };
}
function f(e) {
  const { _hostElement: t, ...r } = e, o = i.useMemo(() => t ? m(t) : {}, [t]);
  return i.createElement(d, {
    ...r,
    ...o
  });
}
var n = {
  messages: "json",
  inputProps: "string",
  showMinimize: "boolean",
  emptyContent: "json",
  showScrollButton: "boolean",
  scrollThreshold: "number",
  autoScrollOnNewMessage: "boolean",
  showTopFade: "boolean",
  className: "string",
  messageAreaClassName: "string"
};
function s(e, t) {
  if (e !== null)
    switch (t) {
      case "number":
        return Number(e);
      case "boolean":
        return e !== "false" && e !== "0";
      case "json":
        try {
          return JSON.parse(e);
        } catch {
          return e;
        }
      default:
        return e;
    }
}
var a = class extends HTMLElement {
  _root = null;
  _childrenContainer = null;
  _props = {};
  _initialized = !1;
  connectedCallback() {
    setTimeout(() => this._initialize(), 0);
  }
  _initialize() {
    if (this._initialized) return;
    this._initialized = !0;
    const e = [];
    for (const r of Array.from(this.childNodes))
      r.nodeType === Node.TEXT_NODE && !r.textContent?.trim() || e.push(r);
    const t = document.createElement("div");
    for (t.style.display = "contents", this._childrenContainer = document.createElement("div"), this._childrenContainer.style.display = "contents", e.forEach((r) => this._childrenContainer.appendChild(r)); this.firstChild; ) this.removeChild(this.firstChild);
    this.appendChild(t), this._root = (0, u.createRoot)(t), this._render();
  }
  disconnectedCallback() {
    this._root?.unmount(), this._root = null;
  }
  attributeChangedCallback(e, t, r) {
    this._render();
  }
  static get observedAttributes() {
    return Object.keys(n).map((e) => e.replace(/([A-Z])/g, "-$1").toLowerCase());
  }
  _setProp(e, t) {
    const r = n[e] || "string";
    this._props[e] = this._parseValue(t, r), this._render();
  }
  _parseValue(e, t) {
    if (t === "boolean" && typeof e == "boolean" || t === "number" && typeof e == "number" || t === "string" && typeof e == "string") return e;
    if (typeof e == "string") switch (t) {
      case "boolean":
        return e !== "false" && e !== "0" && e !== "";
      case "number":
        return Number(e);
      case "json":
        try {
          return JSON.parse(e);
        } catch {
          return e;
        }
      default:
        return e;
    }
    return e;
  }
  _getProp(e) {
    if (e in this._props) return this._props[e];
    const t = e.replace(/([A-Z])/g, "-$1").toLowerCase(), r = n[e] || "string";
    return s(this.getAttribute(t), r);
  }
  _render() {
    if (!this._root || !this._childrenContainer) return;
    const e = {};
    for (const [r, o] of Object.entries(n)) if (r in this._props) e[r] = this._props[r];
    else {
      const c = r.replace(/([A-Z])/g, "-$1").toLowerCase();
      e[r] = s(this.getAttribute(c), o);
    }
    const t = i.createElement(f, {
      ...e,
      _hostElement: this
    }, i.createElement("span", {
      ref: (r) => {
        r && this._childrenContainer && r.replaceWith(this._childrenContainer);
      },
      style: { display: "contents" }
    }));
    this._root.render(t);
  }
};
for (const e of Object.keys(n)) Object.defineProperty(a.prototype, e, {
  get() {
    return this._getProp(e);
  },
  set(t) {
    this._setProp(e, t);
  },
  enumerable: !0,
  configurable: !0
});
typeof customElements < "u" && !customElements.get("hf-ai-container") && customElements.define("hf-ai-container", a);
export {
  a as AIContainerWC,
  a as default
};

//# sourceMappingURL=hf-ai-container.js.map