/**
 * Generate pagination items for a given current page and total pages.
 * 
 * @param current - The current page number
 * @param totalPages - The total number of pages
 * @returns An array of page numbers and ellipsis
 */
export function generatePaginationItems(current: number, totalPages: number): (number | string)[] {
  const items: (number | string)[] = []

  if (totalPages <= 0) {
    return items
  }

  if (totalPages <= 7) {
    // Show all pages if 7 or fewer
    for (let i = 1; i <= totalPages; i++) {
      items.push(i)
    }
  } else {
    // Always show first page
    items.push(1)

    // Calculate the range around current page
    const delta = 1 // Number of pages to show on each side of current
    let start = Math.max(2, current - delta)
    let end = Math.min(totalPages - 1, current + delta)

    // Adjust if we're near the start
    if (current <= 3) {
      end = Math.min(5, totalPages - 1)
    }

    // Adjust if we're near the end
    if (current >= totalPages - 2) {
      start = Math.max(2, totalPages - 4)
    }

    // Add ellipsis after first page if needed
    if (start > 2) {
      items.push('ellipsis')
    }

    // Add page numbers in the range
    for (let i = start; i <= end; i++) {
      items.push(i)
    }

    // Add ellipsis before last page if needed
    if (end < totalPages - 1) {
      items.push('ellipsis')
    }

    // Always show last page
    if (totalPages > 1) {
      items.push(totalPages)
    }
  }

  return items
}