import { jsxs as c, jsx as o } from "@emotion/react/jsx-runtime";
import { useMemo as l, useCallback as A } from "react";
import { CardHeaderStyled as H, CardHeaderLeftStyled as h, CardHeaderRightStyled as j } from "../../../../../../slots/DataGridSlot.js";
import { LayoutExpandOutlined as w } from "@m4l/icons";
import { CheckboxCellAdapter as z } from "../../../../../adapters/CheckboxCellAdapter/CheckboxCellAdapter.js";
import { IconButton as C } from "../../../../../../../extended/mui/IconButton/IconButton.js";
import { useDataGrid as G } from "../../../../../../hooks/shared/useDataGrid/useDataGrid.js";
import { MenuActions as I } from "../../../../../../../MenuActions/MenuActions.js";
function $({
  row: e,
  onOpenDetail: u,
  isChecked: S,
  showCheckbox: s,
  checkedRows: a,
  onCheckedRowsChange: r,
  showExpandButton: y = !0,
  onExpandClick: d
}) {
  const { rowKeyGetter: m, rowActionsGetter: f, size: b, checkedRowsMultiple: p } = G(), i = l(() => m(e), [m, e]), x = A(
    (t, M) => {
      if (!(!r || !a))
        if (p === !1)
          r(t ? /* @__PURE__ */ new Set([i]) : /* @__PURE__ */ new Set());
        else {
          const n = new Set(a);
          t ? n.add(i) : n.delete(i), r(n);
        }
    },
    [a, r, i, p]
  ), v = l(
    () => ({
      vertical: "bottom",
      horizontal: "right"
    }),
    []
  ), g = l(
    () => ({
      vertical: "top",
      horizontal: "right"
    }),
    []
  );
  return /* @__PURE__ */ c(H, { ownerState: { hasCheckedRows: s }, children: [
    s && /* @__PURE__ */ o(h, { ownerState: {}, children: /* @__PURE__ */ o(
      z,
      {
        value: S ?? !1,
        tabIndex: -1,
        onChange: x,
        "aria-label": "Select"
      }
    ) }),
    /* @__PURE__ */ c(j, { ownerState: {}, children: [
      y && /* @__PURE__ */ o(
        C,
        {
          icon: /* @__PURE__ */ o(w, {}),
          size: b,
          variant: "text",
          "data-testid": `card-details-button-${i}`,
          onClick: (t) => {
            t.stopPropagation(), d ? d(e) : u(e);
          }
        }
      ),
      f && /* @__PURE__ */ o(
        I,
        {
          arrowType: "top-left",
          objItem: e,
          menuActions: f,
          anchorOrigin: v,
          transformOrigin: g,
          onClick: (t) => t.stopPropagation(),
          variant: "text"
        }
      )
    ] })
  ] });
}
export {
  $ as CardHeader
};
