export class Loader {
    /* System.js loader - usage:

    System.config({
          baseURL: 'https://unpkg.com/@ema/js-base',
          packages: {
              'dist': {
                  defaultExtension: 'js'
              },
              'src': {
                  defaultExtension: 'ts'
              }
          },
      });
    System.import('loader').then(function(module) {
        let namespace = 'myNamespace';
        let  modules = [
            'cms/wordpress',
            'api',
            'base/base',
            'base/browser',
            'base/server',
            'config/config',
            'config/config-service',
            'config/config-defaults',
            'user',
            'ui/form',
            'util/storage',
            'util/util',
            'validation/validationConstants',
        ];
        module.Loader.loadLibrary({modules: modules, path:'global/',namespace:namespace,extension:''}).then(function(){
            let library = window['myNamespace'];
            console.log(window['myNamespace']);
            //
            // call your applications init function here.
            //
        });
    });
    */
    static loadLibrary(options) {
        const namespace = '_ab';
        let path = '';
        let abl = {};
        let imports = [];
        return new Promise(function (resolve, reject) {
            let extension = '';
            if (options.path) {
                path = options.path;
            }
            if (options.extension) {
                extension = options.extension;
            }
            options.modules.forEach((module) => {
                imports.push(System.import(options.path + module + extension));
            });
            Promise.all(imports).then(function (modules) {
                modules.forEach((module) => {
                    for (let C in module) {
                        abl[C] = module[C];
                    }
                    if (module.Base) {
                        abl.base = new module.Base;
                    }
                });
                if (typeof window !== 'undefined') {
                    if (!window[namespace]) {
                        window[namespace] = abl;
                    }
                    if (options.namespace) {
                        if (!window[options.namespace]) {
                            window[options.namespace] = abl;
                        }
                    }
                }
                resolve(abl);
            });
        });
    }
    ;
}
//# sourceMappingURL=loader.js.map