import { jsx as s, jsxs as O, Fragment as B } from "react/jsx-runtime";
import { motion as H } from "motion/react";
import { useRef as j } from "react";
import F from "../checkbox/Checkbox.js";
import N from "../../utils/classNames.js";
import { resolveRowKey as E, resolveRowClassName as M } from "./model/resolveRowMeta.js";
import { getVerticalAlignClassName as q } from "./shared/getAlignClassName.js";
import { getInteractiveRowProps as z } from "./shared/getInteractiveRowProps.js";
import { useOptionalTableInteractionContext as G } from "./context/TableInteractionContext.js";
import { useOptionalTableRenderConfigContext as J } from "./context/TableRenderConfigContext.js";
import { useOptionalTableSection as L, useTableBodyContext as Q, extractTableHtmlAttributes as T, TableRowContext as U } from "./context/TableStructureContext.js";
import { useOptionalTableRenderContext as W } from "./context/TableRenderContext.js";
const X = (p) => {
  const {
    isSelected: g,
    isSelectable: l,
    hideSelectionControl: x,
    isTableView: m,
    onToggleSelection: h,
    cardCellClassName: b,
    selectionCheckboxVerticalAlignment: a
  } = p;
  return /* @__PURE__ */ s(
    "div",
    {
      className: N(
        "table-cell table-selection-cell",
        q(a),
        !m && b
      ),
      role: "cell",
      "aria-colindex": 1,
      style: m ? { gridColumn: "1 / span 1", gridRow: "1 / span 1" } : void 0,
      onClick: (e) => e.stopPropagation(),
      onKeyDown: (e) => e.stopPropagation(),
      children: !x && /* @__PURE__ */ s("div", { className: "table-selection-control", children: /* @__PURE__ */ s(F, { checked: g, disabled: !l, onChange: h }) })
    }
  );
}, ae = (p) => {
  const { children: g, disabled: l, className: x, noHover: m, selectable: h, sticky: b, ...a } = p, e = J(), c = W(), o = G(), I = L(), f = Q(), C = j(0);
  if (C.current = 0, !c || !e || !o || c.columns.length === 0 || I !== "body" || !f)
    return null;
  const d = a, n = f.nextRowIndex(), t = E(d, n, e.rowKey), u = typeof e.rowAnimationProps == "function" ? e.rowAnimationProps(d, n) : e.rowAnimationProps, r = z({
    isClickable: o.isClickable && !l,
    onRowClick: (i, w) => {
      o.onRowClick?.(i, w), o.onActiveRowChange?.(
        o.activeRowId === t ? void 0 : t,
        i,
        w
      );
    },
    row: d,
    rowIndex: n
  }), R = o.selectableRowIdSet.has(t), v = R && o.selectedRowIdSet.has(t), P = o.showSelectionColumn && /* @__PURE__ */ s(
    X,
    {
      isSelected: v,
      isSelectable: R,
      hideSelectionControl: !R && o.hideSelectionCheckboxesForExcludedRows,
      isTableView: e.isTableView,
      onToggleSelection: () => o.onToggleRowSelection?.(t),
      cardCellClassName: e.cardClasses.cellClassName,
      selectionCheckboxVerticalAlignment: e.selectionCheckboxVerticalAlignment
    }
  ), A = !!c.renderDraft.bodyMaxHeight, y = N(
    "table-row",
    !e.isTableView && "divider-y-1 divider-color-lighter divider-style-solid",
    o.activeRowId === t && "table-row-active",
    l && "table-row-disabled",
    v && "table-row-selected",
    r.isClickableClassName,
    (l || m) && "table-row-no-hover",
    b && "table-row-sticky",
    b && A && "table-row-sticky-in-container",
    !e.isTableView && e.cardClasses.rowClassName,
    x,
    M(e.rowClassName, d, n)
  ), k = /* @__PURE__ */ O(B, { children: [
    P,
    g
  ] }), V = {
    ...T(a),
    className: y,
    "data-index": n,
    "data-row-id": String(t),
    onClick: r.onClick,
    onKeyDown: r.onKeyDown,
    role: "row",
    tabIndex: r.tabIndex
  }, D = {
    ...T(a),
    className: y,
    "data-index": n,
    "data-row-id": String(t),
    onClick: r.onClick,
    onKeyDown: r.onKeyDown,
    role: "row",
    tabIndex: r.tabIndex,
    ...u
  }, S = /* @__PURE__ */ s(
    U.Provider,
    {
      value: {
        nextColumnIndex: (i, w = 1) => {
          if (i !== void 0 && i >= 0)
            return C.current = i + w, i;
          const K = C.current;
          return C.current += w, K;
        },
        rowIndex: n,
        rowId: t,
        rowData: d
      },
      children: u ? /* @__PURE__ */ s(H.div, { ...D, children: k }) : /* @__PURE__ */ s("div", { ...V, children: k })
    }
  );
  return c.renderDraft.bodyRows.push({
    rowId: t,
    rowIndex: n,
    kind: "data",
    disabled: l,
    selectable: !l && h !== !1,
    render: () => S
  }), c.isRegisteringBodyRows ? null : S;
};
export {
  ae as default
};
//# sourceMappingURL=TableRow.js.map
