import { o as h } from "./rolldown-runtime.js";
import { i as m, n as b, t as f } from "./vendor/react.js";
import { t as o } from "./utils.js";
var a = /* @__PURE__ */ h(m(), 1), s = f(), d = a.forwardRef(({ className: e, disableOverflow: t, ...r }, n) => /* @__PURE__ */ (0, s.jsx)("div", {
  "data-slot": "table-container",
  className: o("relative w-full", !t && "overflow-x-auto"),
  children: /* @__PURE__ */ (0, s.jsx)("table", {
    ref: n,
    "data-slot": "table",
    className: o("w-full caption-bottom text-sm", e),
    ...r
  })
}));
d.displayName = "Table";
var u = a.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ (0, s.jsx)("thead", {
  ref: r,
  "data-slot": "table-header",
  className: o("[&_tr]:border-b", e),
  ...t
}));
u.displayName = "TableHeader";
var _ = a.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ (0, s.jsx)("tbody", {
  ref: r,
  "data-slot": "table-body",
  className: o("[&_tr:last-child]:border-0", e),
  ...t
}));
_.displayName = "TableBody";
var y = a.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ (0, s.jsx)("tfoot", {
  ref: r,
  "data-slot": "table-footer",
  className: o("bg-muted/50 border-t font-medium [&>tr]:last:border-b-0", e),
  ...t
}));
y.displayName = "TableFooter";
var N = a.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ (0, s.jsx)("tr", {
  ref: r,
  "data-slot": "table-row",
  className: o("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors duration-200 ease-[var(--ease-smooth)] motion-reduce:transition-none", e),
  ...t
}));
N.displayName = "TableRow";
var C = a.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ (0, s.jsx)("th", {
  ref: r,
  "data-slot": "table-head",
  className: o("text-foreground h-10 px-2 text-start align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pe-0", e),
  ...t
}));
C.displayName = "TableHead";
var w = a.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ (0, s.jsx)("td", {
  ref: r,
  "data-slot": "table-cell",
  className: o("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pe-0", e),
  ...t
}));
w.displayName = "TableCell";
var T = a.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ (0, s.jsx)("caption", {
  ref: r,
  "data-slot": "table-caption",
  className: o("text-muted-foreground mt-4 text-sm", e),
  ...t
}));
T.displayName = "TableCaption";
var g = b(), i = { disableOverflow: "boolean" };
function l(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 c = 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, g.createRoot)(t), this._render();
  }
  disconnectedCallback() {
    this._root?.unmount(), this._root = null;
  }
  attributeChangedCallback(e, t, r) {
    this._render();
  }
  static get observedAttributes() {
    return Object.keys(i).map((e) => e.replace(/([A-Z])/g, "-$1").toLowerCase());
  }
  _setProp(e, t) {
    const r = i[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 = i[e] || "string";
    return l(this.getAttribute(t), r);
  }
  _render() {
    if (!this._root || !this._childrenContainer) return;
    const e = {};
    for (const [r, n] of Object.entries(i)) if (r in this._props) e[r] = this._props[r];
    else {
      const p = r.replace(/([A-Z])/g, "-$1").toLowerCase();
      e[r] = l(this.getAttribute(p), n);
    }
    const t = a.createElement(d, {
      ...e,
      _hostElement: this
    }, a.createElement("span", {
      ref: (r) => {
        r && this._childrenContainer && r.replaceWith(this._childrenContainer);
      },
      style: { display: "contents" }
    }));
    this._root.render(t);
  }
};
for (const e of Object.keys(i)) Object.defineProperty(c.prototype, e, {
  get() {
    return this._getProp(e);
  },
  set(t) {
    this._setProp(e, t);
  },
  enumerable: !0,
  configurable: !0
});
typeof customElements < "u" && !customElements.get("hf-table") && customElements.define("hf-table", c);
export {
  c as TableWC,
  c as default
};

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