import { DEFAULT_PAGE_LIMIT as x, LIMIT_OPTIONS as z } from "../../../internal/Pagination/constants.js";
import { TRANSACTION_FIELDS_REMAPS as k, TRANSACTION_FIELDS as G } from "../components/TransactionsTable/fields.js";
import { getTransactionsFilterParams as Q, getTransactionsFilterQueryParams as U } from "../components/utils.js";
import { useCustomColumnsData as j } from "../../../../hooks/useCustomColumnsData.js";
import { useMemo as c, useRef as F, useCallback as T, useEffect as B } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import H from "../../../utils/customData/normalizeCustomFields.js";
import J from "../../../utils/customData/hasCustomField.js";
import K from "../../../utils/customData/mergeRecords.js";
import V from "../../../internal/Pagination/hooks/useCursorPaginatedRecords.js";
import { useConfigContext as W } from "../../../../core/ConfigContext/preact/context.js";
import { isFunction as C } from "../../../../utils/value/is.js";
const mt = ({
  allowLimitSelection: R = !0,
  preferredLimit: g = x,
  dataCustomization: P,
  fetchEnabled: A,
  filters: r,
  now: s,
  onFiltersChanged: m
}) => {
  const { getTransactions: e } = W().endpoints, t = c(() => Q(r, s), [r, s]), u = F(t).current, d = F(u), I = C(e) && A, h = T(
    async (i, a) => {
      const n = {
        ...i,
        ...U(r, s),
        sortDirection: "desc"
      };
      return e({ signal: a }, { query: n });
    },
    [r, e, s]
  ), {
    canResetFilters: X,
    error: D,
    fetching: L,
    filters: Y,
    limit: S,
    limitOptions: _,
    records: E,
    resetFilters: Z,
    updateFilters: l,
    updateLimit: O,
    ...N
  } = V({
    dataField: "data",
    fetchRecords: h,
    enabled: I,
    filterParams: u,
    initialFiltersSameAsDefault: !0,
    onFiltersChanged: C(m) ? m : void 0,
    preferredLimitOptions: R ? z : void 0,
    preferredLimit: g
  }), y = T(
    ({ records: i, retrievedData: a }) => K(i, a, (n, q) => n.id === q.id),
    []
  ), { fields: f, onDataRetrieve: M } = P?.list ?? {}, o = c(() => H(f, k), [f]), p = c(() => J(o, G), [o]), { customRecords: v, loadingCustomRecords: b } = j({ hasCustomColumn: p, mergeCustomData: y, onDataRetrieve: M, records: E });
  return B(() => {
    d.current !== t && (d.current = t, l?.(t));
  }, [t, l]), {
    ...N,
    error: D,
    fields: o,
    fetching: L || b,
    records: v,
    hasCustomColumn: p,
    limit: S,
    limitOptions: _,
    updateLimit: O
  };
};
export {
  mt as default
};
