import { o as p } from "./rolldown-runtime.js";
import { i as h, n as l } from "./vendor/react.js";
import { t as u } from "./Pagination.js";
var i = /* @__PURE__ */ p(h(), 1), d = l();
function m(e) {
  return {
    onPageChange: (t) => {
      e.dispatchEvent(new CustomEvent("page-change", {
        detail: t,
        bubbles: !0,
        composed: !0
      }));
    },
    onPerPageChange: (t) => {
      e.dispatchEvent(new CustomEvent("per-page-change", {
        detail: t,
        bubbles: !0,
        composed: !0
      }));
    }
  };
}
function f(e) {
  const { _hostElement: t, ...r } = e, s = i.useMemo(() => t ? m(t) : {}, [t]);
  return i.createElement(u, {
    ...r,
    ...s
  });
}
var n = {
  type: "string",
  size: "string",
  variant: "string",
  shape: "string",
  prevNextStyle: "string",
  currentPage: "number",
  totalPages: "number",
  siblingCount: "number",
  showPageNumbers: "boolean",
  previousText: "string",
  nextText: "string",
  itemsPerPage: "number",
  perPageOptions: "json",
  activeColor: "string"
};
function o(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, d.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 o(this.getAttribute(t), r);
  }
  _render() {
    if (!this._root || !this._childrenContainer) return;
    const e = {};
    for (const [r, s] 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] = o(this.getAttribute(c), s);
    }
    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-pagination") && customElements.define("hf-pagination", a);
export {
  a as PaginationWC,
  a as default
};

//# sourceMappingURL=hf-pagination.js.map