import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  standalone: true,
  name: 'calculatePageRange'
})
export class CalculatePageRangePipe implements PipeTransform {
  transform(totalPages: number, currentPage: number, totalPagesCount: number): number[] {
    const visiblePages = 10;
    let startPage = Math.max(currentPage - 5, 1);
    let endPage = Math.min(startPage + visiblePages - 1, totalPagesCount);

    // Adjust the start and end if near the beginning or end
    if (currentPage < 6) {
      endPage = Math.min(visiblePages, totalPagesCount);
    } else if (currentPage > totalPagesCount - 5) {
      startPage = Math.max(totalPagesCount - visiblePages + 1, 1);
    }

    // Generate the range of page numbers to display
    return Array.from({ length: (endPage - startPage) + 1 }, (_, i) => startPage + i);
  }
}
