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