import { loadFiles, loadImages } from './load-files';
import { Program, Texture2D } from '../webgl';
import assert from '../utils/assert';

function noop() {}

export function loadTexture(gl, url, opts = {}) {
  const urls = opts.urls;
  var _opts$onProgress = opts.onProgress;
  const onProgress = _opts$onProgress === undefined ? noop : _opts$onProgress;

  assert(typeof url === 'string', 'loadTexture: url must be string');

  return loadImages(Object.assign({ urls, onProgress }, opts)).then(images => images.map((img, i) => {
    return new Texture2D(gl, Object.assign({ id: urls[i] }, opts, { data: img }));
  }));
}

export function loadProgram(gl, opts = {}) {
  const vs = opts.vs,
        fs = opts.fs;
  var _opts$onProgress2 = opts.onProgress;
  const onProgress = _opts$onProgress2 === undefined ? noop : _opts$onProgress2;

  return loadFiles(Object.assign({ urls: [vs, fs], onProgress }, opts)).then(([vsText, fsText]) => new Program(gl, Object.assign({ vs: vsText, fs: fsText }, opts)));
}

export function loadTextures(gl, opts = {}) {
  const urls = opts.urls;
  var _opts$onProgress3 = opts.onProgress;
  const onProgress = _opts$onProgress3 === undefined ? noop : _opts$onProgress3;

  assert(urls.every(url => typeof url === 'string'), 'loadTextures: {urls} must be array of strings');

  return loadImages(Object.assign({ urls, onProgress }, opts)).then(images => images.map((img, i) => {
    let params = Array.isArray(opts.parameters) ? opts.parameters[i] : opts.parameters;
    params = params === undefined ? {} : params;
    return new Texture2D(gl, Object.assign({ id: urls[i] }, params, { data: img }));
  }));
}
//# sourceMappingURL=load-texture.js.map