import { jsxs as h, Fragment as j, jsx as r } from "react/jsx-runtime";
import C, { useCallback as b, useMemo as E } from "react";
import { TableRow as g, TableCell as m } from "../TablePrimitive.js";
import T from "../../../button/Button.js";
import w from "../../../icon/Icon.js";
import z from "../../utils/getColumnSizeStyles.js";
import c from "../../utils/getNestedValue.js";
import y from "../../../text/Text.js";
import { columnAligns as R } from "../../types/ColumnAlign.js";
import { tableSizes as u } from "../../types/TableSize.js";
import B from "../../../box/Box.js";
import { c as d } from "../../../../index-BtlgVD4m.js";
const L = ({
  columns: o,
  hasColumnSeparator: x = !1,
  size: p = "sm",
  onRowClick: s,
  expandable: t,
  record: a,
  rowIndex: n
}) => {
  const [i, S] = C.useState(!1), v = b(() => {
    S((e) => !e);
  }, []), f = E(() => t ? t.expandableCondition ? t.expandableCondition(a) : !0 : !1, [t, a]), N = b(() => {
    s == null || s(a);
  }, [s, a]);
  return /* @__PURE__ */ h(j, { children: [
    /* @__PURE__ */ h(g, { className: "hover:bg-[var(--base-muted)]", onClick: N, children: [
      t && /* @__PURE__ */ r(m, { className: d("text-center px-1.5"), children: f && /* @__PURE__ */ r(
        T,
        {
          size: "iconXs",
          onClick: v,
          variant: "ghost",
          "aria-label": i ? "Collapse row" : "Expand row",
          icon: /* @__PURE__ */ r(
            w,
            {
              name: "ChevronDown",
              size: 16,
              className: `text-[var(--base-foreground-muted)] transition-transform duration-200 ease-in-out ${i ? "rotate-180" : "rotate-0"}`
            }
          )
        }
      ) }, `jtl-table-row-${n}-expandable`),
      o.map((e, l) => {
        const $ = z(e);
        return /* @__PURE__ */ r(
          m,
          {
            style: $,
            className: d(
              u[p],
              x && l !== o.length - 1 && "border-r border-[var(--base-border)]",
              e.align && R[e.align],
              t && l === 0 && "pl-0"
            ),
            children: e.render ? e.render(c(a, e.dataIndex), a, n) : /* @__PURE__ */ r(y, { truncate: !0, align: e.align, children: String(c(a, e.dataIndex) ?? "") })
          },
          `jtl-table-row-${n}-cell-${l}`
        );
      })
    ] }),
    t && i && f && /* @__PURE__ */ r(g, { children: /* @__PURE__ */ r(
      m,
      {
        colSpan: o.length + 1,
        className: d(u[p], "border-t-0"),
        children: /* @__PURE__ */ r(B, { children: t.expandedRowRender(a) })
      }
    ) }, `jtl-table-row-${n}-expanded`)
  ] });
};
export {
  L as default
};
//# sourceMappingURL=TableRow.js.map
