import { NgModule, Optional, SkipSelf, ApplicationRef, ComponentFactoryResolver } from '@angular/core';
import { HttpModule, Http } from '@angular/http';
import { AuthHttp, AuthConfig } from 'angular2-jwt';
import { AuthService } from '../services/secure-http/auth.service';
import { SecureHttp } from '../services/secure-http.service';
import { throwIfAlreadyLoaded } from '../services/secure-http/module-import-guard';
import { LoginComponent } from '../components/login.component';
export var getAuthHttp = function (http, authService) {
    return new AuthHttp(new AuthConfig({
        headerName: 'Authorization',
        headerPrefix: 'Bearer',
        tokenName: 'access_token',
        tokenGetter: (function () { return authService.token; }),
        noJwtError: true,
        noTokenScheme: true
    }), http);
};
export var getAuthService = function (config, applicationRef, componentFactoryResolver) {
    return new AuthService(config, applicationRef, componentFactoryResolver);
};
var GHDSecureHttpModule = (function () {
    function GHDSecureHttpModule(parentModule) {
        throwIfAlreadyLoaded(parentModule, 'GHDSecureHttpModule');
    }
    GHDSecureHttpModule.forRoot = function (config) {
        return {
            ngModule: GHDSecureHttpModule,
            providers: [
                { provide: 'ADAL_CONFIG', useValue: config },
                {
                    provide: AuthService,
                    useFactory: getAuthService,
                    deps: ['ADAL_CONFIG', ApplicationRef, ComponentFactoryResolver]
                },
                {
                    provide: AuthHttp,
                    useFactory: getAuthHttp,
                    deps: [Http, AuthService]
                },
                SecureHttp
            ]
        };
    };
    GHDSecureHttpModule.decorators = [
        { type: NgModule, args: [{
                    imports: [
                        HttpModule
                    ],
                    declarations: [LoginComponent],
                    entryComponents: [LoginComponent]
                },] },
    ];
    /** @nocollapse */
    GHDSecureHttpModule.ctorParameters = function () { return [
        { type: GHDSecureHttpModule, decorators: [{ type: Optional }, { type: SkipSelf },] },
    ]; };
    return GHDSecureHttpModule;
}());
export { GHDSecureHttpModule };
//# sourceMappingURL=ghd-secure-http.module.js.map