export async function fetchAllPages(urlBuilder) {
  const items = [];
  let page = 0;
  let totalPages = 1;

  while (page < totalPages) {
    const res = await fetch(urlBuilder(page));
    if (!res.ok) {
      throw new Error(`HTTP ${res.status} – ${res.statusText}`);
    }

    const data = await res.json();
    items.push(...(data.content ?? []));
    totalPages = Math.max(data.totalPages ?? 1, 1);
    page += 1;
  }

  return items;
}
