import { jsxs as Y, jsx as e, Fragment as F } from "react/jsx-runtime";
import { useState as S, useMemo as Z, createElement as y, isValidElement as w } from "react";
import { c as I, s as ss, B as L, a as as } from "../tools/tools.js";
import { T as M } from "./table-caption.js";
import { T as W } from "./table-responsive.js";
import { T as q } from "./table-tbody.js";
import { T as A } from "./table-td.js";
import { T as G } from "./table-tfoot.js";
import { T as R } from "./table-th.js";
import { T as H } from "./table-thead.js";
import { T as P } from "./table-tr.js";
const os = (a) => L(a) && !w(a), g = (a = []) => a.map((n, t) => ({
  ...n,
  id: n.id ?? t
})), es = (a, n, t, f, l, p) => {
  const r = `${n.key ?? n.id}${t.id}`, o = os(a), c = o ? a.colSpan : void 0, b = o ? a.rowSpan : void 0, T = o ? a.variant : void 0, u = o ? a.active : void 0, k = o ? a.thProps : void 0, m = o ? a.tdProps : void 0, h = o ? a.value : a;
  return p && l === 0 ? /* @__PURE__ */ y(
    R,
    {
      ...k,
      active: u,
      colSpan: c,
      key: r,
      rowSpan: b,
      scope: t.scope,
      variant: T
    },
    h
  ) : /* @__PURE__ */ y(A, { ...m, active: u, colSpan: c, key: r, rowSpan: b, variant: T }, h);
}, C = ({
  headOptions: a,
  rowIndex: n,
  rowItem: t,
  type: f = "values"
}) => a.map((l, p) => {
  const r = t[f], o = r.find(
    (c) => "key" in l && L(c) && c.key === l.key
  ) ?? r[p];
  return o ? es(o, l, t, n, p, t.scope === "row") : null;
}), i = function(n) {
  const {
    as: t = "table",
    body: f = [],
    bodyProps: l,
    bordered: p,
    borderless: r,
    caption: o,
    captionProps: c,
    className: b,
    dropOldClass: T,
    foot: u = [],
    footProps: k,
    head: m = [],
    headProps: h,
    hover: $,
    middle: j,
    responsive: x,
    responsiveProps: J,
    size: O,
    striped: D,
    stripedColumns: N,
    style: E,
    variables: K,
    variant: B,
    ...Q
  } = n, [v] = S(g(m)), [V] = S(g(u)), [_] = S(g(f)), U = Z(() => {
    const s = I(
      !T && "table",
      B && `table-${B}`,
      D && "table-striped",
      N && "table-striped-columns",
      $ && "table-hover",
      p && "table-bordered",
      r && "table-borderless",
      O && `table-${O}`,
      j && "table align-middle",
      b
    ), d = ss((ts, X) => ({ tKey: as(X) }), K, E);
    return {
      className: s,
      style: d
    };
  }, [
    p,
    r,
    b,
    T,
    $,
    j,
    O,
    D,
    N,
    E,
    K,
    B
  ]), z = /* @__PURE__ */ Y(t, { ...Q, ...U, children: [
    o && /* @__PURE__ */ e(M, { ...c, children: o }),
    v.length > 0 && /* @__PURE__ */ e(H, { ...h, children: /* @__PURE__ */ e(P, { children: v.map((s) => /* @__PURE__ */ y(
      R,
      {
        ...s.props,
        active: s.active,
        key: s.key ?? s.id,
        scope: s.scope,
        variant: s.variant
      },
      s.label
    )) }) }),
    _.length > 0 && /* @__PURE__ */ e(q, { ...l, children: _.map((s, d) => /* @__PURE__ */ y(P, { ...s.props, active: s.active, key: s.id, variant: s.variant }, s.values ? /* @__PURE__ */ e(C, { headOptions: v, rowIndex: d, rowItem: s, type: "values" }) : s.cells ? /* @__PURE__ */ e(C, { headOptions: v, rowIndex: d, rowItem: s, type: "cells" }) : /* @__PURE__ */ e(F, {}))) }),
    V.length > 0 && /* @__PURE__ */ e(G, { ...k, children: V.map((s, d) => /* @__PURE__ */ y(P, { ...s.props, active: s.active, key: s.id, variant: s.variant }, s.values ? /* @__PURE__ */ e(C, { headOptions: v, rowIndex: d, rowItem: s, type: "values" }) : s.cells ? /* @__PURE__ */ e(C, { headOptions: v, rowIndex: d, rowItem: s, type: "cells" }) : /* @__PURE__ */ e(F, {}))) })
  ] });
  return x ? /* @__PURE__ */ e(W, { ...J, responsive: x, children: z }) : z;
};
i.Caption = M;
i.Responsive = W;
i.Tbody = q;
i.Td = A;
i.Tfoot = G;
i.Th = R;
i.Thead = H;
i.Tr = P;
i.displayName = "BRL.Table";
export {
  i as T
};
//# sourceMappingURL=table.js.map
