import { useParentValue } from "@saasquatch/component-boilerplate";
import { REFERRAL_CODES_PAGINATION_CONTEXT, } from "../sqm-referral-codes/useReferralCodes";
import { intl } from "../../global/global";
export function usePagination(props) {
  var _a;
  const context = useParentValue(REFERRAL_CODES_PAGINATION_CONTEXT);
  const currentPage = context.states.currentPage + 1;
  const totalPages = (_a = context.states) === null || _a === void 0 ? void 0 : _a.pageCount;
  return {
    states: {
      currentPage,
      totalPages,
      loading: context.states.loading,
    },
    callbacks: {
      onNext: () => { var _a, _b; return (_a = context.callbacks) === null || _a === void 0 ? void 0 : _a.setCurrentPage(((_b = context.states) === null || _b === void 0 ? void 0 : _b.currentPage) + 1); },
      onPrev: () => { var _a, _b; return (_a = context.callbacks) === null || _a === void 0 ? void 0 : _a.setCurrentPage(((_b = context.states) === null || _b === void 0 ? void 0 : _b.currentPage) - 1); },
    },
    text: {
      paginationText: intl.formatMessage({
        id: `paginationText`,
        defaultMessage: props.paginationText,
      }, {
        currentPage,
        totalPages,
      }),
    },
  };
}
