import { o as l } from "./rolldown-runtime.js";
import { i as p, n as u } from "./vendor/react.js";
import { t as d } from "./AIInput.js";
var i = /* @__PURE__ */ l(p(), 1), h = u();
function m(t) {
  return {
    onChange: (e) => {
      t.dispatchEvent(new CustomEvent("change", {
        detail: e,
        bubbles: !0,
        composed: !0
      }));
    },
    onSubmit: (e) => {
      t.dispatchEvent(new CustomEvent("submit", {
        detail: e,
        bubbles: !0,
        composed: !0
      }));
    },
    onRemoveFile: (e) => {
      t.dispatchEvent(new CustomEvent("remove-file", {
        detail: e,
        bubbles: !0,
        composed: !0
      }));
    },
    onCancelUpload: (e) => {
      t.dispatchEvent(new CustomEvent("cancel-upload", {
        detail: e,
        bubbles: !0,
        composed: !0
      }));
    },
    onRetryUpload: (e) => {
      t.dispatchEvent(new CustomEvent("retry-upload", {
        detail: e,
        bubbles: !0,
        composed: !0
      }));
    },
    onRemoveAllFiles: (e) => {
      t.dispatchEvent(new CustomEvent("remove-all-files", {
        detail: e,
        bubbles: !0,
        composed: !0
      }));
    },
    onFilesSelected: (e) => {
      t.dispatchEvent(new CustomEvent("files-selected", {
        detail: e,
        bubbles: !0,
        composed: !0
      }));
    }
  };
}
function b(t) {
  const { _hostElement: e, ...r } = t, s = i.useMemo(() => e ? m(e) : {}, [e]);
  return i.createElement(d, {
    ...r,
    ...s
  });
}
var n = {
  variant: "string",
  size: "string",
  placeholder: "string",
  value: "string",
  uploadingFiles: "json",
  accept: "string",
  multiple: "boolean",
  dropText: "string",
  disabled: "boolean",
  className: "string",
  leadingActions: "json",
  trailingActions: "json",
  submitButton: "string",
  defaultButton: "string",
  leadingIcon: "json"
};
function o(t, e) {
  if (t !== null)
    switch (e) {
      case "number":
        return Number(t);
      case "boolean":
        return t !== "false" && t !== "0";
      case "json":
        try {
          return JSON.parse(t);
        } catch {
          return t;
        }
      default:
        return t;
    }
}
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 t = [];
    for (const r of Array.from(this.childNodes))
      r.nodeType === Node.TEXT_NODE && !r.textContent?.trim() || t.push(r);
    const e = document.createElement("div");
    for (e.style.display = "contents", this._childrenContainer = document.createElement("div"), this._childrenContainer.style.display = "contents", t.forEach((r) => this._childrenContainer.appendChild(r)); this.firstChild; ) this.removeChild(this.firstChild);
    this.appendChild(e), this._root = (0, h.createRoot)(e), this._render();
  }
  disconnectedCallback() {
    this._root?.unmount(), this._root = null;
  }
  attributeChangedCallback(t, e, r) {
    this._render();
  }
  static get observedAttributes() {
    return Object.keys(n).map((t) => t.replace(/([A-Z])/g, "-$1").toLowerCase());
  }
  _setProp(t, e) {
    const r = n[t] || "string";
    this._props[t] = this._parseValue(e, r), this._render();
  }
  _parseValue(t, e) {
    if (e === "boolean" && typeof t == "boolean" || e === "number" && typeof t == "number" || e === "string" && typeof t == "string") return t;
    if (typeof t == "string") switch (e) {
      case "boolean":
        return t !== "false" && t !== "0" && t !== "";
      case "number":
        return Number(t);
      case "json":
        try {
          return JSON.parse(t);
        } catch {
          return t;
        }
      default:
        return t;
    }
    return t;
  }
  _getProp(t) {
    if (t in this._props) return this._props[t];
    const e = t.replace(/([A-Z])/g, "-$1").toLowerCase(), r = n[t] || "string";
    return o(this.getAttribute(e), r);
  }
  _render() {
    if (!this._root) return;
    const t = {};
    for (const [r, s] of Object.entries(n)) if (r in this._props) t[r] = this._props[r];
    else {
      const c = r.replace(/([A-Z])/g, "-$1").toLowerCase();
      t[r] = o(this.getAttribute(c), s);
    }
    const e = i.createElement(b, {
      ...t,
      _hostElement: this
    });
    this._root.render(e);
  }
};
for (const t of Object.keys(n)) Object.defineProperty(a.prototype, t, {
  get() {
    return this._getProp(t);
  },
  set(e) {
    this._setProp(t, e);
  },
  enumerable: !0,
  configurable: !0
});
typeof customElements < "u" && !customElements.get("hf-ai-input") && customElements.define("hf-ai-input", a);
export {
  a as AIInputWC,
  a as default
};

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