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 G } from "../../../../../../../extended/mui/IconButton/IconButton.js";
import { useDataGrid as I } from "../../../../../../hooks/shared/useDataGrid/useDataGrid.js";
import { MenuActions as L } from "../../../../../../../MenuActions/MenuActions.js";
function $({
  row: e,
  onOpenDetail: u,
  isChecked: S,
  showCheckbox: s,
  checkedRows: a,
  onCheckedRowsChange: r,
  showExpandButton: y = !0,
  onExpandClick: m
}) {
  const { rowKeyGetter: f, rowActionsGetter: d, size: b, checkedRowsMultiple: p } = I(), i = l(() => f(e), [f, 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(
        G,
        {
          icon: /* @__PURE__ */ o(w, {}),
          size: b,
          variant: "text",
          "data-testid": `list-details-button-${i}`,
          onClick: (t) => {
            t.stopPropagation(), m ? m(e) : u(e);
          }
        }
      ),
      d && /* @__PURE__ */ o(
        L,
        {
          arrowType: "top-left",
          objItem: e,
          menuActions: d,
          anchorOrigin: v,
          transformOrigin: g,
          onClick: (t) => t.stopPropagation(),
          variant: "text"
        }
      )
    ] })
  ] });
}
export {
  $ as ListHeader
};
