import {ImageLoader} from '@kibeo/loaders.gl-images';
import {getImageUrls} from './load-image';
import {deepLoad} from './deep-load';

export async function loadImageTextureArray(count, getUrl, options = {}) {
  const imageUrls = await getImageArrayUrls(count, getUrl, options);
  return await deepLoad(imageUrls, ImageLoader.parse, options);
}

export async function getImageArrayUrls(count, getUrl, options = {}) {
  const promises: Promise<any>[] = [];
  for (let index = 0; index < count; index++) {
    const promise = getImageUrls(getUrl, options, {index});
    promises.push(promise);
  }
  return await Promise.all(promises);
}
