import { jsx as o, jsxs as c } from "react/jsx-runtime";
import { Table as j } from "./components/TablePrimitive.js";
import { useMemo as t, useState as w, useCallback as A } from "react";
import L from "../text/Text.js";
import O from "../box/Box.js";
import D from "../app-header/AppHeader.js";
import E from "./context/tableStyleContext.js";
import { ScrollArea as F } from "../scroll-area/ScrollAreaPrimitive.js";
import K from "./components/table-header/TableHeader.js";
import M from "./components/table-body/TableBody.js";
import W from "./components/table-loader/TableLoader.js";
import "./types/ColumnAlign.js";
const $ = ({
  columns: a,
  dataSource: g,
  isLoading: x = !1,
  emptyContent: m,
  hasColumnSeparator: e = !1,
  hasHeader: T = !0,
  size: v = "md",
  height: f = 500,
  onRowClick: H,
  expandable: b,
  headerStyle: r,
  toolbar: s,
  title: d,
  description: l
}) => {
  const u = t(() => {
    if (s)
      return s;
    if (!(!d && !l))
      return {
        title: d ?? "",
        subtitle: l
      };
  }, [l, d, s]), [n, h] = w(0), B = t(
    () => m || /* @__PURE__ */ o(L, { type: "body", align: "center", children: "Keine Daten verfügbar" }),
    [m]
  ), C = A(
    (i) => {
      if (i) {
        const p = i.getBoundingClientRect().height;
        p !== n && h(p);
      }
    },
    [n]
  ), N = t(() => e === !0 || e === "headerOnly", [e]), k = t(() => e === !0 || e === "bodyOnly", [e]), y = t(() => a.some((i) => i.maxWidth !== void 0), [a]), R = {
    header: { backgroundColor: r == null ? void 0 : r.backgroundColor },
    headerText: { color: r == null ? void 0 : r.color }
  };
  return /* @__PURE__ */ c(O, { className: "space-y-4", children: [
    u && /* @__PURE__ */ o(D, { ...u }),
    /* @__PURE__ */ o(E, { value: { ...R }, children: /* @__PURE__ */ c(
      F,
      {
        className: "border border-[var(--base-border)] rounded-[var(--border-radius-default)]",
        style: n < f ? {} : { height: f },
        children: [
          /* @__PURE__ */ c(j, { ref: C, className: y ? "table-fixed" : void 0, children: [
            T && /* @__PURE__ */ o(K, { columns: a, hasColumnSeparator: N, hasExpandableRows: !!b }),
            /* @__PURE__ */ o(
              M,
              {
                dataSource: g,
                columns: a,
                emptyStateContent: B,
                hasColumnSeparator: k,
                size: v,
                onRowClick: H,
                expandable: b
              }
            )
          ] }),
          x && /* @__PURE__ */ o(W, {})
        ]
      }
    ) })
  ] });
};
$.displayName = "Table";
export {
  $ as default
};
//# sourceMappingURL=Table.js.map
