{"version":3,"file":"usePaginatedRows.mjs","sources":["../../../../../../src/components/va-data-table/hooks/usePaginatedRows.ts"],"sourcesContent":["import { Ref, computed, PropType, ExtractPropTypes } from 'vue'\n\nimport { useCurrentPageProp } from './useCommonProps'\n\nimport { useThrottleValue, useThrottleProps } from '../../../composables'\n\nimport type { DataTableItem, DataTableRow } from '../types'\n\nexport const usePaginatedRowsProps = {\n  ...useThrottleProps,\n  ...useCurrentPageProp,\n  perPage: { type: Number as PropType<number | undefined> },\n}\n\ntype PaginatedProps<Item extends DataTableItem> = Omit<ExtractPropTypes<typeof usePaginatedRowsProps>, 'items'> & {\n  items: Item[]\n}\n\nexport const usePaginatedRows = <Item extends DataTableItem>(\n  sortedRows: Ref<DataTableRow<Item>[]>,\n  props: PaginatedProps<Item>,\n) => {\n  const paginatedRows = computed(() => {\n    if (!props.perPage || props.perPage < 0) {\n      return sortedRows.value\n    }\n\n    if (!props.currentPage || props.currentPage < 0) {\n      return sortedRows.value.slice(0, props.perPage)\n    }\n\n    const pageStartIndex = props.perPage * (props.currentPage - 1)\n    return sortedRows.value.slice(pageStartIndex, pageStartIndex + props.perPage)\n  })\n\n  const paginatedRowsThrottled = useThrottleValue(paginatedRows, props)\n\n  return {\n    paginatedRows: paginatedRowsThrottled,\n  }\n}\n"],"names":[],"mappings":";;;AAQO,MAAM,wBAAwB;AAAA,EACnC,GAAG;AAAA,EACH,GAAG;AAAA,EACH,SAAS,EAAE,MAAM,OAAuC;AAC1D;AAMa,MAAA,mBAAmB,CAC9B,YACA,UACG;AACG,QAAA,gBAAgB,SAAS,MAAM;AACnC,QAAI,CAAC,MAAM,WAAW,MAAM,UAAU,GAAG;AACvC,aAAO,WAAW;AAAA,IACpB;AAEA,QAAI,CAAC,MAAM,eAAe,MAAM,cAAc,GAAG;AAC/C,aAAO,WAAW,MAAM,MAAM,GAAG,MAAM,OAAO;AAAA,IAChD;AAEA,UAAM,iBAAiB,MAAM,WAAW,MAAM,cAAc;AAC5D,WAAO,WAAW,MAAM,MAAM,gBAAgB,iBAAiB,MAAM,OAAO;AAAA,EAAA,CAC7E;AAEK,QAAA,yBAAyB,iBAAiB,eAAe,KAAK;AAE7D,SAAA;AAAA,IACL,eAAe;AAAA,EAAA;AAEnB;"}