{"version":3,"file":"usePagination.cjs","names":["_react","require","_i18n","usePagination","currentRowsCount","pageIndex","pageSize","totalRows","t","useTranslation","useMemo","firstRow","lastRow","totalRowsLabel","exports"],"sources":["../../../src/Pagination/usePagination.ts"],"sourcesContent":["/*!\n * Copyright (c) 2023-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport { useMemo } from \"react\";\n\nimport { useTranslation } from \"../i18n.generated/i18n.js\";\n\ntype UsePaginationType = {\n  currentRowsCount: number;\n  pageIndex: number;\n  pageSize: number;\n  totalRows?: number;\n};\n\nexport const usePagination = ({\n  currentRowsCount,\n  pageIndex,\n  pageSize,\n  totalRows,\n}: UsePaginationType) => {\n  const { t } = useTranslation();\n\n  return useMemo(() => {\n    const firstRow = pageSize * (pageIndex - 1) + 1;\n    const lastRow = firstRow + (currentRowsCount - 1);\n\n    const totalRowsLabel =\n      currentRowsCount === 0\n        ? t(\"pagination.totalrows\", { totalRows: 0 })\n        : totalRows\n          ? t(\"pagination.rowswithtotal\", { firstRow, lastRow, totalRows })\n          : t(\"pagination.rowswithouttotal\", { firstRow, lastRow });\n\n    return {\n      firstRow,\n      lastRow,\n      totalRowsLabel,\n    };\n  }, [currentRowsCount, pageIndex, pageSize, totalRows, t]);\n};\n"],"mappings":";;;;;;AAYA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAaO,MAAME,aAAa,GAAGA,CAAC;EAC5BC,gBAAgB;EAChBC,SAAS;EACTC,QAAQ;EACRC;AACiB,CAAC,KAAK;EACvB,MAAM;IAAEC;EAAE,CAAC,GAAG,IAAAC,oBAAc,EAAC,CAAC;EAE9B,OAAO,IAAAC,cAAO,EAAC,MAAM;IACnB,MAAMC,QAAQ,GAAGL,QAAQ,IAAID,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC;IAC/C,MAAMO,OAAO,GAAGD,QAAQ,IAAIP,gBAAgB,GAAG,CAAC,CAAC;IAEjD,MAAMS,cAAc,GAClBT,gBAAgB,KAAK,CAAC,GAClBI,CAAC,CAAC,sBAAsB,EAAE;MAAED,SAAS,EAAE;IAAE,CAAC,CAAC,GAC3CA,SAAS,GACPC,CAAC,CAAC,0BAA0B,EAAE;MAAEG,QAAQ;MAAEC,OAAO;MAAEL;IAAU,CAAC,CAAC,GAC/DC,CAAC,CAAC,6BAA6B,EAAE;MAAEG,QAAQ;MAAEC;IAAQ,CAAC,CAAC;IAE/D,OAAO;MACLD,QAAQ;MACRC,OAAO;MACPC;IACF,CAAC;EACH,CAAC,EAAE,CAACT,gBAAgB,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAACM,OAAA,CAAAX,aAAA,GAAAA,aAAA","ignoreList":[]}