import { jsxs as y, jsx as o } from "@emotion/react/jsx-runtime";
import L, { useMemo as q } from "react";
import { CardContentWrapperStyled as z, CardContentStyled as B, CardStyled as H } from "../../../../slots/DataGridSlot.js";
import { deepEqual as W } from "fast-equals";
import { useCardContent as F } from "../../hooks/useCardContent/useCardContent.js";
import { CardHeader as J } from "./subcomponents/CardHeader/CardHeader.js";
import { LazyLoadCard as N } from "./subcomponents/LazyLoadCard/LazyLoadCard.js";
import { getDefaultAction as O } from "../../../../helpers/shared/getDefaultAction/getDefaultAction.js";
import { useDataGrid as P } from "../../../../hooks/shared/useDataGrid/useDataGrid.js";
function Q({
  row: t,
  rows: e,
  rowIndex: v,
  columns: I,
  originalColumns: T,
  rowKeyGetter: n,
  selectedRows: r,
  onSelectedRowsChange: l,
  onRowsChange: M,
  customRender: i,
  minHeight: h,
  isChecked: a,
  checkedRows: m,
  showCheckbox: d,
  onCheckedRowsChange: s,
  onOpenDetail: k,
  showExpandButton: f = !0,
  onExpandClick: C
}) {
  const { rowActionsGetter: p } = P(), b = i !== void 0, { cardContent: g } = F({
    row: t,
    rows: e,
    rowIndex: v,
    columns: I,
    onRowsChange: M
  }), D = q(() => b ? i.renderContent(t) : /* @__PURE__ */ y(z, { ownerState: {}, children: [
    /* @__PURE__ */ o(
      J,
      {
        row: t,
        onOpenDetail: k,
        isChecked: a,
        showCheckbox: d,
        checkedRows: m,
        onCheckedRowsChange: s,
        showExpandButton: f,
        onExpandClick: C
      }
    ),
    /* @__PURE__ */ o(B, { ownerState: {}, children: g })
  ] }), [
    b,
    i,
    t,
    g,
    a,
    d,
    m,
    s,
    f,
    C
  ]), A = (c) => {
    if (!c.target.closest(
      'input, button, a, [role="button"], .MuiCheckbox-root, .MuiIconButton-root'
    ) && r && l) {
      if (r.has(n(t)))
        return;
      const u = /* @__PURE__ */ new Set([n(t)]);
      l(u);
    }
  }, E = (c) => {
    if (c.target.closest(
      'input, button, a, [role="button"], .MuiCheckbox-root, .MuiIconButton-root'
    ) || !p)
      return;
    const u = p(t), S = O(u);
    S?.onClick && S.onClick(t);
  };
  return /* @__PURE__ */ o(N, { threshold: 200, minHeight: h, rowKey: n(t), children: /* @__PURE__ */ o(
    H,
    {
      variant: "outlined",
      selected: r?.has(n(t)),
      ownerState: {
        checked: a,
        selected: r?.has(n(t))
      },
      onClick: A,
      onDoubleClick: E,
      "data-testid": "data-grid-card",
      "data-row-key": n(t),
      children: D
    }
  ) });
}
const R = L.memo(Q, (t, e) => W(t, e));
export {
  R as CardRow
};
