import { jsx as s } from "@emotion/react/jsx-runtime";
import { useState as O, useEffect as C } from "react";
import { TEST_PROP_ID as b } from "../../../../test/constants_no_mock.js";
import { ContainerWrapperStyled as h, GridWrapperStyled as w } from "../../slots/ObjectLogsSlots.js";
import { usePaginate as S } from "@m4l/graphics";
import { useObjectLogsColumns as T } from "../../hooks/useObjectLogsColumns.js";
import { OBJECT_LOGS_M4L_END_POINT as E, OBJECT_LOGS_KEY_COMPONENT as L } from "../../constants.js";
import { getPropDataTestId as j } from "../../../../test/getNameDataTestId.js";
import { useFilterAndSort as y } from "../../hooks/useFilterAndSort.js";
import { DataGrid as I } from "../../../datagrids/components/DataGridMain/DataGridMain.js";
import { ObjectLogsSlots as N } from "../../slots/ObjectLogsEnum.js";
function J(n) {
  const { resourceId: e, objectId: r, dataTestId: o = "" } = n, [m, a] = O(() => ({ resource_id: e, object_id: r })), c = T("m4l"), { pagerState: t, rows: i, onPageChange: d, onRowsPerPageChange: l, clearRows: p, Refresh: u } = S({
    endPoint: E,
    fireOnFirstLoad: !1,
    fireOnChangeParms: !1,
    queryParams: m,
    bodyToSnakeCase: !0,
    responseToCamelCase: !0
  });
  C(() => {
    p(), a({ resource_id: e, object_id: r });
  }, [e, r]);
  const { leftActions: g, visibleCustomHeader: P, customHeaderComponent: f } = y({ setBackendQueryParams: a, Refresh: u, otherApp: !1 });
  return /* @__PURE__ */ s(
    h,
    {
      ...process.env.NODE_ENV !== "production" ? { [b]: `m4ldatagrids-${o}` } : {},
      ...j(L, N.root, o),
      role: "grid",
      "aria-label": "object-logs",
      children: /* @__PURE__ */ s(
        w,
        {
          children: /* @__PURE__ */ s(
            I,
            {
              id: "users_logs_list",
              dataTestId: o,
              columns: c,
              rows: i,
              rowKeyGetter: (_) => _.id,
              visibleCustomHeader: P,
              customHeader: f,
              withActions: !0,
              actionsProps: {
                leftActions: g,
                withPager: !0,
                withLocalFilters: !0,
                pagerOptions: {
                  records: i.length,
                  totalRecords: t.totalRecords,
                  rowsPerPageOptions: [1, 2, 3, 4, 5, 10, 25],
                  page: t.page,
                  rowsPerPage: t.rowsPerPage,
                  onPageChange: d,
                  onRowsPerPageChange: l
                }
              }
            },
            "users_list_logs"
          )
        }
      )
    }
  );
}
export {
  J as ObjectLogsByM4L
};
